Remove all AudioBuffer code that is not related to storing audio data
This CL moves/removes all code from the AudioBuffer that:
-Is not directly handling audio data (e.g., keytaps, VAD descisions).
-Is caching aggregated versions of the rest of the audio data.
-Is not used (or only used in testing)
Bug: webrtc:10882
Change-Id: I737deb3f692748eff30f46ad806b2c6f6292802c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/149072
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28866}
diff --git a/modules/audio_processing/voice_detection_impl.cc b/modules/audio_processing/voice_detection_impl.cc
index 7bf6c4a..0263de4 100644
--- a/modules/audio_processing/voice_detection_impl.cc
+++ b/modules/audio_processing/voice_detection_impl.cc
@@ -54,30 +54,42 @@
set_likelihood(likelihood_);
}
-void VoiceDetectionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
+bool VoiceDetectionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
rtc::CritScope cs(crit_);
- if (!enabled_) {
- return;
- }
- if (using_external_vad_) {
- using_external_vad_ = false;
- return;
- }
+ RTC_DCHECK(enabled_);
RTC_DCHECK_GE(160, audio->num_frames_per_band());
- // TODO(ajm): concatenate data in frame buffer here.
- int vad_ret =
- WebRtcVad_Process(vad_->state(), sample_rate_hz_,
- audio->mixed_low_pass_data(), frame_size_samples_);
+ std::array<int16_t, 160> mixed_low_pass_data;
+ rtc::ArrayView<const int16_t> mixed_low_pass;
+ if (audio->num_proc_channels() == 1) {
+ mixed_low_pass =
+ rtc::ArrayView<const int16_t>(audio->split_bands_const(0)[kBand0To8kHz],
+ audio->num_frames_per_band());
+ } else {
+ const int num_channels = static_cast<int>(audio->num_channels());
+ for (size_t i = 0; i < audio->num_frames_per_band(); ++i) {
+ int32_t value = audio->split_channels_const(kBand0To8kHz)[0][i];
+ for (int j = 1; j < num_channels; ++j) {
+ value += audio->split_channels_const(kBand0To8kHz)[j][i];
+ }
+ mixed_low_pass_data[i] = value / num_channels;
+ }
+ mixed_low_pass = rtc::ArrayView<const int16_t>(
+ mixed_low_pass_data.data(), audio->num_frames_per_band());
+ }
+
+ int vad_ret = WebRtcVad_Process(vad_->state(), sample_rate_hz_,
+ mixed_low_pass.data(), frame_size_samples_);
if (vad_ret == 0) {
stream_has_voice_ = false;
- audio->set_activity(AudioFrame::kVadPassive);
+ return false;
} else if (vad_ret == 1) {
stream_has_voice_ = true;
- audio->set_activity(AudioFrame::kVadActive);
} else {
RTC_NOTREACHED();
}
+
+ return stream_has_voice_;
}
int VoiceDetectionImpl::Enable(bool enable) {