Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Unified Diff: webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc

Issue 1729753003: Fix the stereo support in IntelligibilityEnhancer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@gains2
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 37b18137d4589647b8cd0c2e5a5caf4a01aa8042..33f4ec5f5a32570f82d5579eaa0e5f7501bce9c4 100644
--- a/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc
+++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.cc
@@ -60,23 +60,6 @@ void MapToErbBands(const float* pow,
} // namespace
-IntelligibilityEnhancer::TransformCallback::TransformCallback(
- IntelligibilityEnhancer* parent)
- : parent_(parent) {
-}
-
-void IntelligibilityEnhancer::TransformCallback::ProcessAudioBlock(
- const std::complex<float>* const* in_block,
- size_t in_channels,
- size_t frames,
- size_t /* out_channels */,
- std::complex<float>* const* out_block) {
- RTC_DCHECK_EQ(parent_->freqs_, frames);
- for (size_t i = 0; i < in_channels; ++i) {
- parent_->ProcessClearBlock(in_block[i], out_block[i]);
- }
-}
-
IntelligibilityEnhancer::IntelligibilityEnhancer(int sample_rate_hz,
size_t num_render_channels)
: freqs_(RealFourier::ComplexLength(
@@ -88,24 +71,17 @@ IntelligibilityEnhancer::IntelligibilityEnhancer(int sample_rate_hz,
clear_power_estimator_(freqs_, kDecayRate),
noise_power_estimator_(
new intelligibility::PowerEstimator<float>(freqs_, kDecayRate)),
- filtered_clear_pow_(new float[bank_size_]),
- filtered_noise_pow_(new float[bank_size_]),
- center_freqs_(new float[bank_size_]),
+ filtered_clear_pow_(bank_size_, 0.f),
+ filtered_noise_pow_(bank_size_, 0.f),
+ center_freqs_(bank_size_),
render_filter_bank_(CreateErbBank(freqs_)),
- gains_eq_(new float[bank_size_]),
+ gains_eq_(bank_size_),
gain_applier_(freqs_, kMaxRelativeGainChange),
- temp_render_out_buffer_(chunk_length_, num_render_channels_),
- render_callback_(this),
audio_s16_(chunk_length_),
chunks_since_voice_(kSpeechOffsetDelay),
is_speech_(false) {
RTC_DCHECK_LE(kRho, 1.f);
- memset(filtered_clear_pow_.get(), 0,
- bank_size_ * sizeof(filtered_clear_pow_[0]));
- memset(filtered_noise_pow_.get(), 0,
- bank_size_ * sizeof(filtered_noise_pow_[0]));
-
const size_t erb_index = static_cast<size_t>(
ceilf(11.17f * logf((kClipFreqKhz + 0.312f) / (kClipFreqKhz + 14.6575f)) +
43.f));
@@ -116,7 +92,7 @@ IntelligibilityEnhancer::IntelligibilityEnhancer(int sample_rate_hz,
WindowGenerator::KaiserBesselDerived(kKbdAlpha, window_size, &kbd_window[0]);
render_mangler_.reset(new LappedTransform(
num_render_channels_, num_render_channels_, chunk_length_, &kbd_window[0],
- window_size, window_size / 2, &render_callback_));
+ window_size, window_size / 2, this));
}
void IntelligibilityEnhancer::SetCaptureNoiseEstimate(
@@ -136,38 +112,40 @@ void IntelligibilityEnhancer::ProcessRenderAudio(float* const* audio,
RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz);
RTC_CHECK_EQ(num_render_channels_, num_channels);
is_speech_ = IsSpeech(audio[0]);
- render_mangler_->ProcessChunk(audio, temp_render_out_buffer_.channels());
- for (size_t i = 0; i < num_render_channels_; ++i) {
- memcpy(audio[i], temp_render_out_buffer_.channels()[i],
- chunk_length_ * sizeof(**audio));
- }
+ render_mangler_->ProcessChunk(audio, audio);
}
-void IntelligibilityEnhancer::ProcessClearBlock(
- const std::complex<float>* in_block,
- std::complex<float>* out_block) {
+void IntelligibilityEnhancer::ProcessAudioBlock(
+ const std::complex<float>* const* in_block,
+ size_t in_channels,
+ size_t frames,
+ size_t /* out_channels */,
+ std::complex<float>* const* out_block) {
+ RTC_DCHECK_EQ(freqs_, frames);
if (is_speech_) {
- clear_power_estimator_.Step(in_block);
+ clear_power_estimator_.Step(in_block[0]);
turaj 2016/02/24 16:00:17 I suppose this change and changes in lines 146-148
aluebs-webrtc 2016/02/25 00:18:37 Yes, as you point out, the main change is removing
}
const std::vector<float>& clear_power = clear_power_estimator_.power();
const std::vector<float>& noise_power = noise_power_estimator_->power();
MapToErbBands(&clear_power[0], render_filter_bank_,
- filtered_clear_pow_.get());
+ &filtered_clear_pow_[0]);
hlundin-webrtc 2016/02/24 10:17:03 I suggest you use .data() instead of &...[0]. See
aluebs-webrtc 2016/02/25 00:18:37 I am aware of that, but I thought it was still not
MapToErbBands(&noise_power[0], capture_filter_bank_,
- filtered_noise_pow_.get());
- SolveForGainsGivenLambda(kLambdaTop, start_freq_, gains_eq_.get());
+ &filtered_noise_pow_[0]);
+ SolveForGainsGivenLambda(kLambdaTop, start_freq_, &gains_eq_[0]);
const float power_target =
std::accumulate(&clear_power[0], &clear_power[0] + freqs_, 0.f);
const float power_top =
- DotProduct(gains_eq_.get(), filtered_clear_pow_.get(), bank_size_);
- SolveForGainsGivenLambda(kLambdaBot, start_freq_, gains_eq_.get());
+ DotProduct(&gains_eq_[0], &filtered_clear_pow_[0], bank_size_);
+ SolveForGainsGivenLambda(kLambdaBot, start_freq_, &gains_eq_[0]);
const float power_bot =
- DotProduct(gains_eq_.get(), filtered_clear_pow_.get(), bank_size_);
+ DotProduct(&gains_eq_[0], &filtered_clear_pow_[0], bank_size_);
if (power_target >= power_bot && power_target <= power_top) {
SolveForLambda(power_target);
UpdateErbGains();
} // Else experiencing power underflow, so do nothing.
- gain_applier_.Apply(in_block, out_block);
+ for (size_t i = 0; i < in_channels; ++i) {
+ gain_applier_.Apply(in_block[i], out_block[i]);
+ }
}
void IntelligibilityEnhancer::SolveForLambda(float power_target) {
@@ -182,9 +160,9 @@ void IntelligibilityEnhancer::SolveForLambda(float power_target) {
int iters = 0;
while (std::fabs(power_ratio - 1.f) > kConvergeThresh && iters <= kMaxIters) {
const float lambda = (lambda_bot + lambda_top) / 2.f;
- SolveForGainsGivenLambda(lambda, start_freq_, gains_eq_.get());
+ SolveForGainsGivenLambda(lambda, start_freq_, &gains_eq_[0]);
const float power =
- DotProduct(gains_eq_.get(), filtered_clear_pow_.get(), bank_size_);
+ DotProduct(&gains_eq_[0], &filtered_clear_pow_[0], bank_size_);
if (power < power_target) {
lambda_bot = lambda;
} else {
@@ -286,8 +264,8 @@ void IntelligibilityEnhancer::SolveForGainsGivenLambda(float lambda,
float* sols) {
const float kMinPower = 1e-5;
- const float* pow_x0 = filtered_clear_pow_.get();
- const float* pow_n0 = filtered_noise_pow_.get();
+ const float* pow_x0 = &filtered_clear_pow_[0];
+ const float* pow_n0 = &filtered_noise_pow_[0];
for (size_t n = 0; n < start_freq; ++n) {
sols[n] = 1.f;

Powered by Google App Engine
This is Rietveld 408576698