News for hackers. Stuff that matters.
Re:WASM SYNTH, or, how music taught me the beauty of math by Weebs on Tuesday May 25, 2021 @02:37PM (#27280543)
Is there a way to supply a PeriodicWave a specific wavetable or series of floating points to represent the wave form? It appears from the docs that PeriodicWave is a way to generate waveforms by shaping sinewaves

One problem I've had in the past trying to do audio on the web is I struggled to find any reference material on how to generate my own waveforms and rely on the browser APIs only for playback. This tutorial, with the AudioWorklet, is the first piece I've seen on how to easily do this.

Re:WASM SYNTH, or, how music taught me the beauty of math by skybrian on Tuesday May 25, 2021 @10:18PM (#27285399)
Oops, I misremembered. For looping a wavetable, you'd want to use AudioBufferSourceNode [1].

If it's a static waveform, you could also do a Fast Fourier Transform and hard-code the resulting table into your program as a Periodic Wave. Apparently, this is how the prefined waveforms of OscillatorNode work. [2]

Generally speaking, you need to read about all the different kinds of nodes that WebAudio gives you and wire them together, sort of like you would with a modular synthesizer. For experimenting with audio synthesis, I'd recommend trying out Rack [3] to figure out what kinds of sounds you want to make, then coding it in JavaScript if you can find equivalent nodes. (Rack is going to have much more capable modules, though.)

[1] https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer... [2] https://webaudio.github.io/web-audio-api/#oscillator-coeffic... [3] https://vcvrack.com/

Re:WASM SYNTH, or, how music taught me the beauty of math by javajosh on Tuesday May 25, 2021 @05:05PM (#27282649)
This probably isn't much help, but if you've got an arbitrary waveform you can do a Fourier transform on it to decompose it into a list of additive sine waves (each wave parameterized by amplitude and frequency, ignoring phase), and then play all those sine waves together to make your sound. I have no idea about the implementation details here (I can imagine that this might get computationally intensive!) but in theory this should work.
Re:WASM SYNTH, or, how music taught me the beauty of math by Weebs on Wednesday May 26, 2021 @02:51PM (#27294548)
If there's a will there's a way :) even if unpractical it's definitely a fun thought!