Chromium Code Reviews| 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..71c62fd3d9543861d6d3ddfa2de614b18189e130 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,8 +21,9 @@ 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))); |
| } |
| } |
| @@ -30,13 +32,19 @@ MultiChannelResampler::~MultiChannelResampler() {} |
| void MultiChannelResampler::Resample(AudioBus* audio_bus, int frames) { |
| DCHECK_EQ(static_cast<size_t>(audio_bus->channels()), resamplers_.size()); |
| + // Optimize the single channel case to avoid chunking. |
|
henrika (OOO until Aug 14)
2013/04/27 19:43:40
"chunking"? Is that a well known term?
DaleCurtis
2013/04/29 22:12:31
Refers to the code section below. I've updated th
|
| + if (audio_bus->channels() == 1) { |
| + resamplers_[0]->Resample(audio_bus->channel(0), frames); |
| + 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. |