Chromium Code Reviews| Index: webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc |
| diff --git a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc |
| index d3feedce5a332f9c4ede71afa16a69d78c759958..af36e0296268a787d126690b452eba9f28ffd237 100644 |
| --- a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc |
| +++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc |
| @@ -30,7 +30,7 @@ const int kChunkSizeMs = 10; // Size provided by APM. |
| const float kClipFreqKhz = 0.2f; |
| const float kKbdAlpha = 1.5f; |
| const float kLambdaBot = -1.0f; // Extreme values in bisection |
| -const float kLambdaTop = -10e-18f; // search for lamda. |
| +const float kLambdaTop = -1e-5; // search for lamda. |
| const float kVoiceProbabilityThreshold = 0.02; |
| // Number of chunks after voice activity which is still considered speech. |
| const size_t kSpeechOffsetDelay = 80; |
| @@ -164,15 +164,13 @@ void IntelligibilityEnhancer::ProcessClearBlock( |
| const float power_bot = |
| DotProduct(gains_eq_.get(), filtered_clear_pow_.get(), bank_size_); |
| if (power_target >= power_bot && power_target <= power_top) { |
| - SolveForLambda(power_target, power_bot, power_top); |
| + SolveForLambda(power_target); |
| UpdateErbGains(); |
| } // Else experiencing power underflow, so do nothing. |
| gain_applier_.Apply(in_block, out_block); |
| } |
| -void IntelligibilityEnhancer::SolveForLambda(float power_target, |
| - float power_bot, |
| - float power_top) { |
| +void IntelligibilityEnhancer::SolveForLambda(float power_target) { |
| const float kConvergeThresh = 0.001f; // TODO(ekmeyerson): Find best values |
| const int kMaxIters = 100; // for these, based on experiments. |
| @@ -183,7 +181,7 @@ void IntelligibilityEnhancer::SolveForLambda(float power_target, |
| float power_ratio = 2.f; // Ratio of achieved power to target power. |
| int iters = 0; |
| while (std::fabs(power_ratio - 1.f) > kConvergeThresh && iters <= kMaxIters) { |
| - const float lambda = lambda_bot + (lambda_top - lambda_bot) / 2.f; |
| + const float lambda = (lambda_bot + lambda_top) / 2.f; |
| SolveForGainsGivenLambda(lambda, start_freq_, gains_eq_.get()); |
| const float power = |
| DotProduct(gains_eq_.get(), filtered_clear_pow_.get(), bank_size_); |
| @@ -288,7 +286,8 @@ std::vector<std::vector<float>> IntelligibilityEnhancer::CreateErbBank( |
| void IntelligibilityEnhancer::SolveForGainsGivenLambda(float lambda, |
| size_t start_freq, |
| float* sols) { |
| - bool quadratic = (kRho < 1.f); |
| + const float kMinPower = 1e-5; |
| + |
| const float* pow_x0 = filtered_clear_pow_.get(); |
| const float* pow_n0 = filtered_noise_pow_.get(); |
| @@ -297,20 +296,22 @@ void IntelligibilityEnhancer::SolveForGainsGivenLambda(float lambda, |
| } |
| // Analytic solution for optimal gains. See paper for derivation. |
| - for (size_t n = start_freq - 1; n < bank_size_; ++n) { |
| - float alpha0, beta0, gamma0; |
| - gamma0 = 0.5f * kRho * pow_x0[n] * pow_n0[n] + |
| - lambda * pow_x0[n] * pow_n0[n] * pow_n0[n]; |
| - beta0 = lambda * pow_x0[n] * (2 - kRho) * pow_x0[n] * pow_n0[n]; |
| - if (quadratic) { |
| - alpha0 = lambda * pow_x0[n] * (1 - kRho) * pow_x0[n] * pow_x0[n]; |
| - sols[n] = |
| - (-beta0 - sqrtf(beta0 * beta0 - 4 * alpha0 * gamma0)) / |
| - (2 * alpha0 + std::numeric_limits<float>::epsilon()); |
| + for (size_t n = start_freq; n < bank_size_; ++n) { |
| + if (pow_x0[n] < kMinPower || pow_n0[n] < kMinPower) { |
| + sols[n] = 1.f; |
| } else { |
| - sols[n] = -gamma0 / beta0; |
| + float gamma0 = 0.5f * kRho * pow_x0[n] * pow_n0[n] + |
|
hlundin-webrtc
2016/02/22 12:59:22
I like local consts...
aluebs-webrtc
2016/02/22 23:56:10
I like them as well, but apparently I have a hard
|
| + lambda * pow_x0[n] * pow_n0[n] * pow_n0[n]; |
| + float beta0 = lambda * pow_x0[n] * (2.f - kRho) * pow_x0[n] * pow_n0[n]; |
| + float alpha0 = lambda * pow_x0[n] * (1.f - kRho) * pow_x0[n] * pow_x0[n]; |
| + if (beta0 * beta0 < 4.f * alpha0 * gamma0) { |
|
hlundin-webrtc
2016/02/22 12:59:22
You are essentially calculating beta0 * beta0 - 4.
aluebs-webrtc
2016/02/22 23:56:11
Good point, done. Although I am not creative enoug
hlundin-webrtc
2016/02/24 09:51:00
I don't know the algorithm good enough to suggest
turaj
2016/02/24 15:26:42
If you consider my suggestion of using max(0, b^2
aluebs-webrtc
2016/02/24 23:40:48
No name is best name :)
|
| + sols[n] = -beta0 / (2.f * alpha0); |
|
hlundin-webrtc
2016/02/22 12:59:22
This is not the same as the old code, right?
turaj
2016/02/22 16:05:20
My interpretation of the paper Eq 18 is that the q
aluebs-webrtc
2016/02/22 23:56:10
I agree that the quadratic equation always has rea
turaj
2016/02/24 15:26:42
Thanks for the explanation, it makes total sense,
aluebs-webrtc
2016/02/24 23:40:47
That is a great point, done.
|
| + } else { |
| + sols[n] = (-beta0 - sqrtf(beta0 * beta0 - 4.f * alpha0 * gamma0)) / |
|
hlundin-webrtc
2016/02/22 12:59:22
No need for regularization any longer?
aluebs-webrtc
2016/02/22 23:56:10
No, because now I check for a minimum power in lin
hlundin-webrtc
2016/02/24 09:51:00
You may want to add a DCHECK to document/verify yo
aluebs-webrtc
2016/02/24 23:40:47
Done.
|
| + (2.f * alpha0); |
| + } |
| + sols[n] = fmax(0.f, sols[n]); |
| } |
| - sols[n] = fmax(0, sols[n]); |
| } |
| } |