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/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() {} | |
hlundin-webrtc
2015/09/15 09:26:38
virtual ~RepetitionDetector() = default;
minyue-webrtc
2015/09/17 13:45:22
Done.
| |
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. | |
hlundin-webrtc
2015/09/15 09:26:38
Consider using the FRIEND_TEST macro instead.
http
minyue-webrtc
2015/09/17 13:45:22
Please see my earlier comment. If you have a bette
hlundin-webrtc
2015/09/17 14:36:33
Acknowledged.
| |
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 // Register repetition patterns. | |
hlundin-webrtc
2015/09/15 09:26:38
This comment adds no more information than the nam
minyue-webrtc
2015/09/17 13:45:22
Done.
| |
69 void RegisterRepetitionPatterns(const Pattern* patterns, | |
70 size_t num_patterns); | |
71 | |
72 // Clear registered repetition patterns. | |
hlundin-webrtc
2015/09/15 09:26:38
Same for this comment. Contribute or die.
minyue-webrtc
2015/09/17 13:45:22
Done.
| |
73 void ClearRepetitionPatterns(); | |
74 | |
75 // Reset |audio_buffer_| when number of channels or sample rate changes. | |
76 void Reset(size_t num_channels, int sample_rate_hz); | |
77 | |
78 // Add frames (interleaved if stereo) to |audio_buffer_|. | |
79 void AddFramesToBuffer(const float* data, size_t num_frames); | |
80 | |
81 // Determine if an audio frame (samples interleaved if stereo) is identical to | |
82 // |audio_buffer_| at a look back position. | |
83 bool Equal(const float* frame, int look_back_samples) const; | |
84 | |
85 // Determine if an audio frame (samples interleaved if stereo) is zero. | |
86 bool IsZero(const float* frame) const; | |
87 | |
88 // Action on finding a repetition with specified pattern id. | |
89 virtual void ReportRepetition(int id) { } | |
90 | |
91 ScopedVector<State> states_; | |
92 int max_look_back_ms_; | |
93 | |
94 std::vector<float> audio_buffer_; // Ring buffers to store input audio. | |
95 size_t num_channels_; // Number of audio channels in buffer. | |
96 int sample_rate_hz_; // Sample rate in kHz. | |
hlundin-webrtc
2015/09/15 09:26:39
Still mismatch between name and comment.
minyue-webrtc
2015/09/17 13:45:22
oh, sorry. I might have missed your earlier commen
| |
97 size_t buffer_size_frames_; // Number of frames in |audio_buffer|. | |
98 size_t buffer_end_index_; // The index of the last frame in |audio_buffer|. | |
99 size_t max_frames_; // The maximum input frames that |audio_buffer_| | |
100 // can handle for each detection. | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(RepetitionDetector); | |
103 }; | |
104 | |
105 } // namespace webrtc | |
106 | |
107 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_ | |
OLD | NEW |