| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 IntelligibilityEnhancer::AudioSource source) | 51 IntelligibilityEnhancer::AudioSource source) |
| 52 : parent_(parent), source_(source) { | 52 : parent_(parent), source_(source) { |
| 53 } | 53 } |
| 54 | 54 |
| 55 void IntelligibilityEnhancer::TransformCallback::ProcessAudioBlock( | 55 void IntelligibilityEnhancer::TransformCallback::ProcessAudioBlock( |
| 56 const complex<float>* const* in_block, | 56 const complex<float>* const* in_block, |
| 57 int in_channels, | 57 int in_channels, |
| 58 size_t frames, | 58 size_t frames, |
| 59 int /* out_channels */, | 59 int /* out_channels */, |
| 60 complex<float>* const* out_block) { | 60 complex<float>* const* out_block) { |
| 61 DCHECK_EQ(parent_->freqs_, frames); | 61 RTC_DCHECK_EQ(parent_->freqs_, frames); |
| 62 for (int i = 0; i < in_channels; ++i) { | 62 for (int i = 0; i < in_channels; ++i) { |
| 63 parent_->DispatchAudio(source_, in_block[i], out_block[i]); | 63 parent_->DispatchAudio(source_, in_block[i], out_block[i]); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 IntelligibilityEnhancer::IntelligibilityEnhancer() | 67 IntelligibilityEnhancer::IntelligibilityEnhancer() |
| 68 : IntelligibilityEnhancer(IntelligibilityEnhancer::Config()) { | 68 : IntelligibilityEnhancer(IntelligibilityEnhancer::Config()) { |
| 69 } | 69 } |
| 70 | 70 |
| 71 IntelligibilityEnhancer::IntelligibilityEnhancer(const Config& config) | 71 IntelligibilityEnhancer::IntelligibilityEnhancer(const Config& config) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 96 rho_(new float[bank_size_]), | 96 rho_(new float[bank_size_]), |
| 97 gains_eq_(new float[bank_size_]), | 97 gains_eq_(new float[bank_size_]), |
| 98 gain_applier_(freqs_, config.gain_change_limit), | 98 gain_applier_(freqs_, config.gain_change_limit), |
| 99 temp_render_out_buffer_(chunk_length_, num_render_channels_), | 99 temp_render_out_buffer_(chunk_length_, num_render_channels_), |
| 100 temp_capture_out_buffer_(chunk_length_, num_capture_channels_), | 100 temp_capture_out_buffer_(chunk_length_, num_capture_channels_), |
| 101 kbd_window_(new float[window_size_]), | 101 kbd_window_(new float[window_size_]), |
| 102 render_callback_(this, AudioSource::kRenderStream), | 102 render_callback_(this, AudioSource::kRenderStream), |
| 103 capture_callback_(this, AudioSource::kCaptureStream), | 103 capture_callback_(this, AudioSource::kCaptureStream), |
| 104 block_count_(0), | 104 block_count_(0), |
| 105 analysis_step_(0) { | 105 analysis_step_(0) { |
| 106 DCHECK_LE(config.rho, 1.0f); | 106 RTC_DCHECK_LE(config.rho, 1.0f); |
| 107 | 107 |
| 108 CreateErbBank(); | 108 CreateErbBank(); |
| 109 | 109 |
| 110 // Assumes all rho equal. | 110 // Assumes all rho equal. |
| 111 for (size_t i = 0; i < bank_size_; ++i) { | 111 for (size_t i = 0; i < bank_size_; ++i) { |
| 112 rho_[i] = config.rho * config.rho; | 112 rho_[i] = config.rho * config.rho; |
| 113 } | 113 } |
| 114 | 114 |
| 115 float freqs_khz = kClipFreq / 1000.0f; | 115 float freqs_khz = kClipFreq / 1000.0f; |
| 116 size_t erb_index = static_cast<size_t>(ceilf( | 116 size_t erb_index = static_cast<size_t>(ceilf( |
| 117 11.17f * logf((freqs_khz + 0.312f) / (freqs_khz + 14.6575f)) + 43.0f)); | 117 11.17f * logf((freqs_khz + 0.312f) / (freqs_khz + 14.6575f)) + 43.0f)); |
| 118 start_freq_ = std::max(static_cast<size_t>(1), erb_index * erb_resolution_); | 118 start_freq_ = std::max(static_cast<size_t>(1), erb_index * erb_resolution_); |
| 119 | 119 |
| 120 WindowGenerator::KaiserBesselDerived(kKbdAlpha, window_size_, | 120 WindowGenerator::KaiserBesselDerived(kKbdAlpha, window_size_, |
| 121 kbd_window_.get()); | 121 kbd_window_.get()); |
| 122 render_mangler_.reset(new LappedTransform( | 122 render_mangler_.reset(new LappedTransform( |
| 123 num_render_channels_, num_render_channels_, chunk_length_, | 123 num_render_channels_, num_render_channels_, chunk_length_, |
| 124 kbd_window_.get(), window_size_, window_size_ / 2, &render_callback_)); | 124 kbd_window_.get(), window_size_, window_size_ / 2, &render_callback_)); |
| 125 capture_mangler_.reset(new LappedTransform( | 125 capture_mangler_.reset(new LappedTransform( |
| 126 num_capture_channels_, num_capture_channels_, chunk_length_, | 126 num_capture_channels_, num_capture_channels_, chunk_length_, |
| 127 kbd_window_.get(), window_size_, window_size_ / 2, &capture_callback_)); | 127 kbd_window_.get(), window_size_, window_size_ / 2, &capture_callback_)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void IntelligibilityEnhancer::ProcessRenderAudio(float* const* audio, | 130 void IntelligibilityEnhancer::ProcessRenderAudio(float* const* audio, |
| 131 int sample_rate_hz, | 131 int sample_rate_hz, |
| 132 int num_channels) { | 132 int num_channels) { |
| 133 CHECK_EQ(sample_rate_hz_, sample_rate_hz); | 133 RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz); |
| 134 CHECK_EQ(num_render_channels_, num_channels); | 134 RTC_CHECK_EQ(num_render_channels_, num_channels); |
| 135 | 135 |
| 136 if (active_) { | 136 if (active_) { |
| 137 render_mangler_->ProcessChunk(audio, temp_render_out_buffer_.channels()); | 137 render_mangler_->ProcessChunk(audio, temp_render_out_buffer_.channels()); |
| 138 } | 138 } |
| 139 | 139 |
| 140 if (active_) { | 140 if (active_) { |
| 141 for (int i = 0; i < num_render_channels_; ++i) { | 141 for (int i = 0; i < num_render_channels_; ++i) { |
| 142 memcpy(audio[i], temp_render_out_buffer_.channels()[i], | 142 memcpy(audio[i], temp_render_out_buffer_.channels()[i], |
| 143 chunk_length_ * sizeof(**audio)); | 143 chunk_length_ * sizeof(**audio)); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 void IntelligibilityEnhancer::AnalyzeCaptureAudio(float* const* audio, | 148 void IntelligibilityEnhancer::AnalyzeCaptureAudio(float* const* audio, |
| 149 int sample_rate_hz, | 149 int sample_rate_hz, |
| 150 int num_channels) { | 150 int num_channels) { |
| 151 CHECK_EQ(sample_rate_hz_, sample_rate_hz); | 151 RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz); |
| 152 CHECK_EQ(num_capture_channels_, num_channels); | 152 RTC_CHECK_EQ(num_capture_channels_, num_channels); |
| 153 | 153 |
| 154 capture_mangler_->ProcessChunk(audio, temp_capture_out_buffer_.channels()); | 154 capture_mangler_->ProcessChunk(audio, temp_capture_out_buffer_.channels()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void IntelligibilityEnhancer::DispatchAudio( | 157 void IntelligibilityEnhancer::DispatchAudio( |
| 158 IntelligibilityEnhancer::AudioSource source, | 158 IntelligibilityEnhancer::AudioSource source, |
| 159 const complex<float>* in_block, | 159 const complex<float>* in_block, |
| 160 complex<float>* out_block) { | 160 complex<float>* out_block) { |
| 161 switch (source) { | 161 switch (source) { |
| 162 case kRenderStream: | 162 case kRenderStream: |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 sols[n] = | 350 sols[n] = |
| 351 (-beta0 - sqrtf(beta0 * beta0 - 4 * alpha0 * gamma0)) / (2 * alpha0); | 351 (-beta0 - sqrtf(beta0 * beta0 - 4 * alpha0 * gamma0)) / (2 * alpha0); |
| 352 } else { | 352 } else { |
| 353 sols[n] = -gamma0 / beta0; | 353 sols[n] = -gamma0 / beta0; |
| 354 } | 354 } |
| 355 sols[n] = fmax(0, sols[n]); | 355 sols[n] = fmax(0, sols[n]); |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 | 358 |
| 359 void IntelligibilityEnhancer::FilterVariance(const float* var, float* result) { | 359 void IntelligibilityEnhancer::FilterVariance(const float* var, float* result) { |
| 360 DCHECK_GT(freqs_, 0u); | 360 RTC_DCHECK_GT(freqs_, 0u); |
| 361 for (size_t i = 0; i < bank_size_; ++i) { | 361 for (size_t i = 0; i < bank_size_; ++i) { |
| 362 result[i] = DotProduct(&filter_bank_[i][0], var, freqs_); | 362 result[i] = DotProduct(&filter_bank_[i][0], var, freqs_); |
| 363 } | 363 } |
| 364 } | 364 } |
| 365 | 365 |
| 366 float IntelligibilityEnhancer::DotProduct(const float* a, | 366 float IntelligibilityEnhancer::DotProduct(const float* a, |
| 367 const float* b, | 367 const float* b, |
| 368 size_t length) { | 368 size_t length) { |
| 369 float ret = 0.0f; | 369 float ret = 0.0f; |
| 370 | 370 |
| 371 for (size_t i = 0; i < length; ++i) { | 371 for (size_t i = 0; i < length; ++i) { |
| 372 ret = fmaf(a[i], b[i], ret); | 372 ret = fmaf(a[i], b[i], ret); |
| 373 } | 373 } |
| 374 return ret; | 374 return ret; |
| 375 } | 375 } |
| 376 | 376 |
| 377 bool IntelligibilityEnhancer::active() const { | 377 bool IntelligibilityEnhancer::active() const { |
| 378 return active_; | 378 return active_; |
| 379 } | 379 } |
| 380 | 380 |
| 381 } // namespace webrtc | 381 } // namespace webrtc |
| OLD | NEW |