From c8140cad4d867b45e43691f999e4972c85a25aed Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Thu, 9 Aug 2012 00:18:23 +0000 Subject: [PATCH] Creating "basic waveform" Oscillator nodes is not efficient https://bugs.webkit.org/show_bug.cgi?id=93194 Patch by Raymond Toy on 2012-08-08 Reviewed by Chris Rogers. Source/WebCore: Cache the wavetables for the basic types so they don't have to be recomputed every time. Also fix a bug where oscillator type was always set to CUSTOM instead of the specified oscillator type. Test added for this. Test: webaudio/oscillator-basic.html * Modules/webaudio/Oscillator.cpp: (WebCore): (WebCore::Oscillator::setType): Use cached wavetables; fix bug in setting the oscillator type. * Modules/webaudio/Oscillator.h: (Oscillator): Define static variables to hold cached wavetables. LayoutTests: Add test to verify that the returned oscillator type is the same as what was set. * webaudio/oscillator-basic-expected.txt: Added. * webaudio/oscillator-basic.html: Added. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125122 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 13 ++++ LayoutTests/webaudio/oscillator-basic-expected.txt | 13 ++++ LayoutTests/webaudio/oscillator-basic.html | 72 ++++++++++++++++++++++ Source/WebCore/ChangeLog | 22 +++++++ Source/WebCore/Modules/webaudio/Oscillator.cpp | 29 ++++++--- Source/WebCore/Modules/webaudio/Oscillator.h | 6 ++ 6 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 LayoutTests/webaudio/oscillator-basic-expected.txt create mode 100644 LayoutTests/webaudio/oscillator-basic.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index f694117..180157b 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,16 @@ +2012-08-08 Raymond Toy + + Creating "basic waveform" Oscillator nodes is not efficient + https://bugs.webkit.org/show_bug.cgi?id=93194 + + Reviewed by Chris Rogers. + + Add test to verify that the returned oscillator type is the same + as what was set. + + * webaudio/oscillator-basic-expected.txt: Added. + * webaudio/oscillator-basic.html: Added. + 2012-08-08 Tom Sepez Avoid ASSERT(m_workerContext->isSharedWorkerContext()) in WorkerScriptController::initScript() diff --git a/LayoutTests/webaudio/oscillator-basic-expected.txt b/LayoutTests/webaudio/oscillator-basic-expected.txt new file mode 100644 index 0000000..46c6edb --- /dev/null +++ b/LayoutTests/webaudio/oscillator-basic-expected.txt @@ -0,0 +1,13 @@ +Basic test of setting Oscillator node types. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + +PASS Oscillator correctly set to SINE type. +PASS Oscillator correctly set to SQUARE type. +PASS Oscillator correctly set to SAWTOOTH type. +PASS Oscillator correctly set to TRIANGLE type. +PASS Oscillator correctly set to CUSTOM type. +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/webaudio/oscillator-basic.html b/LayoutTests/webaudio/oscillator-basic.html new file mode 100644 index 0000000..bf26b02 --- /dev/null +++ b/LayoutTests/webaudio/oscillator-basic.html @@ -0,0 +1,72 @@ + + + + + + + + + + + +
+
+ + + + + + + diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 842a0ed..bb9fd5a 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,25 @@ +2012-08-08 Raymond Toy + + Creating "basic waveform" Oscillator nodes is not efficient + https://bugs.webkit.org/show_bug.cgi?id=93194 + + Reviewed by Chris Rogers. + + Cache the wavetables for the basic types so they don't have to be + recomputed every time. + + Also fix a bug where oscillator type was always set to CUSTOM + instead of the specified oscillator type. Test added for this. + + Test: webaudio/oscillator-basic.html + + * Modules/webaudio/Oscillator.cpp: + (WebCore): + (WebCore::Oscillator::setType): Use cached wavetables; fix bug in + setting the oscillator type. + * Modules/webaudio/Oscillator.h: + (Oscillator): Define static variables to hold cached wavetables. + 2012-08-08 Tom Sepez Avoid ASSERT(m_workerContext->isSharedWorkerContext()) in WorkerScriptController::initScript() diff --git a/Source/WebCore/Modules/webaudio/Oscillator.cpp b/Source/WebCore/Modules/webaudio/Oscillator.cpp index 18588a6..ecbd4db 100644 --- a/Source/WebCore/Modules/webaudio/Oscillator.cpp +++ b/Source/WebCore/Modules/webaudio/Oscillator.cpp @@ -42,6 +42,11 @@ namespace WebCore { using namespace VectorMath; +WaveTable* Oscillator::s_waveTableSine = 0; +WaveTable* Oscillator::s_waveTableSquare = 0; +WaveTable* Oscillator::s_waveTableSawtooth = 0; +WaveTable* Oscillator::s_waveTableTriangle = 0; + PassRefPtr Oscillator::create(AudioContext* context, float sampleRate) { return adoptRef(new Oscillator(context, sampleRate)); @@ -78,30 +83,40 @@ Oscillator::~Oscillator() void Oscillator::setType(unsigned short type) { - RefPtr waveTable; + WaveTable* waveTable = 0; float sampleRate = this->sampleRate(); switch (type) { case SINE: - waveTable = WaveTable::createSine(sampleRate); + if (!s_waveTableSine) + s_waveTableSine = WaveTable::createSine(sampleRate).leakRef(); + waveTable = s_waveTableSine; break; case SQUARE: - waveTable = WaveTable::createSquare(sampleRate); + if (!s_waveTableSquare) + s_waveTableSquare = WaveTable::createSquare(sampleRate).leakRef(); + waveTable = s_waveTableSquare; break; case SAWTOOTH: - waveTable = WaveTable::createSawtooth(sampleRate); + if (!s_waveTableSawtooth) + s_waveTableSawtooth = WaveTable::createSawtooth(sampleRate).leakRef(); + waveTable = s_waveTableSawtooth; break; case TRIANGLE: - waveTable = WaveTable::createTriangle(sampleRate); + if (!s_waveTableTriangle) + s_waveTableTriangle = WaveTable::createTriangle(sampleRate).leakRef(); + waveTable = s_waveTableTriangle; break; case CUSTOM: - // FIXME: throw exception since setWaveTable() method must be called explicitly. + default: + // FIXME: throw exception for invalid types or if the type is CUSTOM since setWaveTable() + // method must be called explicitly in that case. return; break; } + setWaveTable(waveTable); m_type = type; - setWaveTable(waveTable.get()); } bool Oscillator::calculateSampleAccuratePhaseIncrements(size_t framesToProcess) diff --git a/Source/WebCore/Modules/webaudio/Oscillator.h b/Source/WebCore/Modules/webaudio/Oscillator.h index 2158a82..127b31b 100644 --- a/Source/WebCore/Modules/webaudio/Oscillator.h +++ b/Source/WebCore/Modules/webaudio/Oscillator.h @@ -99,6 +99,12 @@ private: AudioFloatArray m_detuneValues; RefPtr m_waveTable; + + // Cache the wave tables for different waveform types, except CUSTOM. + static WaveTable* s_waveTableSine; + static WaveTable* s_waveTableSquare; + static WaveTable* s_waveTableSawtooth; + static WaveTable* s_waveTableTriangle; }; } // namespace WebCore -- 1.8.3.1