Can I play synthesized sound in a browser using JavaScript?

I just stumbled upon a Nintendo emulator, fully written in JavaScript on interfaces, but it has no sound. This made me wonder: is there a way to synthesize sound in a browser using JavaScript and then play it? If this is not possible at all, then is there Safari / Opera / FireFox / IE / Etc. extensions that would allow this to be done?

I am not asking about sound synthesis methods, just about the methods of reproducing sounds that were synthesized using code running in a browser.

+4
source share
4 answers

I would suggest that it is best for Javascript to talk to Flash using ExternalInterface ( http://www.adobe.com/devnet/flash/articles/external_interface.html ). Flash now has a way to transfer data between sound buffers and general-purpose ByteArray classes.

http://www.adobe.com/devnet/flash/articles/dynamic_sound_generation/

You can develop Flash for free using the Flex SDK http://www.adobe.com/products/flex/ .

+3
source

Most developers use SoundManager 2 when they want to add sound to their application using JavaScript. It has hooks, so JavaScript can interact with the functions of Flash 8 and 9. I'm not sure if it has detected the ability to work with Byte Data, which, I think, after that, I never had to deal with this.

+2
source

It turns out that the author of the NES emulator found a dynamic audio library:

https://github.com/bfirsh/dynamicaudio.js

I haven't tried it, but the docs look promising:

var dynamicaudio = new DynamicAudio ({'swf': '/static/dynamicaudio.swf'})

record (samples); // Play an array of samples of audio with floating point in the range from -1.0 to 1.0.

+2
source

In theory, it should be possible to synthesize sounds and then make the browser play them using the data URL.

In practice, Stephen Wittens actually produced a demo of this technique. The functions encodeAudio8bit and encodeAudio16bit are where magic happens.

+1
source

All Articles