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 |
(...skipping 10 matching lines...) Expand all Loading... |
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 "bindings/core/v8/ExceptionMessages.h" | 25 #include "bindings/core/v8/ExceptionMessages.h" |
26 #include "bindings/core/v8/ExceptionState.h" | 26 #include "bindings/core/v8/ExceptionState.h" |
27 #include "core/dom/ExceptionCode.h" | 27 #include "core/dom/ExceptionCode.h" |
28 #include "modules/webaudio/AudioBasicProcessorHandler.h" | 28 #include "modules/webaudio/AudioBasicProcessorHandler.h" |
29 #include "modules/webaudio/BaseAudioContext.h" | 29 #include "modules/webaudio/BaseAudioContext.h" |
30 #include "modules/webaudio/WaveShaperNode.h" | 30 #include "modules/webaudio/WaveShaperNode.h" |
| 31 #include "modules/webaudio/WaveShaperOptions.h" |
31 #include "wtf/PtrUtil.h" | 32 #include "wtf/PtrUtil.h" |
32 | 33 |
33 namespace blink { | 34 namespace blink { |
34 | 35 |
35 WaveShaperNode::WaveShaperNode(BaseAudioContext& context) | 36 WaveShaperNode::WaveShaperNode(BaseAudioContext& context) |
36 : AudioNode(context) | 37 : AudioNode(context) |
37 { | 38 { |
38 setHandler(AudioBasicProcessorHandler::create(AudioHandler::NodeTypeWaveShap
er, *this, context.sampleRate(), wrapUnique(new WaveShaperProcessor(context.samp
leRate(), 1)))); | 39 setHandler(AudioBasicProcessorHandler::create(AudioHandler::NodeTypeWaveShap
er, *this, context.sampleRate(), wrapUnique(new WaveShaperProcessor(context.samp
leRate(), 1)))); |
39 | 40 |
40 handler().initialize(); | 41 handler().initialize(); |
41 } | 42 } |
42 | 43 |
43 WaveShaperNode* WaveShaperNode::create(BaseAudioContext& context, ExceptionState
& exceptionState) | 44 WaveShaperNode* WaveShaperNode::create(BaseAudioContext& context, ExceptionState
& exceptionState) |
44 { | 45 { |
45 DCHECK(isMainThread()); | 46 DCHECK(isMainThread()); |
46 | 47 |
47 if (context.isContextClosed()) { | 48 if (context.isContextClosed()) { |
48 context.throwExceptionForClosedState(exceptionState); | 49 context.throwExceptionForClosedState(exceptionState); |
49 return nullptr; | 50 return nullptr; |
50 } | 51 } |
51 | 52 |
52 return new WaveShaperNode(context); | 53 return new WaveShaperNode(context); |
53 } | 54 } |
54 | 55 |
| 56 WaveShaperNode* WaveShaperNode::create(BaseAudioContext* context, const WaveShap
erOptions& options, ExceptionState& exceptionState) |
| 57 { |
| 58 WaveShaperNode* node = create(*context, exceptionState); |
| 59 |
| 60 if (!node) |
| 61 return nullptr; |
| 62 |
| 63 node->handleChannelOptions(options, exceptionState); |
| 64 |
| 65 if (options.hasCurve()) |
| 66 node->setCurve(options.curve(), exceptionState); |
| 67 if (options.hasOversample()) |
| 68 node->setOversample(options.oversample()); |
| 69 |
| 70 return node; |
| 71 } |
55 WaveShaperProcessor* WaveShaperNode::getWaveShaperProcessor() const | 72 WaveShaperProcessor* WaveShaperNode::getWaveShaperProcessor() const |
56 { | 73 { |
57 return static_cast<WaveShaperProcessor*>(static_cast<AudioBasicProcessorHand
ler&>(handler()).processor()); | 74 return static_cast<WaveShaperProcessor*>(static_cast<AudioBasicProcessorHand
ler&>(handler()).processor()); |
58 } | 75 } |
59 | 76 |
| 77 void WaveShaperNode::setCurveImpl( |
| 78 const float* curveData, unsigned curveLength, ExceptionState& exceptionState
) |
| 79 { |
| 80 DCHECK(isMainThread()); |
| 81 |
| 82 if (curveData && curveLength < 2) { |
| 83 exceptionState.throwDOMException( |
| 84 InvalidAccessError, |
| 85 ExceptionMessages::indexExceedsMinimumBound<unsigned>( |
| 86 "curve length", |
| 87 curveLength, |
| 88 2)); |
| 89 return; |
| 90 } |
| 91 |
| 92 getWaveShaperProcessor()->setCurve(curveData, curveLength); |
| 93 } |
| 94 |
60 void WaveShaperNode::setCurve(DOMFloat32Array* curve, ExceptionState& exceptionS
tate) | 95 void WaveShaperNode::setCurve(DOMFloat32Array* curve, ExceptionState& exceptionS
tate) |
61 { | 96 { |
62 DCHECK(isMainThread()); | 97 DCHECK(isMainThread()); |
63 | 98 |
64 if (curve && curve->length() < 2) { | 99 if (curve) |
65 exceptionState.throwDOMException( | 100 setCurveImpl(curve->data(), curve->length(), exceptionState); |
66 InvalidAccessError, | 101 else |
67 ExceptionMessages::indexExceedsMinimumBound<unsigned>( | 102 setCurveImpl(nullptr, 0, exceptionState); |
68 "curve length", | 103 } |
69 curve->length(), | |
70 2)); | |
71 return; | |
72 } | |
73 | 104 |
74 getWaveShaperProcessor()->setCurve(curve); | 105 void WaveShaperNode::setCurve(const Vector<float>& curve, ExceptionState& except
ionState) |
| 106 { |
| 107 DCHECK(isMainThread()); |
| 108 |
| 109 setCurveImpl(curve.data(), curve.size(), exceptionState); |
75 } | 110 } |
76 | 111 |
77 DOMFloat32Array* WaveShaperNode::curve() | 112 DOMFloat32Array* WaveShaperNode::curve() |
78 { | 113 { |
79 Vector<float>* curve = getWaveShaperProcessor()->curve(); | 114 Vector<float>* curve = getWaveShaperProcessor()->curve(); |
80 if (!curve) | 115 if (!curve) |
81 return nullptr; | 116 return nullptr; |
82 | 117 |
83 unsigned size = curve->size(); | 118 unsigned size = curve->size(); |
84 RefPtr<WTF::Float32Array> newCurve = WTF::Float32Array::create(size); | 119 RefPtr<WTF::Float32Array> newCurve = WTF::Float32Array::create(size); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 case WaveShaperProcessor::OverSample4x: | 153 case WaveShaperProcessor::OverSample4x: |
119 return "4x"; | 154 return "4x"; |
120 default: | 155 default: |
121 ASSERT_NOT_REACHED(); | 156 ASSERT_NOT_REACHED(); |
122 return "none"; | 157 return "none"; |
123 } | 158 } |
124 } | 159 } |
125 | 160 |
126 } // namespace blink | 161 } // namespace blink |
127 | 162 |
OLD | NEW |