Chromium Code Reviews| Index: Source/modules/webaudio/StereoPannerNode.cpp |
| diff --git a/Source/modules/webaudio/StereoPannerNode.cpp b/Source/modules/webaudio/StereoPannerNode.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dbaac71e6c1045296a6ffeadc7f1d3f8d05cf7ed |
| --- /dev/null |
| +++ b/Source/modules/webaudio/StereoPannerNode.cpp |
| @@ -0,0 +1,134 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// |
| +// Redistribution and use in source and binary forms, with or without |
| +// modification, are permitted provided that the following conditions are |
| +// met: |
| +// |
| +// * Redistributions of source code must retain the above copyright |
| +// notice, this list of conditions and the following disclaimer. |
| +// * Redistributions in binary form must reproduce the above |
| +// copyright notice, this list of conditions and the following disclaimer |
| +// in the documentation and/or other materials provided with the |
| +// distribution. |
| +// * Neither the name of Google Inc. nor the names of its |
| +// contributors may be used to endorse or promote products derived from |
| +// this software without specific prior written permission. |
| +// |
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + |
| +#include "config.h" |
| + |
| +#if ENABLE(WEB_AUDIO) |
| + |
| +#include "modules/webaudio/StereoPannerNode.h" |
| + |
| +#include "bindings/core/v8/ExceptionMessages.h" |
| +#include "bindings/core/v8/ExceptionState.h" |
| +#include "core/dom/ExecutionContext.h" |
| +#include "modules/webaudio/AudioContext.h" |
| +#include "modules/webaudio/AudioNodeInput.h" |
| +#include "modules/webaudio/AudioNodeOutput.h" |
| +#include "platform/audio/StereoPanner.h" |
| +#include "wtf/MathExtras.h" |
| + |
| +namespace blink { |
| + |
| +StereoPannerNode::StereoPannerNode(AudioContext* context, float sampleRate) |
| + : AudioNode(context, sampleRate) |
| + , m_sampleAccuratePanValues(AudioNode::ProcessingSizeInFrames) |
| +{ |
| + m_pan = AudioParam::create(context, 0.0); |
|
Raymond Toy
2014/11/11 19:41:47
No trailing ".0" on floating point constants unles
hongchan
2014/11/12 00:06:54
Done.
|
| + |
| + addInput(); |
| + addOutput(AudioNodeOutput::create(this, 2)); |
| + |
| + // This node-specific default mixing rules declare that StereoPannerNode |
| + // can handles mono to stereo and stereo to stereo conversion. |
|
Raymond Toy
2014/11/11 19:41:47
Typo: "handles" -> "handle"
hongchan
2014/11/12 00:06:53
Done.
hongchan
2014/11/12 00:06:54
Done.
|
| + m_channelCount = 2; |
| + m_channelCountMode = ClampedMax; |
| + m_channelInterpretation = AudioBus::Speakers; |
| + |
| + setNodeType(NodeTypeStereoPanner); |
| + |
| + initialize(); |
| +} |
| + |
| +StereoPannerNode::~StereoPannerNode() |
| +{ |
| + ASSERT(!isInitialized()); |
| +} |
| + |
| +void StereoPannerNode::dispose() |
| +{ |
| + uninitialize(); |
| + AudioNode::dispose(); |
| +} |
| + |
| +void StereoPannerNode::process(size_t framesToProcess) |
| +{ |
| + AudioBus* outputBus = output(0)->bus(); |
| + |
| + if (!isInitialized() || !input(0)->isConnected() || !m_stereoPanner.get()) { |
| + outputBus->zero(); |
| + return; |
| + } |
| + |
| + AudioBus* inputBus = input(0)->bus(); |
| + if (!inputBus) { |
| + outputBus->zero(); |
| + return; |
| + } |
| + |
| + if (pan()->hasSampleAccurateValues()) { |
| + // Apply sample-accurate panning specified by AudioParam automation. |
| + ASSERT(framesToProcess <= m_sampleAccuratePanValues.size()); |
| + if (framesToProcess <= m_sampleAccuratePanValues.size()) { |
| + float* panValues = m_sampleAccuratePanValues.data(); |
| + pan()->calculateSampleAccurateValues(panValues, framesToProcess); |
| + m_stereoPanner->panWithSampleAccurateValues(inputBus, outputBus, panValues, framesToProcess); |
| + } |
| + } else { |
| + m_stereoPanner->panToTargetValue(inputBus, outputBus, pan()->value(), framesToProcess); |
| + } |
| +} |
| + |
| +void StereoPannerNode::initialize() |
| +{ |
| + if (isInitialized()) |
| + return; |
| + |
| + m_stereoPanner = Spatializer::create(Spatializer::PanningModelEqualPower, sampleRate()); |
| + |
| + AudioNode::initialize(); |
| +} |
| + |
| +void StereoPannerNode::uninitialize() |
| +{ |
| + if (!isInitialized()) |
| + return; |
| + |
| + m_stereoPanner.clear(); |
| + |
| + AudioNode::uninitialize(); |
| +} |
| + |
| +void StereoPannerNode::trace(Visitor* visitor) |
| +{ |
| + visitor->trace(m_stereoPanner); |
| + visitor->trace(m_pan); |
| + AudioNode::trace(visitor); |
| +} |
| + |
| +} // namespace blink |
| + |
| +#endif // ENABLE(WEB_AUDIO) |