From c7daea8d6a13e29a797b641ffda0d87e601e8a61 Mon Sep 17 00:00:00 2001 From: kthelgason Date: Tue, 14 Mar 2017 03:10:07 -0700 Subject: [PATCH] Make AudioBuffer::InterleaveTo const The only non-const operation was a one-time initialization of a member only used in this function. I've moved it to the ctor. BUG=webrtc:5298 Review-Url: https://codereview.webrtc.org/2741733002 Cr-Commit-Position: refs/heads/master@{#17223} --- webrtc/modules/audio_processing/audio_buffer.cc | 9 +++------ webrtc/modules/audio_processing/audio_buffer.h | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/webrtc/modules/audio_processing/audio_buffer.cc b/webrtc/modules/audio_processing/audio_buffer.cc index 02b8537c07..579a5c2490 100644 --- a/webrtc/modules/audio_processing/audio_buffer.cc +++ b/webrtc/modules/audio_processing/audio_buffer.cc @@ -61,7 +61,8 @@ AudioBuffer::AudioBuffer(size_t input_num_frames, reference_copied_(false), activity_(AudioFrame::kVadUnknown), keyboard_data_(NULL), - data_(new IFChannelBuffer(proc_num_frames_, num_proc_channels_)) { + data_(new IFChannelBuffer(proc_num_frames_, num_proc_channels_)), + output_buffer_(new IFChannelBuffer(output_num_frames_, num_channels_)) { RTC_DCHECK_GT(input_num_frames_, 0); RTC_DCHECK_GT(proc_num_frames_, 0); RTC_DCHECK_GT(output_num_frames_, 0); @@ -416,7 +417,7 @@ void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) { } } -void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) { +void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) const { frame->vad_activity_ = activity_; if (!data_changed) { return; @@ -428,10 +429,6 @@ void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) { // Resample if necessary. IFChannelBuffer* data_ptr = data_.get(); if (proc_num_frames_ != output_num_frames_) { - if (!output_buffer_) { - output_buffer_.reset( - new IFChannelBuffer(output_num_frames_, num_channels_)); - } for (size_t i = 0; i < num_channels_; ++i) { output_resamplers_[i]->Resample( data_->fbuf()->channels()[i], proc_num_frames_, diff --git a/webrtc/modules/audio_processing/audio_buffer.h b/webrtc/modules/audio_processing/audio_buffer.h index d0e79db329..da75dbf1b8 100644 --- a/webrtc/modules/audio_processing/audio_buffer.h +++ b/webrtc/modules/audio_processing/audio_buffer.h @@ -110,7 +110,7 @@ class AudioBuffer { void DeinterleaveFrom(AudioFrame* audioFrame); // If |data_changed| is false, only the non-audio data members will be copied // to |frame|. - void InterleaveTo(AudioFrame* frame, bool data_changed); + void InterleaveTo(AudioFrame* frame, bool data_changed) const; // Use for float deinterleaved data. void CopyFrom(const float* const* data, const StreamConfig& stream_config);