OLD | NEW |
---|---|
(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/base/scoped_ptr.h" | |
18 #include "webrtc/system_wrappers/interface/scoped_vector.h" | |
19 #include "webrtc/typedefs.h" | |
20 | |
21 namespace webrtc { | |
22 | |
23 class RepetitionDetectorForTest; | |
24 | |
25 class RepetitionDetector { | |
26 public: | |
27 RepetitionDetector(); | |
28 virtual ~RepetitionDetector() {} | |
29 | |
30 struct Pattern { | |
31 int id_; | |
32 // All followings are in milliseconds, since repetition patterns are | |
33 // supposedly bounded to certain duration in time. | |
34 int look_back_ms_; | |
35 int min_length_ms_; | |
36 }; | |
37 | |
38 // Detect repetition given audio samples. When multichannel, samples should be | |
39 // interleaved. | |
40 void Detect(const float* data, size_t num_frames, size_t num_channels, | |
41 int sample_rate_hz); | |
42 | |
43 friend class RepetitionDetectorForTest; // For testing. | |
Andrew MacDonald
2015/09/07 06:52:18
Normally you'd use the FRIEND_TEST macro.
minyue-webrtc
2015/09/07 07:33:24
Acknowledged.
minyue-webrtc
2015/09/11 14:01:41
It turns out a bit complicated here.
RepetitionDe
| |
44 | |
45 protected: | |
46 virtual void ReportRepetition(int id) { } | |
Andrew MacDonald
2015/09/07 06:52:18
Why protected?
minyue-webrtc
2015/09/07 07:33:24
true, not needed.
| |
47 | |
48 private: | |
49 class State { | |
50 public: | |
51 State(int id, int look_back_ms, int min_length_ms); | |
52 | |
53 bool reported() const { return reported_; } | |
54 void set_reported(bool reported) { reported_ = reported; } | |
55 | |
56 // Increase the counter by 1, and tell if the counted sample is zero. | |
57 void Increment(bool zero); | |
58 | |
59 bool HasValidReport(int sample_rate_khz) const; | |
60 | |
61 void Reset(); | |
62 int id() const { return id_; } | |
63 int look_back_ms() const { return look_back_ms_; } | |
64 | |
65 private: | |
66 const int id_; | |
67 const int look_back_ms_; | |
68 const int min_length_ms_; | |
69 size_t count_samples_; | |
70 bool all_zero_; | |
71 bool reported_; | |
72 }; | |
73 | |
74 // Register repetition patterns. | |
75 void RegisterRepetitionPatterns(const Pattern* patterns, | |
76 size_t num_patterns); | |
77 | |
78 // Clear registered repetition patterns. | |
79 void ClearRepetitionPatterns(); | |
80 | |
81 // Reset |audio_buffer_| when number of channels or sample rate changes. | |
82 void Reset(size_t num_channels, int sample_rate_hz); | |
83 | |
84 // Add sample (interleaved if stereo) to |audio_buffer_|. | |
85 void AddSampleToBuffer(const float* sample); | |
86 | |
87 // Determine if a sample (interleaved if stereo) is identical to | |
88 // |audio_buffer_| at a look back position. | |
89 bool Equal(const float* sample, int look_back_samples) const; | |
90 | |
91 // Determine if a sample (interleaved if stereo) is zero. | |
92 bool IsZero(const float* sample) const; | |
93 | |
94 ScopedVector<State> states_; | |
95 int max_look_back_ms_; | |
96 | |
97 rtc::scoped_ptr<float[]> audio_buffer_; // Ring buffers to store input audio. | |
98 size_t num_channels_; // Number of audio channels in buffer. | |
99 int sample_rate_hz_; // Sample rate in kHz. | |
100 size_t buffer_size_samples_; // Number of samples in |audio_buffer|. | |
101 size_t buffer_end_index_; // The index of the last sample in |audio_buffer|. | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(RepetitionDetector); | |
104 }; | |
105 | |
106 } // namespace webrtc | |
107 | |
108 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_ | |
OLD | NEW |