WebAudio / web-audio-api-v2

The Web Audio API v2.0, developed by the W3C Audio WG
Other
121 stars 11 forks source link

[Feature Request] Extend the `createPeriodicWave` API to accept time-domain arguments. #62

Closed carlsmith closed 3 years ago

carlsmith commented 4 years ago

Please forgive my ignorance here. I'm new to audio synthesis...

WebAudio supports using custom waveforms with oscillator nodes, but the API (createPeriodicWave) only accept arguments defined in the frequency domain (real and imag).

I have periodic waves in the time domain (defined as functions), but without an FFT, there seems to be no way to pass them into an oscillator node. I understand there are a couple of ways to feed arbitrary signals into the routing graph, but this request is about the signature of createPeriodicWave.

There are a few JavaScript libraries online with FFT implementations, but none have been updated for years. I could probably figure it out for myself, or compile some C to WebAssembly or something, but it would obviously be much nicer if createPeriodicWave also accepted time-domain arguments.

More generally, the API could provide FFT and IFFT helpers (especially if they are already implicitly required by the implementation), but even then, the createPeriodicWave method should still be able to understand time-domain arguments.

Again, sorry if I've misunderstood something.

padenot commented 4 years ago

You're looking for AudioBufferSourceNode and its loop, playbakcRate and detune attribute I believe.

In any case, I'm transferring this to the v2 repo, where we're handling feature requests.

carlsmith commented 4 years ago

Thanks, @padenot. I'll look into using AudioBufferSourceNode. Thanks for transferring this. I didn't know about the v2 repo.

carlsmith commented 4 years ago

Sorry. I thought I was closing the issue for the other repo.

rtoy commented 4 years ago

Looping an AudioBufferSourceNode might work, but it will behave differently from a PeriodicWave created from the time-domain data. In particular, setting the frequency and detune will probably produce a nicer waveform, and it will be band-limited. Don't think AudioBufferSourceNode detune will give band-limited signals.

rtoy commented 4 years ago

This would also be a good excuse for providing access to an FFT routine, couching it in terms of creating the necessary arrays to be used for a PeriodicWave. Then, combined with an OscillatorNode and PeriodicWave, you would have access to FFT and IFFT routines, in a roundabout way. :-)

padenot commented 4 years ago

Don't think AudioBufferSourceNode detune will give band-limited signals.

It does in Gecko (at the expense of being slightly slower to compute).

rtoy commented 4 years ago

Teleconf: This can all be done without adding a new feature. It just requires an FFT for which there are lots of libraries out there that would work.

Maybe we can add a small document/wiki page explaining how it can be done.

padenot commented 4 years ago

Virtual F2F:

padenot commented 3 years ago

AudioWG virtual F2F: