Chromium Code Reviews| 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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ |
| 13 | 13 |
| 14 #include <complex> | 14 #include <complex> |
| 15 #include <vector> | |
| 15 | 16 |
| 16 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
| 17 | 18 |
| 18 namespace webrtc { | 19 namespace webrtc { |
| 19 | 20 |
| 20 // Internal helper for computing the power of a stream of arrays. | 21 // Internal helper for computing the power of a stream of arrays. |
| 21 // The result is an array of power per position: the i-th power is the power of | 22 // The result is an array of power per position: the i-th power is the power of |
| 22 // the stream of data on the i-th positions in the input arrays. | 23 // the stream of data on the i-th positions in the input arrays. |
| 23 class PowerEstimator { | 24 class PowerEstimator { |
| 24 public: | 25 public: |
| 25 // Construct an instance for the given input array length (|freqs|), with the | 26 // Construct an instance for the given input array length (|freqs|), with the |
| 26 // appropriate parameters. |decay| is the forgetting factor. | 27 // appropriate parameters. |decay| is the forgetting factor. |
| 27 PowerEstimator(size_t freqs, float decay); | 28 PowerEstimator(size_t freqs, float decay); |
| 28 | 29 |
| 29 // Add a new data point to the series. | 30 // Add a new data point to the series. |
| 31 void Step(const float* data); | |
| 30 void Step(const std::complex<float>* data); | 32 void Step(const std::complex<float>* data); |
| 31 | 33 |
| 32 // The current power array. | 34 // The current power array. |
| 33 const float* Power(); | 35 const float* power() { return &power_[0]; }; |
|
hlundin-webrtc
2016/02/15 13:05:12
Why not return a const std::vector<float>&?
aluebs-webrtc
2016/02/19 03:56:31
Done.
| |
| 34 | 36 |
| 35 private: | 37 private: |
| 36 // TODO(ekmeyerson): Switch the following running means | 38 // The current power array. |
| 37 // and histories from rtc::scoped_ptr to std::vector. | 39 std::vector<float> power_; |
| 38 rtc::scoped_ptr<std::complex<float>[]> running_mean_sq_; | |
| 39 | 40 |
| 40 // The current magnitude array. | |
| 41 rtc::scoped_ptr<float[]> magnitude_; | |
| 42 // The current power array. | |
| 43 rtc::scoped_ptr<float[]> power_; | |
| 44 | |
| 45 const size_t num_freqs_; | |
| 46 const float decay_; | 41 const float decay_; |
| 47 }; | 42 }; |
| 48 | 43 |
| 49 // Helper class for smoothing gain changes. On each application step, the | 44 // Helper class for smoothing gain changes. On each application step, the |
| 50 // currently used gains are changed towards a set of settable target gains, | 45 // currently used gains are changed towards a set of settable target gains, |
| 51 // constrained by a limit on the magnitude of the changes. | 46 // constrained by a limit on the magnitude of the changes. |
| 52 class GainApplier { | 47 class GainApplier { |
| 53 public: | 48 public: |
| 54 GainApplier(size_t freqs, float change_limit); | 49 GainApplier(size_t freqs, float change_limit); |
| 55 | 50 |
| 56 // Copy |in_block| to |out_block|, multiplied by the current set of gains, | 51 // Copy |in_block| to |out_block|, multiplied by the current set of gains, |
| 57 // and step the current set of gains towards the target set. | 52 // and step the current set of gains towards the target set. |
| 58 void Apply(const std::complex<float>* in_block, | 53 void Apply(const std::complex<float>* in_block, |
| 59 std::complex<float>* out_block); | 54 std::complex<float>* out_block); |
| 60 | 55 |
| 61 // Return the current target gain set. Modify this array to set the targets. | 56 // Return the current target gain set. Modify this array to set the targets. |
| 62 float* target() const { return target_.get(); } | 57 float* target() const { return target_.get(); } |
| 63 | 58 |
| 64 private: | 59 private: |
| 65 const size_t num_freqs_; | 60 const size_t num_freqs_; |
| 66 const float change_limit_; | 61 const float change_limit_; |
| 67 rtc::scoped_ptr<float[]> target_; | 62 rtc::scoped_ptr<float[]> target_; |
| 68 rtc::scoped_ptr<float[]> current_; | 63 rtc::scoped_ptr<float[]> current_; |
| 69 }; | 64 }; |
| 70 | 65 |
| 71 } // namespace webrtc | 66 } // namespace webrtc |
| 72 | 67 |
| 73 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS _H_ | 68 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS _H_ |
| OLD | NEW |