mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
AGC: Removing unnneccessary copying and changing to using const
The changes have been shown to be bitexact on a large dataset. Bug: webrtc:10859 Change-Id: Iedc0e9e944ebfabb717dd7fb4d2682c695da883e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/159694 Reviewed-by: Benjamin Wright <benwright@webrtc.org> Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org> Commit-Queue: Benjamin Wright <benwright@webrtc.org> Commit-Queue: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29883}
This commit is contained in:
parent
2f74d5f793
commit
e35b32c29f
10 changed files with 43 additions and 47 deletions
|
@ -369,10 +369,11 @@ void AudioBuffer::MergeFrequencyBands() {
|
|||
splitting_filter_->Synthesis(split_data_.get(), data_.get());
|
||||
}
|
||||
|
||||
void AudioBuffer::ExportSplitChannelData(size_t channel,
|
||||
int16_t* const* split_band_data) {
|
||||
void AudioBuffer::ExportSplitChannelData(
|
||||
size_t channel,
|
||||
int16_t* const* split_band_data) const {
|
||||
for (size_t k = 0; k < num_bands(); ++k) {
|
||||
const float* band_data = split_bands(channel)[k];
|
||||
const float* band_data = split_bands_const(channel)[k];
|
||||
|
||||
RTC_DCHECK(split_band_data[k]);
|
||||
RTC_DCHECK(band_data);
|
||||
|
|
|
@ -124,7 +124,8 @@ class AudioBuffer {
|
|||
void MergeFrequencyBands();
|
||||
|
||||
// Copies the split bands data into the integer two-dimensional array.
|
||||
void ExportSplitChannelData(size_t channel, int16_t* const* split_band_data);
|
||||
void ExportSplitChannelData(size_t channel,
|
||||
int16_t* const* split_band_data) const;
|
||||
|
||||
// Copies the data in the integer two-dimensional array into the split_bands
|
||||
// data.
|
||||
|
|
|
@ -1015,7 +1015,7 @@ void AudioProcessingImpl::QueueBandedRenderAudio(AudioBuffer* audio) {
|
|||
}
|
||||
|
||||
if (!submodules_.agc_manager) {
|
||||
GainControlImpl::PackRenderAudioBuffer(audio, &agc_render_queue_buffer_);
|
||||
GainControlImpl::PackRenderAudioBuffer(*audio, &agc_render_queue_buffer_);
|
||||
// Insert the samples into the queue.
|
||||
if (!agc_render_signal_queue_->Insert(&agc_render_queue_buffer_)) {
|
||||
// The data queue is full and needs to be emptied.
|
||||
|
@ -1298,7 +1298,7 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() {
|
|||
submodules_.high_pass_filter->Process(capture_buffer);
|
||||
}
|
||||
|
||||
RETURN_ON_ERR(submodules_.gain_control->AnalyzeCaptureAudio(capture_buffer));
|
||||
RETURN_ON_ERR(submodules_.gain_control->AnalyzeCaptureAudio(*capture_buffer));
|
||||
RTC_DCHECK(
|
||||
!(submodules_.legacy_noise_suppressor && submodules_.noise_suppressor));
|
||||
if (submodules_.noise_suppressor) {
|
||||
|
|
|
@ -2102,7 +2102,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
std::make_tuple(32000, 16000, 32000, 16000, 25, 20),
|
||||
std::make_tuple(32000, 16000, 16000, 16000, 25, 0),
|
||||
|
||||
std::make_tuple(16000, 48000, 48000, 48000, 24, 0),
|
||||
std::make_tuple(16000, 48000, 48000, 48000, 23, 0),
|
||||
std::make_tuple(16000, 48000, 32000, 48000, 24, 30),
|
||||
std::make_tuple(16000, 48000, 16000, 48000, 24, 20),
|
||||
std::make_tuple(16000, 44100, 48000, 44100, 15, 20),
|
||||
|
@ -2145,30 +2145,30 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
std::make_tuple(44100, 16000, 32000, 16000, 19, 20),
|
||||
std::make_tuple(44100, 16000, 16000, 16000, 19, 0),
|
||||
|
||||
std::make_tuple(32000, 48000, 48000, 48000, 28, 0),
|
||||
std::make_tuple(32000, 48000, 48000, 48000, 27, 0),
|
||||
std::make_tuple(32000, 48000, 32000, 48000, 65, 30),
|
||||
std::make_tuple(32000, 48000, 16000, 48000, 30, 20),
|
||||
std::make_tuple(32000, 44100, 48000, 44100, 20, 20),
|
||||
std::make_tuple(32000, 44100, 32000, 44100, 20, 15),
|
||||
std::make_tuple(32000, 44100, 16000, 44100, 20, 15),
|
||||
std::make_tuple(32000, 32000, 48000, 32000, 29, 35),
|
||||
std::make_tuple(32000, 32000, 48000, 32000, 27, 35),
|
||||
std::make_tuple(32000, 32000, 32000, 32000, 0, 0),
|
||||
std::make_tuple(32000, 32000, 16000, 32000, 32, 20),
|
||||
std::make_tuple(32000, 32000, 16000, 32000, 30, 20),
|
||||
std::make_tuple(32000, 16000, 48000, 16000, 20, 20),
|
||||
std::make_tuple(32000, 16000, 32000, 16000, 20, 20),
|
||||
std::make_tuple(32000, 16000, 16000, 16000, 20, 0),
|
||||
|
||||
std::make_tuple(16000, 48000, 48000, 48000, 24, 0),
|
||||
std::make_tuple(16000, 48000, 32000, 48000, 25, 30),
|
||||
std::make_tuple(16000, 48000, 48000, 48000, 23, 0),
|
||||
std::make_tuple(16000, 48000, 32000, 48000, 24, 30),
|
||||
std::make_tuple(16000, 48000, 16000, 48000, 25, 20),
|
||||
std::make_tuple(16000, 44100, 48000, 44100, 15, 20),
|
||||
std::make_tuple(16000, 44100, 32000, 44100, 15, 15),
|
||||
std::make_tuple(16000, 44100, 16000, 44100, 15, 15),
|
||||
std::make_tuple(16000, 32000, 48000, 32000, 24, 35),
|
||||
std::make_tuple(16000, 32000, 32000, 32000, 25, 0),
|
||||
std::make_tuple(16000, 32000, 32000, 32000, 24, 0),
|
||||
std::make_tuple(16000, 32000, 16000, 32000, 25, 20),
|
||||
std::make_tuple(16000, 16000, 48000, 16000, 30, 20),
|
||||
std::make_tuple(16000, 16000, 32000, 16000, 30, 20),
|
||||
std::make_tuple(16000, 16000, 48000, 16000, 28, 20),
|
||||
std::make_tuple(16000, 16000, 32000, 16000, 28, 20),
|
||||
std::make_tuple(16000, 16000, 16000, 16000, 0, 0)));
|
||||
#endif
|
||||
|
||||
|
|
|
@ -117,23 +117,22 @@ void GainControlImpl::ProcessRenderAudio(
|
|||
}
|
||||
|
||||
void GainControlImpl::PackRenderAudioBuffer(
|
||||
AudioBuffer* audio,
|
||||
const AudioBuffer& audio,
|
||||
std::vector<int16_t>* packed_buffer) {
|
||||
RTC_DCHECK_GE(AudioBuffer::kMaxSplitFrameLength,
|
||||
audio->num_frames_per_band());
|
||||
RTC_DCHECK_GE(AudioBuffer::kMaxSplitFrameLength, audio.num_frames_per_band());
|
||||
std::array<int16_t, AudioBuffer::kMaxSplitFrameLength> mixed_low_pass_data;
|
||||
rtc::ArrayView<const int16_t> mixed_low_pass(mixed_low_pass_data.data(),
|
||||
audio->num_frames_per_band());
|
||||
if (audio->num_channels() == 1) {
|
||||
FloatS16ToS16(audio->split_bands_const(0)[kBand0To8kHz],
|
||||
audio->num_frames_per_band(), mixed_low_pass_data.data());
|
||||
audio.num_frames_per_band());
|
||||
if (audio.num_channels() == 1) {
|
||||
FloatS16ToS16(audio.split_bands_const(0)[kBand0To8kHz],
|
||||
audio.num_frames_per_band(), mixed_low_pass_data.data());
|
||||
} else {
|
||||
const int num_channels = static_cast<int>(audio->num_channels());
|
||||
for (size_t i = 0; i < audio->num_frames_per_band(); ++i) {
|
||||
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 =
|
||||
FloatS16ToS16(audio->split_channels_const(kBand0To8kHz)[0][i]);
|
||||
FloatS16ToS16(audio.split_channels_const(kBand0To8kHz)[0][i]);
|
||||
for (int j = 1; j < num_channels; ++j) {
|
||||
value += FloatS16ToS16(audio->split_channels_const(kBand0To8kHz)[j][i]);
|
||||
value += FloatS16ToS16(audio.split_channels_const(kBand0To8kHz)[j][i]);
|
||||
}
|
||||
mixed_low_pass_data[i] = value / num_channels;
|
||||
}
|
||||
|
@ -141,18 +140,17 @@ void GainControlImpl::PackRenderAudioBuffer(
|
|||
|
||||
packed_buffer->clear();
|
||||
packed_buffer->insert(packed_buffer->end(), mixed_low_pass.data(),
|
||||
(mixed_low_pass.data() + audio->num_frames_per_band()));
|
||||
(mixed_low_pass.data() + audio.num_frames_per_band()));
|
||||
}
|
||||
|
||||
int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
|
||||
int GainControlImpl::AnalyzeCaptureAudio(const AudioBuffer& audio) {
|
||||
if (!enabled_) {
|
||||
return AudioProcessing::kNoError;
|
||||
}
|
||||
|
||||
RTC_DCHECK(num_proc_channels_);
|
||||
RTC_DCHECK_GE(AudioBuffer::kMaxSplitFrameLength,
|
||||
audio->num_frames_per_band());
|
||||
RTC_DCHECK_EQ(audio->num_channels(), *num_proc_channels_);
|
||||
RTC_DCHECK_GE(AudioBuffer::kMaxSplitFrameLength, audio.num_frames_per_band());
|
||||
RTC_DCHECK_EQ(audio.num_channels(), *num_proc_channels_);
|
||||
RTC_DCHECK_LE(*num_proc_channels_, gain_controllers_.size());
|
||||
|
||||
int16_t split_band_data[AudioBuffer::kMaxNumBands]
|
||||
|
@ -165,13 +163,11 @@ int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
|
|||
for (auto& gain_controller : gain_controllers_) {
|
||||
gain_controller->set_capture_level(analog_capture_level_);
|
||||
|
||||
audio->ExportSplitChannelData(capture_channel, split_bands);
|
||||
audio.ExportSplitChannelData(capture_channel, split_bands);
|
||||
|
||||
int err =
|
||||
WebRtcAgc_AddMic(gain_controller->state(), split_bands,
|
||||
audio->num_bands(), audio->num_frames_per_band());
|
||||
|
||||
audio->ImportSplitChannelData(capture_channel, split_bands);
|
||||
audio.num_bands(), audio.num_frames_per_band());
|
||||
|
||||
if (err != AudioProcessing::kNoError) {
|
||||
return AudioProcessing::kUnspecifiedError;
|
||||
|
@ -183,15 +179,13 @@ int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
|
|||
for (auto& gain_controller : gain_controllers_) {
|
||||
int32_t capture_level_out = 0;
|
||||
|
||||
audio->ExportSplitChannelData(capture_channel, split_bands);
|
||||
audio.ExportSplitChannelData(capture_channel, split_bands);
|
||||
|
||||
int err =
|
||||
WebRtcAgc_VirtualMic(gain_controller->state(), split_bands,
|
||||
audio->num_bands(), audio->num_frames_per_band(),
|
||||
audio.num_bands(), audio.num_frames_per_band(),
|
||||
analog_capture_level_, &capture_level_out);
|
||||
|
||||
audio->ImportSplitChannelData(capture_channel, split_bands);
|
||||
|
||||
gain_controller->set_capture_level(capture_level_out);
|
||||
|
||||
if (err != AudioProcessing::kNoError) {
|
||||
|
|
|
@ -36,12 +36,12 @@ class GainControlImpl : public GainControl {
|
|||
~GainControlImpl() override;
|
||||
|
||||
void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio);
|
||||
int AnalyzeCaptureAudio(AudioBuffer* audio);
|
||||
int AnalyzeCaptureAudio(const AudioBuffer& audio);
|
||||
int ProcessCaptureAudio(AudioBuffer* audio, bool stream_has_echo);
|
||||
|
||||
void Initialize(size_t num_proc_channels, int sample_rate_hz);
|
||||
|
||||
static void PackRenderAudioBuffer(AudioBuffer* audio,
|
||||
static void PackRenderAudioBuffer(const AudioBuffer& audio,
|
||||
std::vector<int16_t>* packed_buffer);
|
||||
|
||||
// GainControl implementation.
|
||||
|
|
|
@ -31,9 +31,9 @@ void ProcessOneFrame(int sample_rate_hz,
|
|||
}
|
||||
|
||||
std::vector<int16_t> render_audio;
|
||||
GainControlImpl::PackRenderAudioBuffer(render_audio_buffer, &render_audio);
|
||||
GainControlImpl::PackRenderAudioBuffer(*render_audio_buffer, &render_audio);
|
||||
gain_controller->ProcessRenderAudio(render_audio);
|
||||
gain_controller->AnalyzeCaptureAudio(capture_audio_buffer);
|
||||
gain_controller->AnalyzeCaptureAudio(*capture_audio_buffer);
|
||||
gain_controller->ProcessCaptureAudio(capture_audio_buffer, false);
|
||||
|
||||
if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
a3bf32dd233cbc5009bd4efce12a5e019771cafb
|
||||
f85386d49e89027aa14f2aad36537a8a4e887a61
|
|
@ -1 +1 @@
|
|||
d2c18cded77614146135b1fd1296c4211d22d754
|
||||
734cc6174a5dac2fd87de267fe8d12519fe18321
|
|
@ -97,12 +97,12 @@ void FuzzGainController(test::FuzzDataHelper* fuzz_data, GainControlImpl* gci) {
|
|||
FillAudioBuffer(fuzz_data, &audio);
|
||||
|
||||
const bool stream_has_echo = fuzz_data->ReadOrDefaultValue(true);
|
||||
gci->AnalyzeCaptureAudio(&audio);
|
||||
gci->AnalyzeCaptureAudio(audio);
|
||||
gci->ProcessCaptureAudio(&audio, stream_has_echo);
|
||||
|
||||
FillAudioBuffer(fuzz_data, &audio);
|
||||
|
||||
gci->PackRenderAudioBuffer(&audio, &packed_render_audio);
|
||||
gci->PackRenderAudioBuffer(audio, &packed_render_audio);
|
||||
gci->ProcessRenderAudio(packed_render_audio);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue