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 |
11 // | 11 // |
12 // Specifies helper classes for intelligibility enhancement. | 12 // Specifies helper classes for intelligibility enhancement. |
13 // | 13 // |
14 | 14 |
15 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ | 15 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ |
16 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ | 16 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ |
17 | 17 |
18 #include <complex> | 18 #include <complex> |
19 | 19 |
20 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 namespace intelligibility { | 24 namespace intelligibility { |
25 | 25 |
26 // Return |current| changed towards |target|, with the change being at most | |
27 // |limit|. | |
28 float UpdateFactor(float target, float current, float limit); | |
29 | |
30 // std::isfinite for complex numbers. | |
31 bool cplxfinite(std::complex<float> c); | |
32 | |
33 // std::isnormal for complex numbers. | |
34 bool cplxnormal(std::complex<float> c); | |
35 | |
36 // Apply a small fudge to degenerate complex values. The numbers in the array | |
37 // were chosen randomly, so that even a series of all zeroes has some small | |
38 // variability. | |
39 std::complex<float> zerofudge(std::complex<float> c); | |
40 | |
41 // Incremental mean computation. Return the mean of the series with the | |
42 // mean |mean| with added |data|. | |
43 std::complex<float> NewMean(std::complex<float> mean, | |
44 std::complex<float> data, | |
hlundin-webrtc
2015/06/30 14:00:54
align
ekm
2015/07/01 23:48:26
Done.
| |
45 int count); | |
46 | |
47 void AddToMean(std::complex<float> data, int count, | |
hlundin-webrtc
2015/06/30 14:00:53
Function description missing.
ekm
2015/07/01 23:48:26
Done.
| |
48 std::complex<float>* mean); | |
hlundin-webrtc
2015/06/30 14:00:53
align
ekm
2015/07/01 23:48:26
Done.
| |
49 | |
50 | |
26 // Internal helper for computing the variances of a stream of arrays. | 51 // Internal helper for computing the variances of a stream of arrays. |
27 // The result is an array of variances per position: the i-th variance | 52 // The result is an array of variances per position: the i-th variance |
28 // is the variance of the stream of data on the i-th positions in the | 53 // is the variance of the stream of data on the i-th positions in the |
29 // input arrays. | 54 // input arrays. |
30 // There are four methods of computation: | 55 // There are four methods of computation: |
31 // * kStepInfinite computes variances from the beginning onwards | 56 // * kStepInfinite computes variances from the beginning onwards |
32 // * kStepDecaying uses a recursive exponential decay formula with a | 57 // * kStepDecaying uses a recursive exponential decay formula with a |
33 // settable forgetting factor | 58 // settable forgetting factor |
34 // * kStepWindowed computes variances within a moving window | 59 // * kStepWindowed computes variances within a moving window |
35 // * kStepBlocked is similar to kStepWindowed, but history is kept | 60 // * kStepBlocked is similar to kStepWindowed, but history is kept |
36 // as a rolling window of blocks: multiple input elements are used for | 61 // as a rolling window of blocks: multiple input elements are used for |
37 // one block and the history then consists of the variances of these blocks | 62 // one block and the history then consists of the variances of these blocks |
38 // with the same effect as kStepWindowed, but less storage, so the window | 63 // with the same effect as kStepWindowed, but less storage, so the window |
39 // can be longer | 64 // can be longer |
40 class VarianceArray { | 65 class VarianceArray { |
41 public: | 66 public: |
42 enum StepType { | 67 enum StepType { |
43 kStepInfinite = 0, | 68 kStepInfinite = 0, |
44 kStepDecaying, | 69 kStepDecaying, |
45 kStepWindowed, | 70 kStepWindowed, |
46 kStepBlocked | 71 kStepBlocked, |
72 kStepBlockBasedMovingAverage | |
47 }; | 73 }; |
48 | 74 |
49 // Construct an instance for the given input array length (|freqs|) and | 75 // Construct an instance for the given input array length (|freqs|) and |
50 // computation algorithm (|type|), with the appropriate parameters. | 76 // computation algorithm (|type|), with the appropriate parameters. |
51 // |window_size| is the number of samples for kStepWindowed and | 77 // |window_size| is the number of samples for kStepWindowed and |
52 // the number of blocks for kStepBlocked. |decay| is the forgetting factor | 78 // the number of blocks for kStepBlocked. |decay| is the forgetting factor |
53 // for kStepDecaying. | 79 // for kStepDecaying. |
54 VarianceArray(int freqs, StepType type, int window_size, float decay); | 80 VarianceArray(int freqs, StepType type, int window_size, float decay); |
55 | 81 |
56 // Add a new data point to the series and compute the new variances. | 82 // Add a new data point to the series and compute the new variances. |
(...skipping 13 matching lines...) Expand all Loading... | |
70 const float* variance() const { return variance_.get(); } | 96 const float* variance() const { return variance_.get(); } |
71 | 97 |
72 // The mean value of the current set of variances. | 98 // The mean value of the current set of variances. |
73 float array_mean() const { return array_mean_; } | 99 float array_mean() const { return array_mean_; } |
74 | 100 |
75 private: | 101 private: |
76 void InfiniteStep(const std::complex<float>* data, bool dummy); | 102 void InfiniteStep(const std::complex<float>* data, bool dummy); |
77 void DecayStep(const std::complex<float>* data, bool dummy); | 103 void DecayStep(const std::complex<float>* data, bool dummy); |
78 void WindowedStep(const std::complex<float>* data, bool dummy); | 104 void WindowedStep(const std::complex<float>* data, bool dummy); |
79 void BlockedStep(const std::complex<float>* data, bool dummy); | 105 void BlockedStep(const std::complex<float>* data, bool dummy); |
106 void BlockBasedMovingAverage(const std::complex<float>* data, bool dummy); | |
80 | 107 |
81 // TODO(ekmeyerson): Switch the following running means | 108 // TODO(ekmeyerson): Switch the following running means |
82 // and histories from rtc::scoped_ptr to std::vector. | 109 // and histories from rtc::scoped_ptr to std::vector. |
83 | 110 |
84 // The current average X and X^2. | 111 // The current average X and X^2. |
85 rtc::scoped_ptr<std::complex<float>[]> running_mean_; | 112 rtc::scoped_ptr<std::complex<float>[]> running_mean_; |
86 rtc::scoped_ptr<std::complex<float>[]> running_mean_sq_; | 113 rtc::scoped_ptr<std::complex<float>[]> running_mean_sq_; |
87 | 114 |
88 // Average X and X^2 for the current block in kStepBlocked. | 115 // Average X and X^2 for the current block in kStepBlocked. |
89 rtc::scoped_ptr<std::complex<float>[]> sub_running_mean_; | 116 rtc::scoped_ptr<std::complex<float>[]> sub_running_mean_; |
90 rtc::scoped_ptr<std::complex<float>[]> sub_running_mean_sq_; | 117 rtc::scoped_ptr<std::complex<float>[]> sub_running_mean_sq_; |
91 | 118 |
92 // Sample history for the rolling window in kStepWindowed and block-wise | 119 // Sample history for the rolling window in kStepWindowed and block-wise |
93 // histories for kStepBlocked. | 120 // histories for kStepBlocked. |
94 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> history_; | 121 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> history_; |
95 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_; | 122 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_; |
96 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_sq_; | 123 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_sq_; |
97 | 124 |
98 // The current set of variances and sums for Welford's algorithm. | 125 // The current set of variances and sums for Welford's algorithm. |
99 rtc::scoped_ptr<float[]> variance_; | 126 rtc::scoped_ptr<float[]> variance_; |
100 rtc::scoped_ptr<float[]> conj_sum_; | 127 rtc::scoped_ptr<float[]> conj_sum_; |
101 | 128 |
102 const int freqs_; | 129 const int freqs_; |
103 const int window_size_; | 130 const int window_size_; |
104 const float decay_; | 131 const float decay_; |
105 int history_cursor_; | 132 int history_cursor_; |
106 int count_; | 133 int count_; |
107 float array_mean_; | 134 float array_mean_; |
135 bool buffer_full_; | |
108 void (VarianceArray::*step_func_)(const std::complex<float>*, bool); | 136 void (VarianceArray::*step_func_)(const std::complex<float>*, bool); |
109 }; | 137 }; |
110 | 138 |
111 // Helper class for smoothing gain changes. On each applicatiion step, the | 139 // Helper class for smoothing gain changes. On each applicatiion step, the |
112 // currently used gains are changed towards a set of settable target gains, | 140 // currently used gains are changed towards a set of settable target gains, |
113 // constrained by a limit on the magnitude of the changes. | 141 // constrained by a limit on the magnitude of the changes. |
114 class GainApplier { | 142 class GainApplier { |
115 public: | 143 public: |
116 GainApplier(int freqs, float change_limit); | 144 GainApplier(int freqs, float change_limit); |
117 | 145 |
(...skipping 10 matching lines...) Expand all Loading... | |
128 const float change_limit_; | 156 const float change_limit_; |
129 rtc::scoped_ptr<float[]> target_; | 157 rtc::scoped_ptr<float[]> target_; |
130 rtc::scoped_ptr<float[]> current_; | 158 rtc::scoped_ptr<float[]> current_; |
131 }; | 159 }; |
132 | 160 |
133 } // namespace intelligibility | 161 } // namespace intelligibility |
134 | 162 |
135 } // namespace webrtc | 163 } // namespace webrtc |
136 | 164 |
137 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS _H_ | 165 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS _H_ |
OLD | NEW |