| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "media/base/multi_channel_resampler.h" | 5 #include "media/base/multi_channel_resampler.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" | 
| 11 #include "base/logging.h" | 11 #include "base/logging.h" | 
|  | 12 #include "base/memory/ptr_util.h" | 
| 12 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" | 
| 13 | 14 | 
| 14 namespace media { | 15 namespace media { | 
| 15 | 16 | 
| 16 MultiChannelResampler::MultiChannelResampler(int channels, | 17 MultiChannelResampler::MultiChannelResampler(int channels, | 
| 17                                              double io_sample_rate_ratio, | 18                                              double io_sample_rate_ratio, | 
| 18                                              size_t request_size, | 19                                              size_t request_size, | 
| 19                                              const ReadCB& read_cb) | 20                                              const ReadCB& read_cb) | 
| 20     : read_cb_(read_cb), | 21     : read_cb_(read_cb), | 
| 21       wrapped_resampler_audio_bus_(AudioBus::CreateWrapper(channels)), | 22       wrapped_resampler_audio_bus_(AudioBus::CreateWrapper(channels)), | 
| 22       output_frames_ready_(0) { | 23       output_frames_ready_(0) { | 
| 23   // Allocate each channel's resampler. | 24   // Allocate each channel's resampler. | 
| 24   resamplers_.reserve(channels); | 25   resamplers_.reserve(channels); | 
| 25   for (int i = 0; i < channels; ++i) { | 26   for (int i = 0; i < channels; ++i) { | 
| 26     resamplers_.push_back(new SincResampler( | 27     resamplers_.push_back(base::MakeUnique<SincResampler>( | 
| 27         io_sample_rate_ratio, request_size, base::Bind( | 28         io_sample_rate_ratio, request_size, | 
| 28             &MultiChannelResampler::ProvideInput, base::Unretained(this), i))); | 29         base::Bind(&MultiChannelResampler::ProvideInput, base::Unretained(this), | 
|  | 30                    i))); | 
| 29   } | 31   } | 
| 30 | 32 | 
| 31   // Setup the wrapped AudioBus for channel data. | 33   // Setup the wrapped AudioBus for channel data. | 
| 32   wrapped_resampler_audio_bus_->set_frames(request_size); | 34   wrapped_resampler_audio_bus_->set_frames(request_size); | 
| 33 | 35 | 
| 34   // Allocate storage for all channels except the first, which will use the | 36   // Allocate storage for all channels except the first, which will use the | 
| 35   // |destination| provided to ProvideInput() directly. | 37   // |destination| provided to ProvideInput() directly. | 
| 36   if (channels > 1) { | 38   if (channels > 1) { | 
| 37     resampler_audio_bus_ = AudioBus::Create(channels - 1, request_size); | 39     resampler_audio_bus_ = AudioBus::Create(channels - 1, request_size); | 
| 38     for (int i = 0; i < resampler_audio_bus_->channels(); ++i) { | 40     for (int i = 0; i < resampler_audio_bus_->channels(); ++i) { | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 121   return resamplers_[0]->BufferedFrames(); | 123   return resamplers_[0]->BufferedFrames(); | 
| 122 } | 124 } | 
| 123 | 125 | 
| 124 void MultiChannelResampler::PrimeWithSilence() { | 126 void MultiChannelResampler::PrimeWithSilence() { | 
| 125   DCHECK(!resamplers_.empty()); | 127   DCHECK(!resamplers_.empty()); | 
| 126   for (size_t i = 0; i < resamplers_.size(); ++i) | 128   for (size_t i = 0; i < resamplers_.size(); ++i) | 
| 127     resamplers_[i]->PrimeWithSilence(); | 129     resamplers_[i]->PrimeWithSilence(); | 
| 128 } | 130 } | 
| 129 | 131 | 
| 130 }  // namespace media | 132 }  // namespace media | 
| OLD | NEW | 
|---|