OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // Apply a small fudge to degenerate complex values. The numbers in the array | 30 // Apply a small fudge to degenerate complex values. The numbers in the array |
31 // were chosen randomly, so that even a series of all zeroes has some small | 31 // were chosen randomly, so that even a series of all zeroes has some small |
32 // variability. | 32 // variability. |
33 std::complex<float> zerofudge(std::complex<float> c); | 33 std::complex<float> zerofudge(std::complex<float> c); |
34 | 34 |
35 // Incremental mean computation. Return the mean of the series with the | 35 // Incremental mean computation. Return the mean of the series with the |
36 // mean |mean| with added |data|. | 36 // mean |mean| with added |data|. |
37 std::complex<float> NewMean(std::complex<float> mean, | 37 std::complex<float> NewMean(std::complex<float> mean, |
38 std::complex<float> data, | 38 std::complex<float> data, |
39 int count); | 39 size_t count); |
40 | 40 |
41 // Updates |mean| with added |data|; | 41 // Updates |mean| with added |data|; |
42 void AddToMean(std::complex<float> data, int count, std::complex<float>* mean); | 42 void AddToMean(std::complex<float> data, |
| 43 size_t count, |
| 44 std::complex<float>* mean); |
43 | 45 |
44 // Internal helper for computing the variances of a stream of arrays. | 46 // Internal helper for computing the variances of a stream of arrays. |
45 // The result is an array of variances per position: the i-th variance | 47 // The result is an array of variances per position: the i-th variance |
46 // is the variance of the stream of data on the i-th positions in the | 48 // is the variance of the stream of data on the i-th positions in the |
47 // input arrays. | 49 // input arrays. |
48 // There are four methods of computation: | 50 // There are four methods of computation: |
49 // * kStepInfinite computes variances from the beginning onwards | 51 // * kStepInfinite computes variances from the beginning onwards |
50 // * kStepDecaying uses a recursive exponential decay formula with a | 52 // * kStepDecaying uses a recursive exponential decay formula with a |
51 // settable forgetting factor | 53 // settable forgetting factor |
52 // * kStepWindowed computes variances within a moving window | 54 // * kStepWindowed computes variances within a moving window |
(...skipping 10 matching lines...) Expand all Loading... |
63 kStepWindowed, | 65 kStepWindowed, |
64 kStepBlocked, | 66 kStepBlocked, |
65 kStepBlockBasedMovingAverage | 67 kStepBlockBasedMovingAverage |
66 }; | 68 }; |
67 | 69 |
68 // Construct an instance for the given input array length (|freqs|) and | 70 // Construct an instance for the given input array length (|freqs|) and |
69 // computation algorithm (|type|), with the appropriate parameters. | 71 // computation algorithm (|type|), with the appropriate parameters. |
70 // |window_size| is the number of samples for kStepWindowed and | 72 // |window_size| is the number of samples for kStepWindowed and |
71 // the number of blocks for kStepBlocked. |decay| is the forgetting factor | 73 // the number of blocks for kStepBlocked. |decay| is the forgetting factor |
72 // for kStepDecaying. | 74 // for kStepDecaying. |
73 VarianceArray(int freqs, StepType type, int window_size, float decay); | 75 VarianceArray(size_t freqs, StepType type, size_t window_size, float decay); |
74 | 76 |
75 // Add a new data point to the series and compute the new variances. | 77 // Add a new data point to the series and compute the new variances. |
76 // TODO(bercic) |skip_fudge| is a flag for kStepWindowed and kStepDecaying, | 78 // TODO(bercic) |skip_fudge| is a flag for kStepWindowed and kStepDecaying, |
77 // whether they should skip adding some small dummy values to the input | 79 // whether they should skip adding some small dummy values to the input |
78 // to prevent problems with all-zero inputs. Can probably be removed. | 80 // to prevent problems with all-zero inputs. Can probably be removed. |
79 void Step(const std::complex<float>* data, bool skip_fudge = false) { | 81 void Step(const std::complex<float>* data, bool skip_fudge = false) { |
80 (this->*step_func_)(data, skip_fudge); | 82 (this->*step_func_)(data, skip_fudge); |
81 } | 83 } |
82 // Reset variances to zero and forget all history. | 84 // Reset variances to zero and forget all history. |
83 void Clear(); | 85 void Clear(); |
(...skipping 28 matching lines...) Expand all Loading... |
112 // Sample history for the rolling window in kStepWindowed and block-wise | 114 // Sample history for the rolling window in kStepWindowed and block-wise |
113 // histories for kStepBlocked. | 115 // histories for kStepBlocked. |
114 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> history_; | 116 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> history_; |
115 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_; | 117 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_; |
116 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_sq_; | 118 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_sq_; |
117 | 119 |
118 // The current set of variances and sums for Welford's algorithm. | 120 // The current set of variances and sums for Welford's algorithm. |
119 rtc::scoped_ptr<float[]> variance_; | 121 rtc::scoped_ptr<float[]> variance_; |
120 rtc::scoped_ptr<float[]> conj_sum_; | 122 rtc::scoped_ptr<float[]> conj_sum_; |
121 | 123 |
122 const int num_freqs_; | 124 const size_t num_freqs_; |
123 const int window_size_; | 125 const size_t window_size_; |
124 const float decay_; | 126 const float decay_; |
125 int history_cursor_; | 127 size_t history_cursor_; |
126 int count_; | 128 size_t count_; |
127 float array_mean_; | 129 float array_mean_; |
128 bool buffer_full_; | 130 bool buffer_full_; |
129 void (VarianceArray::*step_func_)(const std::complex<float>*, bool); | 131 void (VarianceArray::*step_func_)(const std::complex<float>*, bool); |
130 }; | 132 }; |
131 | 133 |
132 // Helper class for smoothing gain changes. On each applicatiion step, the | 134 // Helper class for smoothing gain changes. On each applicatiion step, the |
133 // currently used gains are changed towards a set of settable target gains, | 135 // currently used gains are changed towards a set of settable target gains, |
134 // constrained by a limit on the magnitude of the changes. | 136 // constrained by a limit on the magnitude of the changes. |
135 class GainApplier { | 137 class GainApplier { |
136 public: | 138 public: |
137 GainApplier(int freqs, float change_limit); | 139 GainApplier(size_t freqs, float change_limit); |
138 | 140 |
139 // Copy |in_block| to |out_block|, multiplied by the current set of gains, | 141 // Copy |in_block| to |out_block|, multiplied by the current set of gains, |
140 // and step the current set of gains towards the target set. | 142 // and step the current set of gains towards the target set. |
141 void Apply(const std::complex<float>* in_block, | 143 void Apply(const std::complex<float>* in_block, |
142 std::complex<float>* out_block); | 144 std::complex<float>* out_block); |
143 | 145 |
144 // Return the current target gain set. Modify this array to set the targets. | 146 // Return the current target gain set. Modify this array to set the targets. |
145 float* target() const { return target_.get(); } | 147 float* target() const { return target_.get(); } |
146 | 148 |
147 private: | 149 private: |
148 const int num_freqs_; | 150 const size_t num_freqs_; |
149 const float change_limit_; | 151 const float change_limit_; |
150 rtc::scoped_ptr<float[]> target_; | 152 rtc::scoped_ptr<float[]> target_; |
151 rtc::scoped_ptr<float[]> current_; | 153 rtc::scoped_ptr<float[]> current_; |
152 }; | 154 }; |
153 | 155 |
154 } // namespace intelligibility | 156 } // namespace intelligibility |
155 | 157 |
156 } // namespace webrtc | 158 } // namespace webrtc |
157 | 159 |
158 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS
_H_ | 160 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS
_H_ |
OLD | NEW |