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 #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
| |
16 | |
17 #include "webrtc/base/constructormagic.h" | |
18 #include "webrtc/typedefs.h" | |
19 | |
20 namespace webrtc { | |
21 | |
22 class RepetitionDetector { | |
23 public: | |
24 RepetitionDetector(); | |
25 virtual ~RepetitionDetector(); | |
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 given audio samples. When multichannel, samples should be | |
36 // interleaved and |bytes_per_sample| is the number of bytes of a stereo | |
37 // sample. | |
38 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
| |
39 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.
| |
40 | |
41 protected: | |
42 void RegisterRepetitionPatterns(const Pattern* patterns, | |
Andrew MacDonald
2015/08/28 17:43:42
Why do you need these protected methods? Is it jus
| |
43 size_t num_patterns); | |
44 void ClearRepetitionPatterns(); | |
45 virtual void ReportRepetition(int id) { } | |
46 | |
47 private: | |
48 class State { | |
49 public: | |
50 State(int id, int look_back_ms, int min_length_ms); | |
51 void Increment(bool zero); | |
52 bool HasValidReport(int sample_rate_khz) const; | |
53 bool AlreadyReported() const; | |
54 void SetReported(); | |
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_samples_; | |
64 bool all_zero_; | |
65 bool reported_; | |
66 }; | |
67 | |
68 void Reset(size_t bytes_per_sample, int sample_rate_hz); | |
69 | |
70 void AddSampleToBuffer(const void* sample); | |
71 | |
72 std::vector<State*> states_; | |
73 int max_look_back_ms_; | |
74 | |
75 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
| |
76 size_t bytes_per_sample_; // Number of bytes in each sample. | |
77 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
| |
78 size_t buffer_size_samples_; // Number of samples in |audio_buffer|. | |
79 size_t buffer_end_index_; // The index of the last sample in |audio_buffer|. | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(RepetitionDetector); | |
82 }; | |
83 | |
84 } // namespace webrtc | |
85 | |
86 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_REPETITION_DETECTOR_H_ | |
OLD | NEW |