Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: webrtc/modules/audio_processing/repetition_detector.h

Issue 1287663002: Adding audio RepetitionDetector in AudioProcessingModule. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: more comments addressed Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_
13
14 #include <vector>
15
16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/system_wrappers/interface/scoped_vector.h"
18 #include "webrtc/typedefs.h"
19
20 namespace webrtc {
21
22 class RepetitionDetector {
23 public:
24 RepetitionDetector();
25 virtual ~RepetitionDetector();
26
27 struct Pattern {
28 int id_;
29 // All followings are in milliseconds, since repetition patterns are
30 // supposedly bounded to certain duration in time.
31 int look_back_ms_;
32 int min_length_ms_;
33 };
34
35 // Detect repetition in given |data|. When multichannel, samples should be
36 // interleaved.
37 void Detect(const float* data, size_t num_frames, size_t num_channels,
38 int sample_rate_hz);
39
40 private:
41 friend class RepetitionDetectorForTest; // For testing.
42
43 class State {
44 public:
45 State(int id, int look_back_ms, int min_length_ms);
46
47 bool reported() const { return reported_; }
48 void set_reported(bool reported) { reported_ = reported; }
49
50 // Increase the counter by 1, and tell if the counted audio is zero.
51 void Increment(bool zero);
52
53 bool HasValidReport(int sample_rate_khz) const;
54
55 void Reset();
56 int id() const { return id_; }
57 int look_back_ms() const { return look_back_ms_; }
58
59 private:
60 const int id_;
61 const int look_back_ms_;
62 const int min_length_ms_;
63 size_t count_frames_;
64 bool all_zero_;
65 bool reported_;
66 };
67
68 void RegisterRepetitionPatterns(const Pattern* patterns,
69 size_t num_patterns);
70
71 void ClearRepetitionPatterns();
72
73 // Reset |audio_buffer_| when number of channels or sample rate changes.
74 void Reset(size_t num_channels, int sample_rate_hz);
75
76 // Add frames (interleaved if stereo) to |audio_buffer_|.
77 void AddFramesToBuffer(const float* data, size_t num_frames);
78
79 // Determine if an audio frame (samples interleaved if stereo) is identical to
80 // |audio_buffer_| at a look back position.
81 bool Equal(const float* frame, int look_back_samples) const;
82
83 // Determine if an audio frame (samples interleaved if stereo) is zero.
84 bool IsZero(const float* frame) const;
85
86 // Action on finding a repetition with specified pattern id.
87 virtual void ReportRepetition(int id) { }
88
89 ScopedVector<State> states_;
90 int max_look_back_ms_;
91
92 std::vector<float> audio_buffer_; // Ring buffers to store input audio.
93 size_t num_channels_; // Number of audio channels in buffer.
94 int sample_rate_hz_; // Sample rate in Hz.
95 size_t buffer_size_frames_; // Number of frames in |audio_buffer|.
96 size_t buffer_end_index_; // The index of the last frame in |audio_buffer|.
97 size_t max_frames_; // The maximum input frames that |audio_buffer_|
98 // can handle for each detection.
99
100 DISALLOW_COPY_AND_ASSIGN(RepetitionDetector);
101 };
102
103 } // namespace webrtc
104
105 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/audio_processing_impl.cc ('k') | webrtc/modules/audio_processing/repetition_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698