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

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

Issue 1952793002: Move the exception logic to the AudioNode creator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 7 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived 14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission. 15 * from this software without specific prior written permission.
16 * 16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "modules/webaudio/PeriodicWave.h" 29 #include "modules/webaudio/PeriodicWave.h"
30 #include "bindings/core/v8/ExceptionMessages.h"
31 #include "bindings/core/v8/ExceptionState.h"
32 #include "core/dom/ExceptionCode.h"
33 #include "modules/webaudio/AbstractAudioContext.h"
30 #include "modules/webaudio/OscillatorNode.h" 34 #include "modules/webaudio/OscillatorNode.h"
31 #include "platform/audio/FFTFrame.h" 35 #include "platform/audio/FFTFrame.h"
32 #include "platform/audio/VectorMath.h" 36 #include "platform/audio/VectorMath.h"
33 #include <algorithm> 37 #include <algorithm>
34 38
35 namespace blink { 39 namespace blink {
36 40
37 // The number of bands per octave. Each octave will have this many entries in t he wave tables. 41 // The number of bands per octave. Each octave will have this many entries in t he wave tables.
38 const unsigned kNumberOfOctaveBands = 3; 42 const unsigned kNumberOfOctaveBands = 3;
39 43
40 // The max length of a periodic wave. This must be a power of two greater than o r equal to 2048 and 44 // The max length of a periodic wave. This must be a power of two greater than o r equal to 2048 and
41 // must be supported by the FFT routines. 45 // must be supported by the FFT routines.
42 const unsigned kMaxPeriodicWaveSize = 16384; 46 const unsigned kMaxPeriodicWaveSize = 16384;
43 47
44 const float CentsPerRange = 1200 / kNumberOfOctaveBands; 48 const float CentsPerRange = 1200 / kNumberOfOctaveBands;
45 49
46 using namespace VectorMath; 50 using namespace VectorMath;
47 51
48 PeriodicWave* PeriodicWave::create(float sampleRate, DOMFloat32Array* real, DOMF loat32Array* imag, bool disableNormalization) 52 PeriodicWave* PeriodicWave::create(
53 AbstractAudioContext& context,
54 DOMFloat32Array* real,
55 DOMFloat32Array* imag,
56 bool disableNormalization,
57 ExceptionState& exceptionState)
49 { 58 {
50 bool isGood = real && imag && real->length() == imag->length(); 59 DCHECK(isMainThread());
51 ASSERT(isGood); 60
52 if (isGood) { 61 if (context.isContextClosed()) {
53 PeriodicWave* periodicWave = new PeriodicWave(sampleRate); 62 context.throwExceptionForClosedState(exceptionState);
54 size_t numberOfComponents = real->length(); 63 return nullptr;
55 periodicWave->createBandLimitedTables(real->data(), imag->data(), number OfComponents, disableNormalization);
56 return periodicWave;
57 } 64 }
58 return nullptr; 65
66 if (real->length() != imag->length()) {
67 exceptionState.throwDOMException(
68 IndexSizeError,
69 "length of real array (" + String::number(real->length())
70 + ") and length of imaginary array (" + String::number(imag->length ())
71 + ") must match.");
72 return nullptr;
73 }
74
75 PeriodicWave* periodicWave = new PeriodicWave(context.sampleRate());
76 size_t numberOfComponents = real->length();
77 periodicWave->createBandLimitedTables(real->data(), imag->data(), numberOfCo mponents, disableNormalization);
78 return periodicWave;
59 } 79 }
60 80
61 PeriodicWave* PeriodicWave::createSine(float sampleRate) 81 PeriodicWave* PeriodicWave::createSine(float sampleRate)
62 { 82 {
63 PeriodicWave* periodicWave = new PeriodicWave(sampleRate); 83 PeriodicWave* periodicWave = new PeriodicWave(sampleRate);
64 periodicWave->generateBasicWaveform(OscillatorHandler::SINE); 84 periodicWave->generateBasicWaveform(OscillatorHandler::SINE);
65 return periodicWave; 85 return periodicWave;
66 } 86 }
67 87
68 PeriodicWave* PeriodicWave::createSquare(float sampleRate) 88 PeriodicWave* PeriodicWave::createSquare(float sampleRate)
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 342
323 realP[n] = 0; 343 realP[n] = 0;
324 imagP[n] = b; 344 imagP[n] = b;
325 } 345 }
326 346
327 createBandLimitedTables(realP, imagP, halfSize, false); 347 createBandLimitedTables(realP, imagP, halfSize, false);
328 } 348 }
329 349
330 } // namespace blink 350 } // namespace blink
331 351
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698