Reputation: 129
I'm looking for a javascript code that causes a reverb to an audio file.the audio file is a recorded audio file using html5.I want to be able to add the reverb effect to that file.I tried searching Google for anycode. but could not find or sometimes find something hard to follow if someone can please help
Upvotes: 7
Views: 6945
Reputation: 145
Update December 2015: The <audio> tag in HTML5 does not give you any direct way to change the sound of the source audio file. Therefore, you need to go another level deeper and use the more advanced Web Audio API.
Since there is not just one way to do reverb (there are many room types, algorithms, etc.), the Web Audio API provides support for a convolution node, which is a generalization of reverb-, filter-, and delay- type effects. Convolution allows you to accurately reproduce nearly any space with an impulse response (generally, an audio recording of a percussive sound). Using the convolution node is a little bit tricky to get right, and it still doesn't solve the problem of selecting the specific room you are trying to reproduce.
To make this easier, I've written a reverb wrapper library around the Web Audio API's convolution node called Reverb.js (http://reverbjs.org). The project also hosts a growing number of Creative Commons-licensed impulse responses that you can freely use, or you can use your own. It can also load audio from a Base64 string, so you can entirely embed the impulse response and/or the sound in your HTML document. Finally, an integration example accompanies each impulse response, which makes selecting and using a particular reverb more convenient.
Upvotes: 3
Reputation: 628
There are several libraries on github enabling this:
https://github.com/web-audio-components/simple-reverb
https://github.com/Dinahmoe/tuna
What they eventually do, is using the AudioContext api to create a convolver(which is also an option if you dont want to use the libraries).
The principle is:
1.)Load the file via Ajax, get the response, and use AudioContext.decodeAudioData saved to a variable.
2.)Create an audio context, and instead connecting it straight to .destination, add a a convolver using the .createConvolver()
The audioContext api documentation would help you a lot:
https://developer.mozilla.org/en-US/docs/Web/API/AudioContext.createConvolver
Upvotes: 8