| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "platform/audio/AudioResampler.h" | 25 #include "platform/audio/AudioResampler.h" |
| 26 #include <algorithm> |
| 26 #include "wtf/MathExtras.h" | 27 #include "wtf/MathExtras.h" |
| 27 #include "wtf/PtrUtil.h" | |
| 28 #include <algorithm> | |
| 29 | 28 |
| 30 namespace blink { | 29 namespace blink { |
| 31 | 30 |
| 32 const double AudioResampler::MaxRate = 8.0; | 31 const double AudioResampler::MaxRate = 8.0; |
| 33 | 32 |
| 34 AudioResampler::AudioResampler() | 33 AudioResampler::AudioResampler() |
| 35 : m_rate(1.0) | 34 : m_rate(1.0) |
| 36 { | 35 { |
| 37 m_kernels.append(wrapUnique(new AudioResamplerKernel(this))); | 36 m_kernels.append(adoptPtr(new AudioResamplerKernel(this))); |
| 38 m_sourceBus = AudioBus::create(1, 0, false); | 37 m_sourceBus = AudioBus::create(1, 0, false); |
| 39 } | 38 } |
| 40 | 39 |
| 41 AudioResampler::AudioResampler(unsigned numberOfChannels) | 40 AudioResampler::AudioResampler(unsigned numberOfChannels) |
| 42 : m_rate(1.0) | 41 : m_rate(1.0) |
| 43 { | 42 { |
| 44 for (unsigned i = 0; i < numberOfChannels; ++i) | 43 for (unsigned i = 0; i < numberOfChannels; ++i) |
| 45 m_kernels.append(wrapUnique(new AudioResamplerKernel(this))); | 44 m_kernels.append(adoptPtr(new AudioResamplerKernel(this))); |
| 46 | 45 |
| 47 m_sourceBus = AudioBus::create(numberOfChannels, 0, false); | 46 m_sourceBus = AudioBus::create(numberOfChannels, 0, false); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void AudioResampler::configureChannels(unsigned numberOfChannels) | 49 void AudioResampler::configureChannels(unsigned numberOfChannels) |
| 51 { | 50 { |
| 52 unsigned currentSize = m_kernels.size(); | 51 unsigned currentSize = m_kernels.size(); |
| 53 if (numberOfChannels == currentSize) | 52 if (numberOfChannels == currentSize) |
| 54 return; // already setup | 53 return; // already setup |
| 55 | 54 |
| 56 // First deal with adding or removing kernels. | 55 // First deal with adding or removing kernels. |
| 57 if (numberOfChannels > currentSize) { | 56 if (numberOfChannels > currentSize) { |
| 58 for (unsigned i = currentSize; i < numberOfChannels; ++i) | 57 for (unsigned i = currentSize; i < numberOfChannels; ++i) |
| 59 m_kernels.append(wrapUnique(new AudioResamplerKernel(this))); | 58 m_kernels.append(adoptPtr(new AudioResamplerKernel(this))); |
| 60 } else | 59 } else |
| 61 m_kernels.resize(numberOfChannels); | 60 m_kernels.resize(numberOfChannels); |
| 62 | 61 |
| 63 // Reconfigure our source bus to the new channel size. | 62 // Reconfigure our source bus to the new channel size. |
| 64 m_sourceBus = AudioBus::create(numberOfChannels, 0, false); | 63 m_sourceBus = AudioBus::create(numberOfChannels, 0, false); |
| 65 } | 64 } |
| 66 | 65 |
| 67 void AudioResampler::process(AudioSourceProvider* provider, AudioBus* destinatio
nBus, size_t framesToProcess) | 66 void AudioResampler::process(AudioSourceProvider* provider, AudioBus* destinatio
nBus, size_t framesToProcess) |
| 68 { | 67 { |
| 69 ASSERT(provider); | 68 ASSERT(provider); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 110 |
| 112 void AudioResampler::reset() | 111 void AudioResampler::reset() |
| 113 { | 112 { |
| 114 unsigned numberOfChannels = m_kernels.size(); | 113 unsigned numberOfChannels = m_kernels.size(); |
| 115 for (unsigned i = 0; i < numberOfChannels; ++i) | 114 for (unsigned i = 0; i < numberOfChannels; ++i) |
| 116 m_kernels[i]->reset(); | 115 m_kernels[i]->reset(); |
| 117 } | 116 } |
| 118 | 117 |
| 119 } // namespace blink | 118 } // namespace blink |
| 120 | 119 |
| OLD | NEW |