Loading audio files
- uses
AudioBufferfor short to medium-length sounds XMLHttpRequestis used to fetch sound files- audio files can be in any format supported by the
audioelement (eg. wav, mp3, aac, varies on different browsers as well) var request = new XMLHttpRequest();request.open('GET', url, true);request.responseType = 'arraybuffer';- as audio file data is binary,responseTypeis set toarraybuffer
Decoding audio files
decodeAudioData- decodes audio file data contained in
ArrayBuffer, loaded from an XMLHttpRequestrequest.responseattribute audioData: ArrayButter containing audio file datasuccessCallbackis invoked when decoding is finished, representing the decoded PCM audio dataerrorCallbackis invoked if there is an erro decoding the audio file data- decoded PCM audio data is represented as an
AudioBuffer - asynchronously decodes the audio file
Playing sounds
playSound()- called every time a key is pressed or mouse is clickedstart(time)- function to schedule precise sound playback for games and applications
ArrayBuffer
- a generic fixed-length container for binary data (bytes)
Codec support
-
audio coding formats supported by the
audioelement, on various browsers - Google Chrome: ogg, vorbis, wav, pcm, mp3, aac, opus
- Internet Explorer: mp3, aac
- Mozilla Firefox: ogg, vorbis, wav, pcm, mp3, aac, opus
- Opera: ogg, vorbis, wav, pcm, mp3, aac, opus
- Safari: wav, pcm, mp3, aac
One-shot behaviour
- an
AudioBufferSourceNodeacts one-shot, only executes once when called - create new one once it has been
.start()and.stop()
LINKS: