diff options
Diffstat (limited to 'chromium/third_party/webrtc/common_audio/resampler/push_sinc_resampler.cc')
-rw-r--r-- | chromium/third_party/webrtc/common_audio/resampler/push_sinc_resampler.cc | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/chromium/third_party/webrtc/common_audio/resampler/push_sinc_resampler.cc b/chromium/third_party/webrtc/common_audio/resampler/push_sinc_resampler.cc index 1fb72dc76cf..027555902b8 100644 --- a/chromium/third_party/webrtc/common_audio/resampler/push_sinc_resampler.cc +++ b/chromium/third_party/webrtc/common_audio/resampler/push_sinc_resampler.cc @@ -9,22 +9,23 @@ */ #include "webrtc/common_audio/include/audio_util.h" -#include "webrtc/common_audio/resampler/push_sinc_resampler.h" +#include <assert.h> #include <string.h> +#include "webrtc/common_audio/resampler/push_sinc_resampler.h" + namespace webrtc { -PushSincResampler::PushSincResampler(int source_frames, - int destination_frames) +PushSincResampler::PushSincResampler(int source_frames, int destination_frames) : resampler_(new SincResampler(source_frames * 1.0 / destination_frames, - source_frames, this)), - float_buffer_(new float[destination_frames]), + source_frames, + this)), source_ptr_(NULL), + source_ptr_int_(NULL), destination_frames_(destination_frames), first_pass_(true), - source_available_(0) { -} + source_available_(0) {} PushSincResampler::~PushSincResampler() { } @@ -33,6 +34,21 @@ int PushSincResampler::Resample(const int16_t* source, int source_length, int16_t* destination, int destination_capacity) { + if (!float_buffer_.get()) + float_buffer_.reset(new float[destination_frames_]); + + source_ptr_int_ = source; + // Pass NULL as the float source to have Run() read from the int16 source. + Resample(NULL, source_length, float_buffer_.get(), destination_frames_); + RoundToInt16(float_buffer_.get(), destination_frames_, destination); + source_ptr_int_ = NULL; + return destination_frames_; +} + +int PushSincResampler::Resample(const float* source, + int source_length, + float* destination, + int destination_capacity) { assert(source_length == resampler_->request_frames()); assert(destination_capacity >= destination_frames_); // Cache the source pointer. Calling Resample() will immediately trigger @@ -54,17 +70,14 @@ int PushSincResampler::Resample(const int16_t* source, // request in order to prime the buffer with a single Run() request for // |source_frames|. if (first_pass_) - resampler_->Resample(resampler_->ChunkSize(), float_buffer_.get()); + resampler_->Resample(resampler_->ChunkSize(), destination); - resampler_->Resample(destination_frames_, float_buffer_.get()); - for (int i = 0; i < destination_frames_; ++i) - destination[i] = RoundToInt16(ClampInt16(float_buffer_[i])); + resampler_->Resample(destination_frames_, destination); source_ptr_ = NULL; return destination_frames_; } void PushSincResampler::Run(int frames, float* destination) { - assert(source_ptr_ != NULL); // Ensure we are only asked for the available samples. This would fail if // Run() was triggered more than once per Resample() call. assert(source_available_ == frames); @@ -74,11 +87,16 @@ void PushSincResampler::Run(int frames, float* destination) { // discarded, as described in Resample(). memset(destination, 0, frames * sizeof(float)); first_pass_ = false; + return; + } + + if (source_ptr_) { + memcpy(destination, source_ptr_, frames * sizeof(float)); } else { for (int i = 0; i < frames; ++i) - destination[i] = static_cast<float>(source_ptr_[i]); - source_available_ -= frames; + destination[i] = static_cast<float>(source_ptr_int_[i]); } + source_available_ -= frames; } } // namespace webrtc |