Removing all external access to the integer sample data in AudioBuffer
This CL removes all external access to the integer sample data in the AudioBuffer class. It also removes the API in AudioBuffer that provides this. The purpose of this is to pave the way for removing the sample duplicating and implicit conversions between integer and floating point sample formats which is done inside the AudioBuffer. Bug: webrtc:10882 Change-Id: I1438b691bcef98278aef8e3c63624c367c2d12e9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/149162 Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org> Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org> Commit-Queue: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28912}
This commit is contained in:
@ -56,6 +56,7 @@ AudioProcessing::Error MapError(int err) {
|
||||
return AudioProcessing::kUnspecifiedError;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
struct EchoControlMobileImpl::StreamProperties {
|
||||
@ -131,7 +132,8 @@ void EchoControlMobileImpl::PackRenderAudioBuffer(
|
||||
size_t num_output_channels,
|
||||
size_t num_channels,
|
||||
std::vector<int16_t>* packed_buffer) {
|
||||
RTC_DCHECK_GE(160, audio->num_frames_per_band());
|
||||
RTC_DCHECK_GE(AudioBuffer::kMaxSplitFrameLength,
|
||||
audio->num_frames_per_band());
|
||||
RTC_DCHECK_EQ(num_channels, audio->num_channels());
|
||||
|
||||
// The ordering convention must be followed to pass to the correct AECM.
|
||||
@ -139,12 +141,14 @@ void EchoControlMobileImpl::PackRenderAudioBuffer(
|
||||
int render_channel = 0;
|
||||
for (size_t i = 0; i < num_output_channels; i++) {
|
||||
for (size_t j = 0; j < audio->num_channels(); j++) {
|
||||
std::array<int16_t, AudioBuffer::kMaxSplitFrameLength> data_to_buffer;
|
||||
FloatS16ToS16(audio->split_bands_const_f(render_channel)[kBand0To8kHz],
|
||||
audio->num_frames_per_band(), data_to_buffer.data());
|
||||
|
||||
// Buffer the samples in the render queue.
|
||||
packed_buffer->insert(
|
||||
packed_buffer->end(),
|
||||
audio->split_bands_const(render_channel)[kBand0To8kHz],
|
||||
(audio->split_bands_const(render_channel)[kBand0To8kHz] +
|
||||
audio->num_frames_per_band()));
|
||||
packed_buffer->end(), data_to_buffer.data(),
|
||||
data_to_buffer.data() + audio->num_frames_per_band());
|
||||
render_channel = (render_channel + 1) % audio->num_channels();
|
||||
}
|
||||
}
|
||||
@ -174,7 +178,21 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio,
|
||||
RTC_DCHECK_LT(capture, low_pass_reference_.size());
|
||||
const int16_t* noisy =
|
||||
reference_copied_ ? low_pass_reference_[capture].data() : nullptr;
|
||||
const int16_t* clean = audio->split_bands_const(capture)[kBand0To8kHz];
|
||||
|
||||
RTC_DCHECK_GE(AudioBuffer::kMaxSplitFrameLength,
|
||||
audio->num_frames_per_band());
|
||||
|
||||
std::array<int16_t, AudioBuffer::kMaxSplitFrameLength> split_bands_data;
|
||||
int16_t* split_bands = split_bands_data.data();
|
||||
const int16_t* clean = split_bands_data.data();
|
||||
if (audio->split_bands_f(capture)[kBand0To8kHz]) {
|
||||
FloatS16ToS16(audio->split_bands_f(capture)[kBand0To8kHz],
|
||||
audio->num_frames_per_band(), split_bands_data.data());
|
||||
} else {
|
||||
clean = nullptr;
|
||||
split_bands = nullptr;
|
||||
}
|
||||
|
||||
if (noisy == NULL) {
|
||||
noisy = clean;
|
||||
clean = NULL;
|
||||
@ -182,8 +200,13 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio,
|
||||
for (size_t render = 0; render < stream_properties_->num_reverse_channels;
|
||||
++render) {
|
||||
err = WebRtcAecm_Process(cancellers_[handle_index]->state(), noisy, clean,
|
||||
audio->split_bands(capture)[kBand0To8kHz],
|
||||
audio->num_frames_per_band(), stream_delay_ms);
|
||||
split_bands, audio->num_frames_per_band(),
|
||||
stream_delay_ms);
|
||||
|
||||
if (split_bands) {
|
||||
S16ToFloatS16(split_bands, audio->num_frames_per_band(),
|
||||
audio->split_bands_f(capture)[kBand0To8kHz]);
|
||||
}
|
||||
|
||||
if (err != AudioProcessing::kNoError) {
|
||||
return MapError(err);
|
||||
@ -192,9 +215,9 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio,
|
||||
++handle_index;
|
||||
}
|
||||
for (size_t band = 1u; band < audio->num_bands(); ++band) {
|
||||
memset(audio->split_bands(capture)[band], 0,
|
||||
memset(audio->split_bands_f(capture)[band], 0,
|
||||
audio->num_frames_per_band() *
|
||||
sizeof(audio->split_bands(capture)[band][0]));
|
||||
sizeof(audio->split_bands_f(capture)[band][0]));
|
||||
}
|
||||
}
|
||||
return AudioProcessing::kNoError;
|
||||
@ -204,9 +227,9 @@ void EchoControlMobileImpl::CopyLowPassReference(AudioBuffer* audio) {
|
||||
RTC_DCHECK_LE(audio->num_channels(), low_pass_reference_.size());
|
||||
reference_copied_ = true;
|
||||
for (size_t capture = 0; capture < audio->num_channels(); ++capture) {
|
||||
memcpy(low_pass_reference_[capture].data(),
|
||||
audio->split_bands_const(capture)[kBand0To8kHz],
|
||||
audio->num_frames_per_band() * sizeof(int16_t));
|
||||
FloatS16ToS16(audio->split_bands_const_f(capture)[kBand0To8kHz],
|
||||
audio->num_frames_per_band(),
|
||||
low_pass_reference_[capture].data());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user