LabSound / LabSound

:microscope: :speaker: graph-based audio engine

Home Page:http://labsound.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rename Oscillator waveTable to match updated periodicWave API

dug9 opened this issue · comments

commented

Web3d.org v4 standard was designed around web audio standard.
https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-DIS/Part01/components/sound.html#PeriodicWave
Web Audio shows context has a createPeriodicWave function taking 2 float arrays (imag, real) and generates a 'wave' which can then be set in Oscillator for type CUSTOM.
https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode/setPeriodicWave
I don't see that in LabSound.
I see something in LabSound called WaveTable, but I don't see an example of it being used.
Is there a way to apply WaveTable to Oscillator that is equivalent to web audio createPeriodicWave /setPeriodicWave?
Thanks

LabSound has been around for a while. AFAIK PeriodicWave wasn't in WebKit at the time the original fork was made. I think, but am not sure, that PeriodicWave and WaveTable share an underlying basic concept.

here's an example of a wavetable synth. https://github.com/cwilso/web-audio-samples/blob/master/samples/audio/wavetable-synth.html (also https://github.com/GoogleChromeLabs/web-audio-samples/tree/main/src/demos/wavetable-synth) I haven't attempted porting it.
...
Ahhhh ~ WebKit/WebKit@593971c ~ WaveTable was renamed to PeriodicWave. ~ https://dvcs.w3.org/hg/audio/rev/7c4a40a9bb57

So we should do the same change as indicated in https://dvcs.w3.org/hg/audio/rev/7c4a40a9bb57 to modernize the implementation. That seems straight forward.

I renamed the issue to reflect the work that needs to be done.

The rename is complete. However, the CUSTOM oscillator type is meant to be used with PeriodicWave. The implementation of this oscillator type needs to be created.

From this code here https://github.com/WebKit/WebKit/blob/main/Source/WebCore/Modules/webaudio/OscillatorNode.cpp we can see how the PeriodicWave is meant to generate samples according to

    if (!hasSampleAccurateValues) {
        frequency = m_frequency->finalValue();
        float detune = m_detune->finalValue();
        float detuneScale = detuneToFrequencyMultiplier(detune);
        frequency *= detuneScale;
        clampFrequency(&frequency, 1, context().sampleRate() / 2);
        m_periodicWave->waveDataForFundamentalFrequency(frequency, lowerWaveData, higherWaveData, tableInterpolationFactor);
    }

so implementing this missing feature should be straight forward.

Here is an example of modulating a periodicWave to create a siren effect. we should add it to the test-examples.

https://gist.github.com/slv/631074e032731a84c0f5

commented

I tried implementing oscillatorNode.setPeriodicWave(pwave) but its a bit too much for me especially the labsound vs webkit plumbing. I have #define METHODB and regular waveforms still work with the webkit method. But setPeriodicWave bombs and the call stack is weird, seeming to cycle back through .setType -- what seems to b
custom_oscillator.zip
e labsound plumbing.

I can have a look in the next few days, thanks for having a go.