summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/webaudio/PeriodicWave.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/webaudio/PeriodicWave.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/Modules/webaudio/PeriodicWave.cpp')
-rw-r--r--Source/WebCore/Modules/webaudio/PeriodicWave.cpp58
1 files changed, 24 insertions, 34 deletions
diff --git a/Source/WebCore/Modules/webaudio/PeriodicWave.cpp b/Source/WebCore/Modules/webaudio/PeriodicWave.cpp
index 3044c21c1..bb2a07d23 100644
--- a/Source/WebCore/Modules/webaudio/PeriodicWave.cpp
+++ b/Source/WebCore/Modules/webaudio/PeriodicWave.cpp
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -33,7 +33,6 @@
#include "PeriodicWave.h"
#include "FFTFrame.h"
-#include "OscillatorNode.h"
#include "VectorMath.h"
#include <algorithm>
@@ -45,44 +44,40 @@ namespace WebCore {
using namespace VectorMath;
-PassRefPtr<PeriodicWave> PeriodicWave::create(float sampleRate, Float32Array* real, Float32Array* imag)
+Ref<PeriodicWave> PeriodicWave::create(float sampleRate, Float32Array& real, Float32Array& imaginary)
{
- bool isGood = real && imag && real->length() == imag->length();
- ASSERT(isGood);
- if (isGood) {
- RefPtr<PeriodicWave> waveTable = adoptRef(new PeriodicWave(sampleRate));
- size_t numberOfComponents = real->length();
- waveTable->createBandLimitedTables(real->data(), imag->data(), numberOfComponents);
- return waveTable;
- }
- return nullptr;
+ ASSERT(real.length() == imaginary.length());
+
+ auto waveTable = adoptRef(*new PeriodicWave(sampleRate));
+ waveTable->createBandLimitedTables(real.data(), imaginary.data(), real.length());
+ return waveTable;
}
-PassRefPtr<PeriodicWave> PeriodicWave::createSine(float sampleRate)
+Ref<PeriodicWave> PeriodicWave::createSine(float sampleRate)
{
- RefPtr<PeriodicWave> waveTable = adoptRef(new PeriodicWave(sampleRate));
- waveTable->generateBasicWaveform(OscillatorNode::SINE);
+ Ref<PeriodicWave> waveTable = adoptRef(*new PeriodicWave(sampleRate));
+ waveTable->generateBasicWaveform(Type::Sine);
return waveTable;
}
-PassRefPtr<PeriodicWave> PeriodicWave::createSquare(float sampleRate)
+Ref<PeriodicWave> PeriodicWave::createSquare(float sampleRate)
{
- RefPtr<PeriodicWave> waveTable = adoptRef(new PeriodicWave(sampleRate));
- waveTable->generateBasicWaveform(OscillatorNode::SQUARE);
+ Ref<PeriodicWave> waveTable = adoptRef(*new PeriodicWave(sampleRate));
+ waveTable->generateBasicWaveform(Type::Square);
return waveTable;
}
-PassRefPtr<PeriodicWave> PeriodicWave::createSawtooth(float sampleRate)
+Ref<PeriodicWave> PeriodicWave::createSawtooth(float sampleRate)
{
- RefPtr<PeriodicWave> waveTable = adoptRef(new PeriodicWave(sampleRate));
- waveTable->generateBasicWaveform(OscillatorNode::SAWTOOTH);
+ Ref<PeriodicWave> waveTable = adoptRef(*new PeriodicWave(sampleRate));
+ waveTable->generateBasicWaveform(Type::Sawtooth);
return waveTable;
}
-PassRefPtr<PeriodicWave> PeriodicWave::createTriangle(float sampleRate)
+Ref<PeriodicWave> PeriodicWave::createTriangle(float sampleRate)
{
- RefPtr<PeriodicWave> waveTable = adoptRef(new PeriodicWave(sampleRate));
- waveTable->generateBasicWaveform(OscillatorNode::TRIANGLE);
+ Ref<PeriodicWave> waveTable = adoptRef(*new PeriodicWave(sampleRate));
+ waveTable->generateBasicWaveform(Type::Triangle);
return waveTable;
}
@@ -217,7 +212,7 @@ void PeriodicWave::createBandLimitedTables(const float* realData, const float* i
}
}
-void PeriodicWave::generateBasicWaveform(int shape)
+void PeriodicWave::generateBasicWaveform(Type shape)
{
unsigned fftSize = periodicWaveSize();
unsigned halfSize = fftSize / 2;
@@ -242,31 +237,26 @@ void PeriodicWave::generateBasicWaveform(int shape)
// Calculate Fourier coefficients depending on the shape.
// Note that the overall scaling (magnitude) of the waveforms is normalized in createBandLimitedTables().
switch (shape) {
- case OscillatorNode::SINE:
+ case Type::Sine:
// Standard sine wave function.
a = 0;
b = (n == 1) ? 1 : 0;
break;
- case OscillatorNode::SQUARE:
+ case Type::Square:
// Square-shaped waveform with the first half its maximum value and the second half its minimum value.
a = 0;
b = invOmega * ((n & 1) ? 2 : 0);
break;
- case OscillatorNode::SAWTOOTH:
+ case Type::Sawtooth:
// Sawtooth-shaped waveform with the first half ramping from zero to maximum and the second half from minimum to zero.
a = 0;
b = -invOmega * cos(0.5 * omega);
break;
- case OscillatorNode::TRIANGLE:
+ case Type::Triangle:
// Triangle-shaped waveform going from its maximum value to its minimum value then back to the maximum value.
a = (4 - 4 * cos(0.5 * omega)) / (n * n * piFloat * piFloat);
b = 0;
break;
- default:
- ASSERT_NOT_REACHED();
- a = 0;
- b = 0;
- break;
}
realP[n] = a;