Changeset 125122 in webkit


Ignore:
Timestamp:
Aug 8, 2012 5:18:23 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Creating "basic waveform" Oscillator nodes is not efficient
https://bugs.webkit.org/show_bug.cgi?id=93194

Patch by Raymond Toy <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.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r125120 r125122  
     12012-08-08  Raymond Toy  <rtoy@google.com>
     2
     3        Creating "basic waveform" Oscillator nodes is not efficient
     4        https://bugs.webkit.org/show_bug.cgi?id=93194
     5
     6        Reviewed by Chris Rogers.
     7
     8        Add test to verify that the returned oscillator type is the same
     9        as what was set.
     10       
     11        * webaudio/oscillator-basic-expected.txt: Added.
     12        * webaudio/oscillator-basic.html: Added.
     13
    1142012-08-08  Tom Sepez  <tsepez@chromium.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r125120 r125122  
     12012-08-08  Raymond Toy  <rtoy@google.com>
     2
     3        Creating "basic waveform" Oscillator nodes is not efficient
     4        https://bugs.webkit.org/show_bug.cgi?id=93194
     5
     6        Reviewed by Chris Rogers.
     7
     8        Cache the wavetables for the basic types so they don't have to be
     9        recomputed every time.
     10
     11        Also fix a bug where oscillator type was always set to CUSTOM
     12        instead of the specified oscillator type.  Test added for this.
     13
     14        Test: webaudio/oscillator-basic.html
     15
     16        * Modules/webaudio/Oscillator.cpp:
     17        (WebCore):
     18        (WebCore::Oscillator::setType): Use cached wavetables; fix bug in
     19        setting the oscillator type.
     20        * Modules/webaudio/Oscillator.h:
     21        (Oscillator): Define static variables to hold cached wavetables.
     22
    1232012-08-08  Tom Sepez  <tsepez@chromium.org>
    224
  • trunk/Source/WebCore/Modules/webaudio/Oscillator.cpp

    r116485 r125122  
    4343using namespace VectorMath;
    4444
     45WaveTable* Oscillator::s_waveTableSine = 0;
     46WaveTable* Oscillator::s_waveTableSquare = 0;
     47WaveTable* Oscillator::s_waveTableSawtooth = 0;
     48WaveTable* Oscillator::s_waveTableTriangle = 0;
     49
    4550PassRefPtr<Oscillator> Oscillator::create(AudioContext* context, float sampleRate)
    4651{
     
    7984void Oscillator::setType(unsigned short type)
    8085{
    81     RefPtr<WaveTable> waveTable;
     86    WaveTable* waveTable = 0;
    8287    float sampleRate = this->sampleRate();
    8388
    8489    switch (type) {
    8590    case SINE:
    86         waveTable = WaveTable::createSine(sampleRate);
     91        if (!s_waveTableSine)
     92            s_waveTableSine = WaveTable::createSine(sampleRate).leakRef();
     93        waveTable = s_waveTableSine;
    8794        break;
    8895    case SQUARE:
    89         waveTable = WaveTable::createSquare(sampleRate);
     96        if (!s_waveTableSquare)
     97            s_waveTableSquare = WaveTable::createSquare(sampleRate).leakRef();
     98        waveTable = s_waveTableSquare;
    9099        break;
    91100    case SAWTOOTH:
    92         waveTable = WaveTable::createSawtooth(sampleRate);
     101        if (!s_waveTableSawtooth)
     102            s_waveTableSawtooth = WaveTable::createSawtooth(sampleRate).leakRef();
     103        waveTable = s_waveTableSawtooth;
    93104        break;
    94105    case TRIANGLE:
    95         waveTable = WaveTable::createTriangle(sampleRate);
     106        if (!s_waveTableTriangle)
     107            s_waveTableTriangle = WaveTable::createTriangle(sampleRate).leakRef();
     108        waveTable = s_waveTableTriangle;
    96109        break;
    97110    case CUSTOM:
    98         // FIXME: throw exception since setWaveTable() method must be called explicitly.
    99         return;
    100         break;
    101     }
    102 
     111    default:
     112        // FIXME: throw exception for invalid types or if the type is CUSTOM since setWaveTable()
     113        // method must be called explicitly in that case.
     114        return;
     115        break;
     116    }
     117
     118    setWaveTable(waveTable);
    103119    m_type = type;
    104     setWaveTable(waveTable.get());
    105120}
    106121
  • trunk/Source/WebCore/Modules/webaudio/Oscillator.h

    r116201 r125122  
    100100   
    101101    RefPtr<WaveTable> m_waveTable;
     102
     103    // Cache the wave tables for different waveform types, except CUSTOM.
     104    static WaveTable* s_waveTableSine;
     105    static WaveTable* s_waveTableSquare;
     106    static WaveTable* s_waveTableSawtooth;
     107    static WaveTable* s_waveTableTriangle;
    102108};
    103109
Note: See TracChangeset for help on using the changeset viewer.