Skip to content

Instantly share code, notes, and snippets.

@hikerpig
Created March 13, 2020 09:13
Show Gist options
  • Save hikerpig/8616ddfb2106b8799172e178a2f2f914 to your computer and use it in GitHub Desktop.
Save hikerpig/8616ddfb2106b8799172e178a2f2f914 to your computer and use it in GitHub Desktop.
Web Audio tricks
// copy from https://stackoverflow.com/questions/9874167/how-can-i-play-audio-in-reverse-with-web-audio-api
var context = new AudioContext(),
request = new XMLHttpRequest();
request.open('GET', 'path/to/audio.mp3', true);
request.responseType = 'arraybuffer';
request.addEventListener('load', function(){
context.decodeAudioData(request.response, function(buffer){
var source = context.createBufferSource();
Array.prototype.reverse.call( buffer.getChannelData(0) );
Array.prototype.reverse.call( buffer.getChannelData(1) );
source.buffer = buffer;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment