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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 kStepDecaying, | 44 kStepDecaying, |
45 kStepWindowed, | 45 kStepWindowed, |
46 kStepBlocked | 46 kStepBlocked |
47 }; | 47 }; |
48 | 48 |
49 // Construct an instance for the given input array length (|freqs|) and | 49 // Construct an instance for the given input array length (|freqs|) and |
50 // computation algorithm (|type|), with the appropriate parameters. | 50 // computation algorithm (|type|), with the appropriate parameters. |
51 // |window_size| is the number of samples for kStepWindowed and | 51 // |window_size| is the number of samples for kStepWindowed and |
52 // the number of blocks for kStepBlocked. |decay| is the forgetting factor | 52 // the number of blocks for kStepBlocked. |decay| is the forgetting factor |
53 // for kStepDecaying. | 53 // for kStepDecaying. |
54 VarianceArray(int freqs, StepType type, int window_size, float decay); | 54 VarianceArray(size_t freqs, StepType type, size_t window_size, float decay); |
55 | 55 |
56 // Add a new data point to the series and compute the new variances. | 56 // Add a new data point to the series and compute the new variances. |
57 // TODO(bercic) |skip_fudge| is a flag for kStepWindowed and kStepDecaying, | 57 // TODO(bercic) |skip_fudge| is a flag for kStepWindowed and kStepDecaying, |
58 // whether they should skip adding some small dummy values to the input | 58 // whether they should skip adding some small dummy values to the input |
59 // to prevent problems with all-zero inputs. Can probably be removed. | 59 // to prevent problems with all-zero inputs. Can probably be removed. |
60 void Step(const std::complex<float>* data, bool skip_fudge = false) { | 60 void Step(const std::complex<float>* data, bool skip_fudge = false) { |
61 (this->*step_func_)(data, skip_fudge); | 61 (this->*step_func_)(data, skip_fudge); |
62 } | 62 } |
63 // Reset variances to zero and forget all history. | 63 // Reset variances to zero and forget all history. |
64 void Clear(); | 64 void Clear(); |
(...skipping 27 matching lines...) Expand all Loading... |
92 // Sample history for the rolling window in kStepWindowed and block-wise | 92 // Sample history for the rolling window in kStepWindowed and block-wise |
93 // histories for kStepBlocked. | 93 // histories for kStepBlocked. |
94 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> history_; | 94 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> history_; |
95 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_; | 95 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_; |
96 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_sq_; | 96 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_sq_; |
97 | 97 |
98 // The current set of variances and sums for Welford's algorithm. | 98 // The current set of variances and sums for Welford's algorithm. |
99 rtc::scoped_ptr<float[]> variance_; | 99 rtc::scoped_ptr<float[]> variance_; |
100 rtc::scoped_ptr<float[]> conj_sum_; | 100 rtc::scoped_ptr<float[]> conj_sum_; |
101 | 101 |
102 const int freqs_; | 102 const size_t freqs_; |
103 const int window_size_; | 103 const size_t window_size_; |
104 const float decay_; | 104 const float decay_; |
105 int history_cursor_; | 105 size_t history_cursor_; |
106 int count_; | 106 size_t count_; |
107 float array_mean_; | 107 float array_mean_; |
108 void (VarianceArray::*step_func_)(const std::complex<float>*, bool); | 108 void (VarianceArray::*step_func_)(const std::complex<float>*, bool); |
109 }; | 109 }; |
110 | 110 |
111 // Helper class for smoothing gain changes. On each applicatiion step, the | 111 // Helper class for smoothing gain changes. On each applicatiion step, the |
112 // currently used gains are changed towards a set of settable target gains, | 112 // currently used gains are changed towards a set of settable target gains, |
113 // constrained by a limit on the magnitude of the changes. | 113 // constrained by a limit on the magnitude of the changes. |
114 class GainApplier { | 114 class GainApplier { |
115 public: | 115 public: |
116 GainApplier(int freqs, float change_limit); | 116 GainApplier(size_t freqs, float change_limit); |
117 | 117 |
118 // Copy |in_block| to |out_block|, multiplied by the current set of gains, | 118 // Copy |in_block| to |out_block|, multiplied by the current set of gains, |
119 // and step the current set of gains towards the target set. | 119 // and step the current set of gains towards the target set. |
120 void Apply(const std::complex<float>* in_block, | 120 void Apply(const std::complex<float>* in_block, |
121 std::complex<float>* out_block); | 121 std::complex<float>* out_block); |
122 | 122 |
123 // Return the current target gain set. Modify this array to set the targets. | 123 // Return the current target gain set. Modify this array to set the targets. |
124 float* target() const { return target_.get(); } | 124 float* target() const { return target_.get(); } |
125 | 125 |
126 private: | 126 private: |
127 const int freqs_; | 127 const size_t freqs_; |
128 const float change_limit_; | 128 const float change_limit_; |
129 rtc::scoped_ptr<float[]> target_; | 129 rtc::scoped_ptr<float[]> target_; |
130 rtc::scoped_ptr<float[]> current_; | 130 rtc::scoped_ptr<float[]> current_; |
131 }; | 131 }; |
132 | 132 |
133 } // namespace intelligibility | 133 } // namespace intelligibility |
134 | 134 |
135 } // namespace webrtc | 135 } // namespace webrtc |
136 | 136 |
137 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS
_H_ | 137 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS
_H_ |
OLD | NEW |