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 |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 23 * DAMAGE. |
23 */ | 24 */ |
24 | 25 |
25 #include "platform/audio/AudioResampler.h" | 26 #include "platform/audio/AudioResampler.h" |
26 #include "wtf/MathExtras.h" | 27 #include "wtf/MathExtras.h" |
27 #include "wtf/PtrUtil.h" | 28 #include "wtf/PtrUtil.h" |
28 #include <algorithm> | 29 #include <algorithm> |
29 | 30 |
30 namespace blink { | 31 namespace blink { |
31 | 32 |
32 const double AudioResampler::MaxRate = 8.0; | 33 const double AudioResampler::MaxRate = 8.0; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 71 |
71 // Make sure our configuration matches the bus we're rendering to. | 72 // Make sure our configuration matches the bus we're rendering to. |
72 bool channelsMatch = (destinationBus && | 73 bool channelsMatch = (destinationBus && |
73 destinationBus->numberOfChannels() == numberOfChannels); | 74 destinationBus->numberOfChannels() == numberOfChannels); |
74 ASSERT(channelsMatch); | 75 ASSERT(channelsMatch); |
75 if (!channelsMatch) | 76 if (!channelsMatch) |
76 return; | 77 return; |
77 | 78 |
78 // Setup the source bus. | 79 // Setup the source bus. |
79 for (unsigned i = 0; i < numberOfChannels; ++i) { | 80 for (unsigned i = 0; i < numberOfChannels; ++i) { |
80 // Figure out how many frames we need to get from the provider, and a pointe
r to the buffer. | 81 // Figure out how many frames we need to get from the provider, and a |
| 82 // pointer to the buffer. |
81 size_t framesNeeded; | 83 size_t framesNeeded; |
82 float* fillPointer = | 84 float* fillPointer = |
83 m_kernels[i]->getSourcePointer(framesToProcess, &framesNeeded); | 85 m_kernels[i]->getSourcePointer(framesToProcess, &framesNeeded); |
84 ASSERT(fillPointer); | 86 ASSERT(fillPointer); |
85 if (!fillPointer) | 87 if (!fillPointer) |
86 return; | 88 return; |
87 | 89 |
88 m_sourceBus->setChannelMemory(i, fillPointer, framesNeeded); | 90 m_sourceBus->setChannelMemory(i, fillPointer, framesNeeded); |
89 } | 91 } |
90 | 92 |
91 // Ask the provider to supply the desired number of source frames. | 93 // Ask the provider to supply the desired number of source frames. |
92 provider->provideInput(m_sourceBus.get(), m_sourceBus->length()); | 94 provider->provideInput(m_sourceBus.get(), m_sourceBus->length()); |
93 | 95 |
94 // Now that we have the source data, resample each channel into the destinatio
n bus. | 96 // Now that we have the source data, resample each channel into the |
95 // FIXME: optimize for the common stereo case where it's faster to process bot
h left/right channels in the same inner loop. | 97 // destination bus. |
| 98 // FIXME: optimize for the common stereo case where it's faster to process |
| 99 // both left/right channels in the same inner loop. |
96 for (unsigned i = 0; i < numberOfChannels; ++i) { | 100 for (unsigned i = 0; i < numberOfChannels; ++i) { |
97 float* destination = destinationBus->channel(i)->mutableData(); | 101 float* destination = destinationBus->channel(i)->mutableData(); |
98 m_kernels[i]->process(destination, framesToProcess); | 102 m_kernels[i]->process(destination, framesToProcess); |
99 } | 103 } |
100 } | 104 } |
101 | 105 |
102 void AudioResampler::setRate(double rate) { | 106 void AudioResampler::setRate(double rate) { |
103 if (std::isnan(rate) || std::isinf(rate) || rate <= 0.0) | 107 if (std::isnan(rate) || std::isinf(rate) || rate <= 0.0) |
104 return; | 108 return; |
105 | 109 |
106 m_rate = std::min(AudioResampler::MaxRate, rate); | 110 m_rate = std::min(AudioResampler::MaxRate, rate); |
107 } | 111 } |
108 | 112 |
109 void AudioResampler::reset() { | 113 void AudioResampler::reset() { |
110 unsigned numberOfChannels = m_kernels.size(); | 114 unsigned numberOfChannels = m_kernels.size(); |
111 for (unsigned i = 0; i < numberOfChannels; ++i) | 115 for (unsigned i = 0; i < numberOfChannels; ++i) |
112 m_kernels[i]->reset(); | 116 m_kernels[i]->reset(); |
113 } | 117 } |
114 | 118 |
115 } // namespace blink | 119 } // namespace blink |
OLD | NEW |