| Index: third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
|
| diff --git a/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp b/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
|
| index 69321b15b6550d29b5660e4bd455bc3e30c54fb7..733f675bccd544a185c13153eeba7de1cc862f5e 100644
|
| --- a/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
|
| +++ b/third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp
|
| @@ -32,6 +32,7 @@
|
| #include "modules/webaudio/BaseAudioContext.h"
|
| #include "modules/webaudio/OscillatorNode.h"
|
| #include "modules/webaudio/PeriodicWave.h"
|
| +#include "modules/webaudio/PeriodicWaveOptions.h"
|
| #include "platform/audio/FFTFrame.h"
|
| #include "platform/audio/VectorMath.h"
|
| #include "wtf/PtrUtil.h"
|
| @@ -53,8 +54,10 @@ using namespace VectorMath;
|
|
|
| PeriodicWave* PeriodicWave::create(
|
| BaseAudioContext& context,
|
| - DOMFloat32Array* real,
|
| - DOMFloat32Array* imag,
|
| + size_t realLength,
|
| + const float* real,
|
| + size_t imagLength,
|
| + const float* imag,
|
| bool disableNormalization,
|
| ExceptionState& exceptionState)
|
| {
|
| @@ -65,21 +68,80 @@ PeriodicWave* PeriodicWave::create(
|
| return nullptr;
|
| }
|
|
|
| - if (real->length() != imag->length()) {
|
| + if (realLength != imagLength) {
|
| exceptionState.throwDOMException(
|
| IndexSizeError,
|
| - "length of real array (" + String::number(real->length())
|
| - + ") and length of imaginary array (" + String::number(imag->length())
|
| + "length of real array (" + String::number(realLength)
|
| + + ") and length of imaginary array (" + String::number(imagLength)
|
| + ") must match.");
|
| return nullptr;
|
| }
|
|
|
| PeriodicWave* periodicWave = new PeriodicWave(context.sampleRate());
|
| - size_t numberOfComponents = real->length();
|
| - periodicWave->createBandLimitedTables(real->data(), imag->data(), numberOfComponents, disableNormalization);
|
| + periodicWave->createBandLimitedTables(real, imag, realLength, disableNormalization);
|
| return periodicWave;
|
| }
|
|
|
| +PeriodicWave* PeriodicWave::create(
|
| + BaseAudioContext& context,
|
| + DOMFloat32Array* real,
|
| + DOMFloat32Array* imag,
|
| + bool disableNormalization,
|
| + ExceptionState& exceptionState)
|
| +{
|
| + DCHECK(isMainThread());
|
| +
|
| + return create(
|
| + context,
|
| + real->length(),
|
| + real->data(),
|
| + imag->length(),
|
| + imag->data(),
|
| + disableNormalization,
|
| + exceptionState);
|
| +}
|
| +
|
| +PeriodicWave* PeriodicWave::create(
|
| + BaseAudioContext* context,
|
| + const PeriodicWaveOptions& options,
|
| + ExceptionState& exceptionState)
|
| +{
|
| + bool normalize = options.hasDisableNormalization() ? options.disableNormalization() : false;
|
| +
|
| +
|
| + if (!options.hasReal() && !options.hasImag()) {
|
| + exceptionState.throwDOMException(
|
| + InvalidStateError,
|
| + "At least one of real and imag members must be specified.");
|
| + return nullptr;
|
| + }
|
| +
|
| + Vector<float> realCoef;
|
| + Vector<float> imagCoef;
|
| +
|
| + if (options.hasReal()) {
|
| + realCoef = options.real();
|
| + if (options.hasImag())
|
| + imagCoef = options.imag();
|
| + else
|
| + imagCoef.resize(realCoef.size());
|
| + } else {
|
| + // We know real is not given, so imag must exist (because we checked for
|
| + // this above).
|
| + imagCoef = options.imag();
|
| + realCoef.resize(imagCoef.size());
|
| + }
|
| +
|
| + return create(
|
| + *context,
|
| + realCoef.size(),
|
| + realCoef.data(),
|
| + imagCoef.size(),
|
| + imagCoef.data(),
|
| + normalize,
|
| + exceptionState);
|
| +}
|
| +
|
| PeriodicWave* PeriodicWave::createSine(float sampleRate)
|
| {
|
| PeriodicWave* periodicWave = new PeriodicWave(sampleRate);
|
|
|