Showing posts with label web audio api. Show all posts
Showing posts with label web audio api. Show all posts

Wednesday, January 26, 2022

Using the Web Audio API in 2022

draft
  
The good news is that there is a pretty interesting Javascript interface to audio inside HTML 5 that is supported by most browsers.  The bad news is that the documentation is not perfect, it rarely is.  Here is a list of some of the things I learned implementing a web browser based "typewriter"-like interface.
 
1. The abbreviation "mdn" stands for Mozilla Developer Network and is the best place that I have found for documentation on HTML and the Javascript API. So by prefacing any search for information with the letters "mdn" I eliminate most of the extraneous trash.
 
2. Most browsers seem to support the Web Audio API just fine, but you will discover that the browser web page will start muted, with audio disabled. Therefore, you need something like a button the user has to hit to enable audio and you need to check the state of your audio context and possibly "resume" it.
 
3. Not all nodes support start() and stop().

4. Nodes that do support start() and stop() can only be used once.  Therefore you will need to recreate any node for each time you plan to start/stop it.

5. The good news is that this node recreation can be fast, particularly if you are just reusing an audio buffer having previously created it.

6. To use sampled audio (e.g. not an oscillator or a constant), you will need to do the following or equivalent: