| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 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 | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND |
| 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE | 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE |
| 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 23 * DAMAGE. | 23 * DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "modules/webaudio/WaveShaperDSPKernel.h" | 26 #include "modules/webaudio/WaveShaperDSPKernel.h" |
| 27 |
| 28 #include "platform/audio/AudioUtilities.h" |
| 27 #include "wtf/PtrUtil.h" | 29 #include "wtf/PtrUtil.h" |
| 28 #include "wtf/Threading.h" | 30 #include "wtf/Threading.h" |
| 29 #include <algorithm> | 31 #include <algorithm> |
| 30 | 32 |
| 31 const unsigned RenderingQuantum = 128; | |
| 32 | |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 WaveShaperDSPKernel::WaveShaperDSPKernel(WaveShaperProcessor* processor) | 35 WaveShaperDSPKernel::WaveShaperDSPKernel(WaveShaperProcessor* processor) |
| 36 : AudioDSPKernel(processor) { | 36 : AudioDSPKernel(processor) { |
| 37 if (processor->oversample() != WaveShaperProcessor::OverSampleNone) | 37 if (processor->oversample() != WaveShaperProcessor::OverSampleNone) |
| 38 lazyInitializeOversampling(); | 38 lazyInitializeOversampling(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void WaveShaperDSPKernel::lazyInitializeOversampling() { | 41 void WaveShaperDSPKernel::lazyInitializeOversampling() { |
| 42 if (!m_tempBuffer) { | 42 if (!m_tempBuffer) { |
| 43 m_tempBuffer = wrapUnique(new AudioFloatArray(RenderingQuantum * 2)); | 43 m_tempBuffer = wrapUnique( |
| 44 m_tempBuffer2 = wrapUnique(new AudioFloatArray(RenderingQuantum * 4)); | 44 new AudioFloatArray(AudioUtilities::kRenderQuantumFrames * 2)); |
| 45 m_upSampler = wrapUnique(new UpSampler(RenderingQuantum)); | 45 m_tempBuffer2 = wrapUnique( |
| 46 m_downSampler = wrapUnique(new DownSampler(RenderingQuantum * 2)); | 46 new AudioFloatArray(AudioUtilities::kRenderQuantumFrames * 4)); |
| 47 m_upSampler2 = wrapUnique(new UpSampler(RenderingQuantum * 2)); | 47 m_upSampler = |
| 48 m_downSampler2 = wrapUnique(new DownSampler(RenderingQuantum * 4)); | 48 wrapUnique(new UpSampler(AudioUtilities::kRenderQuantumFrames)); |
| 49 m_downSampler = |
| 50 wrapUnique(new DownSampler(AudioUtilities::kRenderQuantumFrames * 2)); |
| 51 m_upSampler2 = |
| 52 wrapUnique(new UpSampler(AudioUtilities::kRenderQuantumFrames * 2)); |
| 53 m_downSampler2 = |
| 54 wrapUnique(new DownSampler(AudioUtilities::kRenderQuantumFrames * 4)); |
| 49 } | 55 } |
| 50 } | 56 } |
| 51 | 57 |
| 52 void WaveShaperDSPKernel::process(const float* source, | 58 void WaveShaperDSPKernel::process(const float* source, |
| 53 float* destination, | 59 float* destination, |
| 54 size_t framesToProcess) { | 60 size_t framesToProcess) { |
| 55 switch (getWaveShaperProcessor()->oversample()) { | 61 switch (getWaveShaperProcessor()->oversample()) { |
| 56 case WaveShaperProcessor::OverSampleNone: | 62 case WaveShaperProcessor::OverSampleNone: |
| 57 processCurve(source, destination, framesToProcess); | 63 processCurve(source, destination, framesToProcess); |
| 58 break; | 64 break; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 output = | 128 output = |
| 123 (1.0 - interpolationFactor) * value1 + interpolationFactor * value2; | 129 (1.0 - interpolationFactor) * value1 + interpolationFactor * value2; |
| 124 } | 130 } |
| 125 destination[i] = output; | 131 destination[i] = output; |
| 126 } | 132 } |
| 127 } | 133 } |
| 128 | 134 |
| 129 void WaveShaperDSPKernel::processCurve2x(const float* source, | 135 void WaveShaperDSPKernel::processCurve2x(const float* source, |
| 130 float* destination, | 136 float* destination, |
| 131 size_t framesToProcess) { | 137 size_t framesToProcess) { |
| 132 bool isSafe = framesToProcess == RenderingQuantum; | 138 bool isSafe = framesToProcess == AudioUtilities::kRenderQuantumFrames; |
| 133 DCHECK(isSafe); | 139 DCHECK(isSafe); |
| 134 if (!isSafe) | 140 if (!isSafe) |
| 135 return; | 141 return; |
| 136 | 142 |
| 137 float* tempP = m_tempBuffer->data(); | 143 float* tempP = m_tempBuffer->data(); |
| 138 | 144 |
| 139 m_upSampler->process(source, tempP, framesToProcess); | 145 m_upSampler->process(source, tempP, framesToProcess); |
| 140 | 146 |
| 141 // Process at 2x up-sampled rate. | 147 // Process at 2x up-sampled rate. |
| 142 processCurve(tempP, tempP, framesToProcess * 2); | 148 processCurve(tempP, tempP, framesToProcess * 2); |
| 143 | 149 |
| 144 m_downSampler->process(tempP, destination, framesToProcess * 2); | 150 m_downSampler->process(tempP, destination, framesToProcess * 2); |
| 145 } | 151 } |
| 146 | 152 |
| 147 void WaveShaperDSPKernel::processCurve4x(const float* source, | 153 void WaveShaperDSPKernel::processCurve4x(const float* source, |
| 148 float* destination, | 154 float* destination, |
| 149 size_t framesToProcess) { | 155 size_t framesToProcess) { |
| 150 bool isSafe = framesToProcess == RenderingQuantum; | 156 bool isSafe = framesToProcess == AudioUtilities::kRenderQuantumFrames; |
| 151 DCHECK(isSafe); | 157 DCHECK(isSafe); |
| 152 if (!isSafe) | 158 if (!isSafe) |
| 153 return; | 159 return; |
| 154 | 160 |
| 155 float* tempP = m_tempBuffer->data(); | 161 float* tempP = m_tempBuffer->data(); |
| 156 float* tempP2 = m_tempBuffer2->data(); | 162 float* tempP2 = m_tempBuffer2->data(); |
| 157 | 163 |
| 158 m_upSampler->process(source, tempP, framesToProcess); | 164 m_upSampler->process(source, tempP, framesToProcess); |
| 159 m_upSampler2->process(tempP, tempP2, framesToProcess * 2); | 165 m_upSampler2->process(tempP, tempP2, framesToProcess * 2); |
| 160 | 166 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 break; | 204 break; |
| 199 } | 205 } |
| 200 default: | 206 default: |
| 201 ASSERT_NOT_REACHED(); | 207 ASSERT_NOT_REACHED(); |
| 202 } | 208 } |
| 203 | 209 |
| 204 return static_cast<double>(latencyFrames) / sampleRate(); | 210 return static_cast<double>(latencyFrames) / sampleRate(); |
| 205 } | 211 } |
| 206 | 212 |
| 207 } // namespace blink | 213 } // namespace blink |
| OLD | NEW |