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