Chromium Code Reviews| 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..97ff8d561aac12842e3046822444f6bfc006ad4b |
| --- /dev/null |
| +++ b/webrtc/modules/audio_processing/repetition_detector.h |
| @@ -0,0 +1,86 @@ |
| +/* |
| + * 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 <memory> |
|
hlundin-webrtc
2015/08/31 13:46:46
Order of includes.
minyue-webrtc
2015/09/03 13:23:58
Yes, but memory is not needed any longer now
|
| + |
| +#include "webrtc/base/constructormagic.h" |
| +#include "webrtc/typedefs.h" |
| + |
| +namespace webrtc { |
| + |
| +class RepetitionDetector { |
| + public: |
| + RepetitionDetector(); |
| + virtual ~RepetitionDetector(); |
| + |
| + 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 given audio samples. When multichannel, samples should be |
| + // interleaved and |bytes_per_sample| is the number of bytes of a stereo |
| + // sample. |
| + void Detect(const void* data, size_t bytes_per_sample, |
|
Andrew MacDonald
2015/08/28 17:43:42
Don't use void. Be confident about your type safet
minyue-webrtc
2015/09/01 10:21:48
A benefit of this is that we can compare even larg
ajm
2015/09/02 05:28:28
Yes, make them explicit. I see that lack of type s
minyue-webrtc
2015/09/03 13:23:58
Ok. I take it. To make it simple enough, I even re
|
| + size_t samples_per_channel, int sample_rate_hz); |
|
Andrew MacDonald
2015/08/28 17:43:42
We've been using num_frames for the samples_per_ch
minyue-webrtc
2015/09/01 10:21:48
Ok. will change.
|
| + |
| + protected: |
| + void RegisterRepetitionPatterns(const Pattern* patterns, |
|
Andrew MacDonald
2015/08/28 17:43:42
Why do you need these protected methods? Is it jus
|
| + size_t num_patterns); |
| + void ClearRepetitionPatterns(); |
| + virtual void ReportRepetition(int id) { } |
| + |
| + private: |
| + class State { |
| + public: |
| + State(int id, int look_back_ms, int min_length_ms); |
| + void Increment(bool zero); |
| + bool HasValidReport(int sample_rate_khz) const; |
| + bool AlreadyReported() const; |
| + void SetReported(); |
| + 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_samples_; |
| + bool all_zero_; |
| + bool reported_; |
| + }; |
| + |
| + void Reset(size_t bytes_per_sample, int sample_rate_hz); |
| + |
| + void AddSampleToBuffer(const void* sample); |
| + |
| + std::vector<State*> states_; |
| + int max_look_back_ms_; |
| + |
| + std::unique_ptr<char[]> audio_buffer_; // Ring buffers to store input audio. |
|
Andrew MacDonald
2015/08/28 17:43:42
unique_ptr is disallowed because it's C++11 standa
minyue-webrtc
2015/09/01 10:21:48
Now I tried to switch to RingBuffer and I see a po
ajm
2015/09/02 05:28:28
Ah OK. Use a vector here then.
minyue-webrtc
2015/09/03 13:23:58
will scoped_ptr be better, I feel that vector has
Andrew MacDonald
2015/09/07 06:52:18
You can expect an empty vector to consume 12 bytes
|
| + size_t bytes_per_sample_; // Number of bytes in each sample. |
| + int sample_rate_hz_; // Sample rate in kHz. |
|
hlundin-webrtc
2015/08/31 13:46:46
Name says Hz, comment says kHz.
minyue-webrtc
2015/09/01 10:21:48
Thanks, it was kHz, but to handle 44.1, I made it
|
| + size_t buffer_size_samples_; // Number of samples in |audio_buffer|. |
| + size_t buffer_end_index_; // The index of the last sample in |audio_buffer|. |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RepetitionDetector); |
| +}; |
| + |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_ |