Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Oscillator waveTable to match updated periodicWave API #180

Open
dug9 opened this issue Jan 25, 2023 · 6 comments
Open

Rename Oscillator waveTable to match updated periodicWave API #180

dug9 opened this issue Jan 25, 2023 · 6 comments

Comments

@dug9
Copy link
Contributor

dug9 commented Jan 25, 2023

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

@dug9 dug9 changed the title OscillatorSource.setPeriodicWave() missing? Oscillator.setPeriodicWave() missing? Jan 25, 2023
@meshula
Copy link
Member

meshula commented Jan 31, 2023

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.

@meshula meshula changed the title Oscillator.setPeriodicWave() missing? Rename Oscillator waveTable to match updated periodicWave API Jan 31, 2023
@meshula meshula self-assigned this Jan 31, 2023
@meshula
Copy link
Member

meshula commented Jan 31, 2023

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

@meshula
Copy link
Member

meshula commented Feb 6, 2023

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.

@meshula
Copy link
Member

meshula commented Feb 6, 2023

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

@meshula meshula added v1.3 and removed v1.2 labels Feb 6, 2023
@dug9
Copy link
Contributor Author

dug9 commented Apr 10, 2023

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.

@meshula
Copy link
Member

meshula commented Apr 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants