| 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..86bf41cf1caad89e3001bffefbc812b4f69738bf
|
| --- /dev/null
|
| +++ b/webrtc/modules/audio_processing/repetition_detector.h
|
| @@ -0,0 +1,105 @@
|
| +/*
|
| + * 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();
|
| +
|
| + 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.
|
| +
|
| + 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_;
|
| + };
|
| +
|
| + void RegisterRepetitionPatterns(const Pattern* patterns,
|
| + size_t num_patterns);
|
| +
|
| + 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 Hz.
|
| + 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_
|
|
|