Index: webrtc/modules/audio_processing/repetition_detector.h |
diff --git a/webrtc/modules/audio_processing/repetition_detector.h b/webrtc/modules/audio_processing/repetition_detector.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9434812e0e6141a8808515f63520d19d15c8e51d |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/repetition_detector.h |
@@ -0,0 +1,107 @@ |
+/* |
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_ |
+#define WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_ |
+ |
+#include <vector> |
+ |
+#include "webrtc/base/constructormagic.h" |
+#include "webrtc/system_wrappers/interface/scoped_vector.h" |
+#include "webrtc/typedefs.h" |
+ |
+namespace webrtc { |
+ |
+class RepetitionDetector { |
+ public: |
+ RepetitionDetector(); |
+ virtual ~RepetitionDetector() {} |
hlundin-webrtc
2015/09/15 09:26:38
virtual ~RepetitionDetector() = default;
minyue-webrtc
2015/09/17 13:45:22
Done.
|
+ |
+ struct Pattern { |
+ int id_; |
+ // All followings are in milliseconds, since repetition patterns are |
+ // supposedly bounded to certain duration in time. |
+ int look_back_ms_; |
+ int min_length_ms_; |
+ }; |
+ |
+ // Detect repetition in given |data|. When multichannel, samples should be |
+ // interleaved. |
+ void Detect(const float* data, size_t num_frames, size_t num_channels, |
+ int sample_rate_hz); |
+ |
+ private: |
+ 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.
|
+ |
+ class State { |
+ public: |
+ State(int id, int look_back_ms, int min_length_ms); |
+ |
+ bool reported() const { return reported_; } |
+ void set_reported(bool reported) { reported_ = reported; } |
+ |
+ // Increase the counter by 1, and tell if the counted audio is zero. |
+ void Increment(bool zero); |
+ |
+ bool HasValidReport(int sample_rate_khz) const; |
+ |
+ void Reset(); |
+ int id() const { return id_; } |
+ int look_back_ms() const { return look_back_ms_; } |
+ |
+ private: |
+ const int id_; |
+ const int look_back_ms_; |
+ const int min_length_ms_; |
+ size_t count_frames_; |
+ bool all_zero_; |
+ bool reported_; |
+ }; |
+ |
+ // 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.
|
+ void RegisterRepetitionPatterns(const Pattern* patterns, |
+ size_t num_patterns); |
+ |
+ // 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.
|
+ void ClearRepetitionPatterns(); |
+ |
+ // Reset |audio_buffer_| when number of channels or sample rate changes. |
+ void Reset(size_t num_channels, int sample_rate_hz); |
+ |
+ // Add frames (interleaved if stereo) to |audio_buffer_|. |
+ void AddFramesToBuffer(const float* data, size_t num_frames); |
+ |
+ // Determine if an audio frame (samples interleaved if stereo) is identical to |
+ // |audio_buffer_| at a look back position. |
+ bool Equal(const float* frame, int look_back_samples) const; |
+ |
+ // Determine if an audio frame (samples interleaved if stereo) is zero. |
+ bool IsZero(const float* frame) const; |
+ |
+ // Action on finding a repetition with specified pattern id. |
+ virtual void ReportRepetition(int id) { } |
+ |
+ ScopedVector<State> states_; |
+ int max_look_back_ms_; |
+ |
+ std::vector<float> audio_buffer_; // Ring buffers to store input audio. |
+ size_t num_channels_; // Number of audio channels in buffer. |
+ 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
|
+ size_t buffer_size_frames_; // Number of frames in |audio_buffer|. |
+ size_t buffer_end_index_; // The index of the last frame in |audio_buffer|. |
+ size_t max_frames_; // The maximum input frames that |audio_buffer_| |
+ // can handle for each detection. |
+ |
+ DISALLOW_COPY_AND_ASSIGN(RepetitionDetector); |
+}; |
+ |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_ |