Index: media/base/multi_channel_resampler.cc |
diff --git a/media/base/multi_channel_resampler.cc b/media/base/multi_channel_resampler.cc |
index 23ab0ebbe0f263dac1408cfb0b3272d00fee6d3b..1004af8834fac808ec8778fbbbd678dc8d270fed 100644 |
--- a/media/base/multi_channel_resampler.cc |
+++ b/media/base/multi_channel_resampler.cc |
@@ -7,6 +7,7 @@ |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
#include "base/logging.h" |
+#include "media/base/audio_bus.h" |
namespace media { |
@@ -14,7 +15,6 @@ MultiChannelResampler::MultiChannelResampler(int channels, |
double io_sample_rate_ratio, |
const ReadCB& read_cb) |
: last_frame_count_(0), |
- first_frame_count_(0), |
read_cb_(read_cb) { |
// Allocate each channel's resampler. |
resamplers_.reserve(channels); |
@@ -24,17 +24,10 @@ MultiChannelResampler::MultiChannelResampler(int channels, |
} |
} |
-MultiChannelResampler::~MultiChannelResampler() { |
- // Clean up |resampler_audio_data_|. Skip the first channel since we never |
- // allocated that, but just used the destination passed into ProvideInput(). |
- for (size_t i = 1; i < resampler_audio_data_.size(); ++i) |
- delete [] resampler_audio_data_[i]; |
- resampler_audio_data_.clear(); |
-} |
+MultiChannelResampler::~MultiChannelResampler() {} |
-void MultiChannelResampler::Resample(const std::vector<float*>& destination, |
- int frames) { |
- DCHECK_EQ(destination.size(), resamplers_.size()); |
+void MultiChannelResampler::Resample(AudioBus* audio_bus, int frames) { |
+ DCHECK_EQ(static_cast<size_t>(audio_bus->channels()), resamplers_.size()); |
// We need to ensure that SincResampler only calls ProvideInput once for each |
// channel. To ensure this, we chunk the number of requested frames into |
@@ -55,7 +48,8 @@ void MultiChannelResampler::Resample(const std::vector<float*>& destination, |
// the first channel, then it will call it for the remaining channels, |
// since they all buffer in the same way and are processing the same |
// number of frames. |
- resamplers_[i]->Resample(destination[i] + frames_done, frames_this_time); |
+ resamplers_[i]->Resample( |
+ audio_bus->channel(i) + frames_done, frames_this_time); |
} |
frames_done += frames_this_time; |
@@ -69,30 +63,21 @@ void MultiChannelResampler::ProvideInput(int channel, float* destination, |
// from that (stored in |resampler_audio_data_|). |
if (channel == 0) { |
// Allocate staging arrays on the first request. |
- if (resampler_audio_data_.size() == 0) { |
- first_frame_count_ = frames; |
- // Skip allocation of the first buffer, since we'll use |destination| |
- // directly for that. |
- resampler_audio_data_.reserve(resamplers_.size()); |
- resampler_audio_data_.push_back(destination); |
- for (size_t i = 1; i < resamplers_.size(); ++i) |
- resampler_audio_data_.push_back(new float[frames]); |
- } else { |
- DCHECK_LE(frames, first_frame_count_); |
- resampler_audio_data_[0] = destination; |
- } |
+ if (!resampler_audio_bus_.get()) |
+ resampler_audio_bus_ = AudioBus::Create(resamplers_.size(), frames); |
+ DCHECK_LE(frames, resampler_audio_bus_->frames()); |
last_frame_count_ = frames; |
- read_cb_.Run(resampler_audio_data_, frames); |
- } else { |
- // All channels must ask for the same amount. This should always be the |
- // case, but let's just make sure. |
- DCHECK_EQ(frames, last_frame_count_); |
- |
- // Copy the channel data from what we received from |read_cb_|. |
- memcpy(destination, resampler_audio_data_[channel], |
- sizeof(*resampler_audio_data_[channel]) * frames); |
+ read_cb_.Run(resampler_audio_bus_.get(), frames); |
} |
+ |
+ // All channels must ask for the same amount. This should always be the |
+ // case, but let's just make sure. |
+ DCHECK_EQ(frames, last_frame_count_); |
+ |
+ // Copy the channel data from what we received from |read_cb_|. |
+ memcpy(destination, resampler_audio_bus_->channel(channel), |
+ sizeof(*resampler_audio_bus_->channel(channel)) * frames); |
} |
} // namespace media |