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 // | |
12 // Specifies helper classes for intelligibility enhancement. | |
13 // | |
14 | |
15 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ |
16 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ |
17 | 13 |
18 #include <complex> | 14 #include <complex> |
19 | 15 |
20 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
21 | 17 |
22 namespace webrtc { | 18 namespace webrtc { |
23 | 19 |
24 namespace intelligibility { | 20 namespace intelligibility { |
25 | 21 |
26 // Internal helper for computing the variances of a stream of arrays. | 22 // 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 | 23 // 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 | 24 // is the variance of the stream of data on the i-th positions in the |
29 // input arrays. | 25 // input arrays. |
30 // There are four methods of computation: | 26 // There are four methods of computation: |
(...skipping 29 matching lines...) Expand all Loading... |
60 void Step(const std::complex<float>* data, bool skip_fudge = false) { | 56 void Step(const std::complex<float>* data, bool skip_fudge = false) { |
61 (this->*step_func_)(data, skip_fudge); | 57 (this->*step_func_)(data, skip_fudge); |
62 } | 58 } |
63 // Reset variances to zero and forget all history. | 59 // Reset variances to zero and forget all history. |
64 void Clear(); | 60 void Clear(); |
65 // Scale the input data by |scale|. Effectively multiply variances | 61 // Scale the input data by |scale|. Effectively multiply variances |
66 // by |scale^2|. | 62 // by |scale^2|. |
67 void ApplyScale(float scale); | 63 void ApplyScale(float scale); |
68 | 64 |
69 // The current set of variances. | 65 // The current set of variances. |
70 const float* variance() const { return variance_.get(); } | 66 const float* variance() const { |
| 67 return variance_.get(); |
| 68 } |
71 | 69 |
72 // The mean value of the current set of variances. | 70 // The mean value of the current set of variances. |
73 float array_mean() const { return array_mean_; } | 71 float array_mean() const { |
| 72 return array_mean_; |
| 73 } |
74 | 74 |
75 private: | 75 private: |
76 void InfiniteStep(const std::complex<float>* data, bool dummy); | 76 void InfiniteStep(const std::complex<float>* data, bool dummy); |
77 void DecayStep(const std::complex<float>* data, bool dummy); | 77 void DecayStep(const std::complex<float>* data, bool dummy); |
78 void WindowedStep(const std::complex<float>* data, bool dummy); | 78 void WindowedStep(const std::complex<float>* data, bool dummy); |
79 void BlockedStep(const std::complex<float>* data, bool dummy); | 79 void BlockedStep(const std::complex<float>* data, bool dummy); |
80 | 80 |
81 // TODO(ekmeyerson): Switch the following running means | |
82 // and histories from rtc::scoped_ptr to std::vector. | |
83 | |
84 // The current average X and X^2. | 81 // The current average X and X^2. |
85 rtc::scoped_ptr<std::complex<float>[]> running_mean_; | 82 scoped_ptr<std::complex<float>[]> running_mean_; |
86 rtc::scoped_ptr<std::complex<float>[]> running_mean_sq_; | 83 scoped_ptr<std::complex<float>[]> running_mean_sq_; |
87 | 84 |
88 // Average X and X^2 for the current block in kStepBlocked. | 85 // Average X and X^2 for the current block in kStepBlocked. |
89 rtc::scoped_ptr<std::complex<float>[]> sub_running_mean_; | 86 scoped_ptr<std::complex<float>[]> sub_running_mean_; |
90 rtc::scoped_ptr<std::complex<float>[]> sub_running_mean_sq_; | 87 scoped_ptr<std::complex<float>[]> sub_running_mean_sq_; |
91 | 88 |
92 // Sample history for the rolling window in kStepWindowed and block-wise | 89 // Sample history for the rolling window in kStepWindowed and block-wise |
93 // histories for kStepBlocked. | 90 // histories for kStepBlocked. |
94 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> history_; | 91 scoped_ptr<scoped_ptr<std::complex<float>[]>[]> history_; |
95 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_; | 92 scoped_ptr<scoped_ptr<std::complex<float>[]>[]> subhistory_; |
96 rtc::scoped_ptr<rtc::scoped_ptr<std::complex<float>[]>[]> subhistory_sq_; | 93 scoped_ptr<scoped_ptr<std::complex<float>[]>[]> subhistory_sq_; |
97 | 94 |
98 // The current set of variances and sums for Welford's algorithm. | 95 // The current set of variances and sums for Welford's algorithm. |
99 rtc::scoped_ptr<float[]> variance_; | 96 scoped_ptr<float[]> variance_; |
100 rtc::scoped_ptr<float[]> conj_sum_; | 97 scoped_ptr<float[]> conj_sum_; |
101 | 98 |
102 const int freqs_; | 99 const int freqs_; |
103 const int window_size_; | 100 const int window_size_; |
104 const float decay_; | 101 const float decay_; |
105 int history_cursor_; | 102 int history_cursor_; |
106 int count_; | 103 int count_; |
107 float array_mean_; | 104 float array_mean_; |
108 void (VarianceArray::*step_func_)(const std::complex<float>*, bool); | 105 void (VarianceArray::*step_func_)(const std::complex<float>*, bool); |
109 }; | 106 }; |
110 | 107 |
111 // Helper class for smoothing gain changes. On each applicatiion step, the | 108 // Helper class for smoothing gain changes. On each applicatiion step, the |
112 // currently used gains are changed towards a set of settable target gains, | 109 // currently used gains are changed towards a set of settable target gains, |
113 // constrained by a limit on the magnitude of the changes. | 110 // constrained by a limit on the magnitude of the changes. |
114 class GainApplier { | 111 class GainApplier { |
115 public: | 112 public: |
116 GainApplier(int freqs, float change_limit); | 113 GainApplier(int freqs, float change_limit); |
117 | 114 |
118 // Copy |in_block| to |out_block|, multiplied by the current set of gains, | 115 // 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. | 116 // and step the current set of gains towards the target set. |
120 void Apply(const std::complex<float>* in_block, | 117 void Apply(const std::complex<float>* in_block, |
121 std::complex<float>* out_block); | 118 std::complex<float>* out_block); |
122 | 119 |
123 // Return the current target gain set. Modify this array to set the targets. | 120 // Return the current target gain set. Modify this array to set the targets. |
124 float* target() const { return target_.get(); } | 121 float* target() const { |
| 122 return target_.get(); |
| 123 } |
125 | 124 |
126 private: | 125 private: |
127 const int freqs_; | 126 const int freqs_; |
128 const float change_limit_; | 127 const float change_limit_; |
129 rtc::scoped_ptr<float[]> target_; | 128 scoped_ptr<float[]> target_; |
130 rtc::scoped_ptr<float[]> current_; | 129 scoped_ptr<float[]> current_; |
131 }; | 130 }; |
132 | 131 |
133 } // namespace intelligibility | 132 } // namespace intelligibility |
134 | 133 |
135 } // namespace webrtc | 134 } // namespace webrtc |
136 | 135 |
137 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS
_H_ | 136 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS
_H_ |
| 137 |
OLD | NEW |