Index: media/base/multi_channel_resampler.cc |
diff --git a/media/base/multi_channel_resampler.cc b/media/base/multi_channel_resampler.cc |
index 9aa00d88efb20d2cebf6dad4b717432f31938adf..a9aa8d68909fc2bcb238aeef715282d56cf0b50f 100644 |
--- a/media/base/multi_channel_resampler.cc |
+++ b/media/base/multi_channel_resampler.cc |
@@ -13,6 +13,7 @@ namespace media { |
MultiChannelResampler::MultiChannelResampler(int channels, |
double io_sample_rate_ratio, |
+ size_t request_size, |
const ReadCB& read_cb) |
: last_frame_count_(0), |
read_cb_(read_cb), |
@@ -20,23 +21,30 @@ MultiChannelResampler::MultiChannelResampler(int channels, |
// Allocate each channel's resampler. |
resamplers_.reserve(channels); |
for (int i = 0; i < channels; ++i) { |
- resamplers_.push_back(new SincResampler(io_sample_rate_ratio, base::Bind( |
- &MultiChannelResampler::ProvideInput, base::Unretained(this), i))); |
+ resamplers_.push_back(new SincResampler( |
+ io_sample_rate_ratio, request_size, base::Bind( |
+ &MultiChannelResampler::ProvideInput, base::Unretained(this), i))); |
} |
} |
MultiChannelResampler::~MultiChannelResampler() {} |
-void MultiChannelResampler::Resample(AudioBus* audio_bus, int frames) { |
+void MultiChannelResampler::Resample(int frames, AudioBus* audio_bus) { |
DCHECK_EQ(static_cast<size_t>(audio_bus->channels()), resamplers_.size()); |
+ // Optimize the single channel case to avoid the chunking process below. |
+ if (audio_bus->channels() == 1) { |
+ resamplers_[0]->Resample(frames, audio_bus->channel(0)); |
+ return; |
+ } |
+ |
// We need to ensure that SincResampler only calls ProvideInput once for each |
// channel. To ensure this, we chunk the number of requested frames into |
// SincResampler::ChunkSize() sized chunks. SincResampler guarantees it will |
// only call ProvideInput() once when we resample this way. |
output_frames_ready_ = 0; |
- int chunk_size = resamplers_[0]->ChunkSize(); |
while (output_frames_ready_ < frames) { |
+ int chunk_size = resamplers_[0]->ChunkSize(); |
int frames_this_time = std::min(frames - output_frames_ready_, chunk_size); |
// Resample each channel. |
@@ -50,15 +58,16 @@ void MultiChannelResampler::Resample(AudioBus* audio_bus, int frames) { |
// since they all buffer in the same way and are processing the same |
// number of frames. |
resamplers_[i]->Resample( |
- audio_bus->channel(i) + output_frames_ready_, frames_this_time); |
+ frames_this_time, audio_bus->channel(i) + output_frames_ready_); |
} |
output_frames_ready_ += frames_this_time; |
} |
} |
-void MultiChannelResampler::ProvideInput(int channel, float* destination, |
- int frames) { |
+void MultiChannelResampler::ProvideInput(int channel, |
+ int frames, |
+ float* destination) { |
// Get the data from the multi-channel provider when the first channel asks |
// for it. For subsequent channels, we can just dish out the channel data |
// from that (stored in |resampler_audio_bus_|). |