OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // | |
3 // Redistribution and use in source and binary forms, with or without | |
4 // modification, are permitted provided that the following conditions are | |
5 // met: | |
6 // | |
7 // * Redistributions of source code must retain the above copyright | |
8 // notice, this list of conditions and the following disclaimer. | |
9 // * Redistributions in binary form must reproduce the above | |
10 // copyright notice, this list of conditions and the following disclaimer | |
11 // in the documentation and/or other materials provided with the | |
12 // distribution. | |
13 // * Neither the name of Google Inc. nor the names of its | |
14 // contributors may be used to endorse or promote products derived from | |
15 // this software without specific prior written permission. | |
16 // | |
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | |
29 #include "config.h" | |
30 | |
31 #if ENABLE(WEB_AUDIO) | |
32 | |
33 #include "modules/webaudio/StereoPannerNode.h" | |
34 | |
35 #include "bindings/core/v8/ExceptionMessages.h" | |
36 #include "bindings/core/v8/ExceptionState.h" | |
37 #include "core/dom/ExecutionContext.h" | |
38 #include "modules/webaudio/AudioContext.h" | |
39 #include "modules/webaudio/AudioNodeInput.h" | |
40 #include "modules/webaudio/AudioNodeOutput.h" | |
41 #include "platform/audio/StereoPanner.h" | |
42 #include "wtf/MathExtras.h" | |
43 | |
44 namespace blink { | |
45 | |
46 StereoPannerNode::StereoPannerNode(AudioContext* context, float sampleRate) | |
47 : AudioNode(context, sampleRate) | |
48 , m_sampleAccuratePanValues(AudioNode::ProcessingSizeInFrames) | |
49 { | |
50 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.
| |
51 | |
52 addInput(); | |
53 addOutput(AudioNodeOutput::create(this, 2)); | |
54 | |
55 // This node-specific default mixing rules declare that StereoPannerNode | |
56 // 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.
| |
57 m_channelCount = 2; | |
58 m_channelCountMode = ClampedMax; | |
59 m_channelInterpretation = AudioBus::Speakers; | |
60 | |
61 setNodeType(NodeTypeStereoPanner); | |
62 | |
63 initialize(); | |
64 } | |
65 | |
66 StereoPannerNode::~StereoPannerNode() | |
67 { | |
68 ASSERT(!isInitialized()); | |
69 } | |
70 | |
71 void StereoPannerNode::dispose() | |
72 { | |
73 uninitialize(); | |
74 AudioNode::dispose(); | |
75 } | |
76 | |
77 void StereoPannerNode::process(size_t framesToProcess) | |
78 { | |
79 AudioBus* outputBus = output(0)->bus(); | |
80 | |
81 if (!isInitialized() || !input(0)->isConnected() || !m_stereoPanner.get()) { | |
82 outputBus->zero(); | |
83 return; | |
84 } | |
85 | |
86 AudioBus* inputBus = input(0)->bus(); | |
87 if (!inputBus) { | |
88 outputBus->zero(); | |
89 return; | |
90 } | |
91 | |
92 if (pan()->hasSampleAccurateValues()) { | |
93 // Apply sample-accurate panning specified by AudioParam automation. | |
94 ASSERT(framesToProcess <= m_sampleAccuratePanValues.size()); | |
95 if (framesToProcess <= m_sampleAccuratePanValues.size()) { | |
96 float* panValues = m_sampleAccuratePanValues.data(); | |
97 pan()->calculateSampleAccurateValues(panValues, framesToProcess); | |
98 m_stereoPanner->panWithSampleAccurateValues(inputBus, outputBus, pan Values, framesToProcess); | |
99 } | |
100 } else { | |
101 m_stereoPanner->panToTargetValue(inputBus, outputBus, pan()->value(), fr amesToProcess); | |
102 } | |
103 } | |
104 | |
105 void StereoPannerNode::initialize() | |
106 { | |
107 if (isInitialized()) | |
108 return; | |
109 | |
110 m_stereoPanner = Spatializer::create(Spatializer::PanningModelEqualPower, sa mpleRate()); | |
111 | |
112 AudioNode::initialize(); | |
113 } | |
114 | |
115 void StereoPannerNode::uninitialize() | |
116 { | |
117 if (!isInitialized()) | |
118 return; | |
119 | |
120 m_stereoPanner.clear(); | |
121 | |
122 AudioNode::uninitialize(); | |
123 } | |
124 | |
125 void StereoPannerNode::trace(Visitor* visitor) | |
126 { | |
127 visitor->trace(m_stereoPanner); | |
128 visitor->trace(m_pan); | |
129 AudioNode::trace(visitor); | |
130 } | |
131 | |
132 } // namespace blink | |
133 | |
134 #endif // ENABLE(WEB_AUDIO) | |
OLD | NEW |