elemaudio / elementary

Elementary is a JavaScript library for digital audio signal processing.
https://www.elementary.audio/
MIT License
331 stars 29 forks source link

Custom Oscillator with Fourier Series/WaveTable #31

Open fastaro opened 11 months ago

fastaro commented 11 months ago

It'd be awesome if there was a feature to allow custom oscillators similar to the web audio api

https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createoscillator

nick-thompson commented 11 months ago

Hey @fastaro I'm sorry for the delay here! I love that idea and I think it should be pretty easy to add. I'll mark it for inclusion as a new feature. I think this is a good opportunity for a first-time contributor too, so I'll add some details on how I envision implementing it and you or anyone else can feel free to pick it up if you get to it before I do!

Generally I think this implementation could look a lot like the existing el.table, so we'd add a new node type in a new file that looks much like Table.h, and instead of taking a property path that looks up a wavetable in the shared resouce map, it should take a property (maybe "coefficients") that provides the real/imag coefficients from which to compute a lookup table. Then can allocate a buffer, build the appropriate lookup table (following the algorithm defined in that spec here: https://webaudio.github.io/web-audio-api/#waveform-generation), and pass the lookup table to the realtime thread to be read from via the incoming phasor. Should be a fun one!