Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AnalyserNode.cpp

Issue 2102133002: Add constructors for WebAudio nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update files to the right GN files. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 "modules/webaudio/AnalyserNode.h" 25 #include "modules/webaudio/AnalyserNode.h"
26 #include "bindings/core/v8/ExceptionMessages.h" 26 #include "bindings/core/v8/ExceptionMessages.h"
27 #include "bindings/core/v8/ExceptionState.h" 27 #include "bindings/core/v8/ExceptionState.h"
28 #include "core/dom/ExceptionCode.h" 28 #include "core/dom/ExceptionCode.h"
29 #include "modules/webaudio/AnalyserOptions.h"
29 #include "modules/webaudio/AudioNodeInput.h" 30 #include "modules/webaudio/AudioNodeInput.h"
30 #include "modules/webaudio/AudioNodeOutput.h" 31 #include "modules/webaudio/AudioNodeOutput.h"
31 32
32 namespace blink { 33 namespace blink {
33 34
34 AnalyserHandler::AnalyserHandler(AudioNode& node, float sampleRate) 35 AnalyserHandler::AnalyserHandler(AudioNode& node, float sampleRate)
35 : AudioBasicInspectorHandler(NodeTypeAnalyser, node, sampleRate, 2) 36 : AudioBasicInspectorHandler(NodeTypeAnalyser, node, sampleRate, 2)
36 { 37 {
37 initialize(); 38 initialize();
38 } 39 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 { 94 {
94 if (k > minDecibels()) { 95 if (k > minDecibels()) {
95 m_analyser.setMaxDecibels(k); 96 m_analyser.setMaxDecibels(k);
96 } else { 97 } else {
97 exceptionState.throwDOMException( 98 exceptionState.throwDOMException(
98 IndexSizeError, 99 IndexSizeError,
99 ExceptionMessages::indexExceedsMinimumBound("maxDecibels", k, minDec ibels())); 100 ExceptionMessages::indexExceedsMinimumBound("maxDecibels", k, minDec ibels()));
100 } 101 }
101 } 102 }
102 103
104 void AnalyserHandler::setMinMaxDecibels(double minDecibels, double maxDecibels, ExceptionState& exceptionState)
105 {
106 if (minDecibels >= maxDecibels) {
107 exceptionState.throwDOMException(
108 IndexSizeError,
109 "maxDecibels (" + String::number(maxDecibels)
110 + ") must be greater than or equal to minDecibels "
111 + "( " + String::number(minDecibels) + ").");
112 return;
113 }
114 m_analyser.setMinDecibels(minDecibels);
115 m_analyser.setMaxDecibels(maxDecibels);
116 }
117
103 void AnalyserHandler::setSmoothingTimeConstant(double k, ExceptionState& excepti onState) 118 void AnalyserHandler::setSmoothingTimeConstant(double k, ExceptionState& excepti onState)
104 { 119 {
105 if (k >= 0 && k <= 1) { 120 if (k >= 0 && k <= 1) {
106 m_analyser.setSmoothingTimeConstant(k); 121 m_analyser.setSmoothingTimeConstant(k);
107 } else { 122 } else {
108 exceptionState.throwDOMException( 123 exceptionState.throwDOMException(
109 IndexSizeError, 124 IndexSizeError,
110 ExceptionMessages::indexOutsideRange("smoothing value", k, 0.0, Exce ptionMessages::InclusiveBound, 1.0, ExceptionMessages::InclusiveBound)); 125 ExceptionMessages::indexOutsideRange("smoothing value", k, 0.0, Exce ptionMessages::InclusiveBound, 1.0, ExceptionMessages::InclusiveBound));
111 } 126 }
112 } 127 }
(...skipping 11 matching lines...) Expand all
124 DCHECK(isMainThread()); 139 DCHECK(isMainThread());
125 140
126 if (context.isContextClosed()) { 141 if (context.isContextClosed()) {
127 context.throwExceptionForClosedState(exceptionState); 142 context.throwExceptionForClosedState(exceptionState);
128 return nullptr; 143 return nullptr;
129 } 144 }
130 145
131 return new AnalyserNode(context); 146 return new AnalyserNode(context);
132 } 147 }
133 148
149 AnalyserNode* AnalyserNode::create(BaseAudioContext* context, const AnalyserOpti ons& options, ExceptionState& exceptionState)
150 {
hongchan 2016/09/08 21:41:11 DCHECK(isMainThread()); Perhaps?
Raymond Toy 2016/09/08 21:58:00 Yes!
Raymond Toy 2016/09/09 17:32:53 Done.
151 AnalyserNode* node = create(*context, exceptionState);
152
153 if (!node)
154 return node;
hongchan 2016/09/08 21:41:11 Wouldn't it be better to return nullptr?
Raymond Toy 2016/09/09 17:32:53 Done.
155
156 node->handleChannelOptions(options, exceptionState);
157
158 if (options.hasFftSize())
159 node->setFftSize(options.fftSize(), exceptionState);
160
161 if (options.hasSmoothingTimeConstant())
162 node->setSmoothingTimeConstant(options.smoothingTimeConstant(), exceptio nState);
163
164 // minDecibels and maxDecibels have default values. Set both of the values
165 // at once.
166 node->setMinMaxDecibels(options.minDecibels(), options.maxDecibels(), except ionState);
167
168 return node;
169 }
170
134 AnalyserHandler& AnalyserNode::analyserHandler() const 171 AnalyserHandler& AnalyserNode::analyserHandler() const
135 { 172 {
136 return static_cast<AnalyserHandler&>(handler()); 173 return static_cast<AnalyserHandler&>(handler());
137 } 174 }
138 175
139 unsigned AnalyserNode::fftSize() const 176 unsigned AnalyserNode::fftSize() const
140 { 177 {
141 return analyserHandler().fftSize(); 178 return analyserHandler().fftSize();
142 } 179 }
143 180
(...skipping 15 matching lines...) Expand all
159 double AnalyserNode::minDecibels() const 196 double AnalyserNode::minDecibels() const
160 { 197 {
161 return analyserHandler().minDecibels(); 198 return analyserHandler().minDecibels();
162 } 199 }
163 200
164 void AnalyserNode::setMaxDecibels(double max, ExceptionState& exceptionState) 201 void AnalyserNode::setMaxDecibels(double max, ExceptionState& exceptionState)
165 { 202 {
166 analyserHandler().setMaxDecibels(max, exceptionState); 203 analyserHandler().setMaxDecibels(max, exceptionState);
167 } 204 }
168 205
206 void AnalyserNode::setMinMaxDecibels(double min, double max, ExceptionState& exc eptionState)
207 {
208 analyserHandler().setMinMaxDecibels(min, max, exceptionState);
209 }
210
169 double AnalyserNode::maxDecibels() const 211 double AnalyserNode::maxDecibels() const
170 { 212 {
171 return analyserHandler().maxDecibels(); 213 return analyserHandler().maxDecibels();
172 } 214 }
173 215
174 void AnalyserNode::setSmoothingTimeConstant(double smoothingTime, ExceptionState & exceptionState) 216 void AnalyserNode::setSmoothingTimeConstant(double smoothingTime, ExceptionState & exceptionState)
175 { 217 {
176 analyserHandler().setSmoothingTimeConstant(smoothingTime, exceptionState); 218 analyserHandler().setSmoothingTimeConstant(smoothingTime, exceptionState);
177 } 219 }
178 220
(...skipping 17 matching lines...) Expand all
196 analyserHandler().getFloatTimeDomainData(array); 238 analyserHandler().getFloatTimeDomainData(array);
197 } 239 }
198 240
199 void AnalyserNode::getByteTimeDomainData(DOMUint8Array* array) 241 void AnalyserNode::getByteTimeDomainData(DOMUint8Array* array)
200 { 242 {
201 analyserHandler().getByteTimeDomainData(array); 243 analyserHandler().getByteTimeDomainData(array);
202 } 244 }
203 245
204 } // namespace blink 246 } // namespace blink
205 247
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698