diff options
author | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-21 04:24:19 +0000 |
---|---|---|
committer | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-21 04:24:19 +0000 |
commit | 4187ea43e11dd33ec2d542edd76163d8fc7ed1c1 (patch) | |
tree | 142e57255a31a095905e78423279f1fa2f4eb42e /media/base/multi_channel_resampler.cc | |
parent | 2d115a11ba119dc8d3df465b3fdb96fb94a0e1bc (diff) | |
download | chromium_src-4187ea43e11dd33ec2d542edd76163d8fc7ed1c1.zip chromium_src-4187ea43e11dd33ec2d542edd76163d8fc7ed1c1.tar.gz chromium_src-4187ea43e11dd33ec2d542edd76163d8fc7ed1c1.tar.bz2 |
Collapse AudioRendererMixer and OnMoreDataResampler into AudioTransform.
Currently we have roughly equivalent functionality in two places, and
the CloudView project will add a third. As such there's a need for a
single super class which can handle mixing, resampling, and general
conversion from one set of AudioParameters to another.
This change introduces the AudioTransform object which collapses the
key functionality from AudioRendererMixer and OnMoreDataResampler into
a single AudioTransform class which can do everything and is oblivious
to the peculiars of RenderCallback vs AudioSourceCallback.
It also introduces output_frames_ready() methods to the AudioPullFifo
and MultiChannelResampler classes so that buffer delay can be measured
accurately without resorting to input vs output byte counting.
Due to the bulk of AudioRendererMixer's functionality moving into the
new AudioTransform, it made sense to move some decisions into the
AudioRendererMixerInput class as well.
On my Z600, benchmarking 50000 iterations:
Convert() w/ FIFO took 7030.11ms.
Convert() w/o FIFO took 5218.83ms.
BUG=none
TEST=AudioTransform* unittests.
TBR=sergeyu
Review URL: https://chromiumcodereview.appspot.com/11410012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168976 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/multi_channel_resampler.cc')
-rw-r--r-- | media/base/multi_channel_resampler.cc | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/media/base/multi_channel_resampler.cc b/media/base/multi_channel_resampler.cc index b8df97d..a5cbf3ef 100644 --- a/media/base/multi_channel_resampler.cc +++ b/media/base/multi_channel_resampler.cc @@ -15,7 +15,8 @@ MultiChannelResampler::MultiChannelResampler(int channels, double io_sample_rate_ratio, const ReadCB& read_cb) : last_frame_count_(0), - read_cb_(read_cb) { + read_cb_(read_cb), + output_frames_ready_(0) { // Allocate each channel's resampler. resamplers_.reserve(channels); for (int i = 0; i < channels; ++i) { @@ -33,10 +34,10 @@ void MultiChannelResampler::Resample(AudioBus* audio_bus, int frames) { // 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. - int frames_done = 0; + output_frames_ready_ = 0; int chunk_size = resamplers_[0]->ChunkSize(); - while (frames_done < frames) { - int frames_this_time = std::min(frames - frames_done, chunk_size); + while (output_frames_ready_ < frames) { + int frames_this_time = std::min(frames - output_frames_ready_, chunk_size); // Resample each channel. for (size_t i = 0; i < resamplers_.size(); ++i) { @@ -49,10 +50,10 @@ 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) + frames_done, frames_this_time); + audio_bus->channel(i) + output_frames_ready_, frames_this_time); } - frames_done += frames_this_time; + output_frames_ready_ += frames_this_time; } } @@ -82,7 +83,7 @@ void MultiChannelResampler::ProvideInput(int channel, float* destination, } last_frame_count_ = frames; - read_cb_.Run(wrapped_resampler_audio_bus_.get()); + read_cb_.Run(output_frames_ready_, wrapped_resampler_audio_bus_.get()); } else { // All channels must ask for the same amount. This should always be the // case, but let's just make sure. |