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 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 float UpdateFactor(float target, float current, float limit) { | 24 float UpdateFactor(float target, float current, float limit) { |
| 25 float delta = fabsf(target - current); | 25 float delta = fabsf(target - current); |
| 26 float sign = copysign(1.0f, target - current); | 26 float sign = copysign(1.0f, target - current); |
| 27 return current + sign * fminf(delta, limit); | 27 return current + sign * fminf(delta, limit); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 PowerEstimator::PowerEstimator(size_t num_freqs, | 32 PowerEstimator::PowerEstimator(size_t num_freqs, |
| 33 float decay) | 33 float decay) |
| 34 : magnitude_(new float[num_freqs]()), | 34 : power_(num_freqs, 0.f), |
| 35 power_(new float[num_freqs]()), | 35 decay_(decay) {} |
| 36 num_freqs_(num_freqs), | |
| 37 decay_(decay) { | |
| 38 memset(magnitude_.get(), 0, sizeof(*magnitude_.get()) * num_freqs_); | |
| 39 memset(power_.get(), 0, sizeof(*power_.get()) * num_freqs_); | |
| 40 } | |
| 41 | 36 |
| 42 // Compute the magnitude from the beginning, with exponential decaying of the | 37 // Compute the power from the beginning, with exponential decaying of the series |
| 43 // series data. | 38 // data. |
| 44 void PowerEstimator::Step(const std::complex<float>* data) { | 39 void PowerEstimator::Step(const float* data) { |
|
turaj
2016/02/13 00:09:43
This is a utility class so I guess it is fine to b
hlundin-webrtc
2016/02/15 13:05:12
Acknowledged.
aluebs-webrtc
2016/02/19 03:56:31
Done.
| |
| 45 for (size_t i = 0; i < num_freqs_; ++i) { | 40 for (size_t i = 0; i < power_.size(); ++i) { |
|
turaj
2016/02/13 00:09:43
maybe a DCHECK that power_ and data are of the sam
hlundin-webrtc
2016/02/15 13:05:12
You don't know the size of |data|.
aluebs-webrtc
2016/02/19 03:56:31
As Henrik points out, the size of data is unknown.
turaj
2016/02/19 16:48:47
Sorry, my mistake, no I don't think it is necessar
| |
| 46 magnitude_[i] = decay_ * magnitude_[i] + | 41 power_[i] = decay_ * power_[i] + (1.f - decay_) * data[i] * data[i]; |
| 47 (1.0f - decay_) * std::abs(data[i]); | |
| 48 } | 42 } |
| 49 } | 43 } |
| 50 | 44 |
| 51 const float* PowerEstimator::Power() { | 45 void PowerEstimator::Step(const std::complex<float>* data) { |
| 52 for (size_t i = 0; i < num_freqs_; ++i) { | 46 for (size_t i = 0; i < power_.size(); ++i) { |
|
turaj
2016/02/13 00:09:43
same comment as line 40.
| |
| 53 power_[i] = magnitude_[i] * magnitude_[i]; | 47 power_[i] = decay_ * power_[i] + |
| 48 (1.f - decay_) * std::abs(data[i]) * std::abs(data[i]); | |
| 54 } | 49 } |
| 55 return &power_[0]; | |
| 56 } | 50 } |
| 57 | 51 |
| 58 GainApplier::GainApplier(size_t freqs, float change_limit) | 52 GainApplier::GainApplier(size_t freqs, float change_limit) |
| 59 : num_freqs_(freqs), | 53 : num_freqs_(freqs), |
| 60 change_limit_(change_limit), | 54 change_limit_(change_limit), |
| 61 target_(new float[freqs]()), | 55 target_(new float[freqs]()), |
| 62 current_(new float[freqs]()) { | 56 current_(new float[freqs]()) { |
| 63 for (size_t i = 0; i < freqs; ++i) { | 57 for (size_t i = 0; i < freqs; ++i) { |
| 64 target_[i] = 1.0f; | 58 target_[i] = 1.0f; |
| 65 current_[i] = 1.0f; | 59 current_[i] = 1.0f; |
| 66 } | 60 } |
| 67 } | 61 } |
| 68 | 62 |
| 69 void GainApplier::Apply(const std::complex<float>* in_block, | 63 void GainApplier::Apply(const std::complex<float>* in_block, |
| 70 std::complex<float>* out_block) { | 64 std::complex<float>* out_block) { |
| 71 for (size_t i = 0; i < num_freqs_; ++i) { | 65 for (size_t i = 0; i < num_freqs_; ++i) { |
| 72 float factor = sqrtf(fabsf(current_[i])); | 66 float factor = sqrtf(fabsf(current_[i])); |
| 73 if (!std::isnormal(factor)) { | 67 if (!std::isnormal(factor)) { |
| 74 factor = 1.f; | 68 factor = 1.f; |
| 75 } | 69 } |
| 76 out_block[i] = factor * in_block[i]; | 70 out_block[i] = factor * in_block[i]; |
| 77 current_[i] = UpdateFactor(target_[i], current_[i], change_limit_); | 71 current_[i] = UpdateFactor(target_[i], current_[i], change_limit_); |
| 78 } | 72 } |
| 79 } | 73 } |
| 80 | 74 |
| 81 } // namespace webrtc | 75 } // namespace webrtc |
| OLD | NEW |