Skip to content

Instantly share code, notes, and snippets.

@72lions
Created January 14, 2013 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 72lions/4528848 to your computer and use it in GitHub Desktop.
Save 72lions/4528848 to your computer and use it in GitHub Desktop.
Replaces the AudioBuffer of an AudioSource
// Adding a bit of scheduling so that we won't have single digit milisecond overlaps.
// Thanks to Chris Wilson for his suggestion.
var scheduledTime = 0.015;
try {
_audioSource.stop(scheduledTime);
} catch (e) {}
_audioSource = _context.createBufferSource();
_audioSource.buffer = _audioBuffer;
_audioSource.connect(_analyser);
_audioSource.connect(_context.destination);
var currentTime = _context.currentTime + 0.010 || 0;
_audioSource.start(scheduledTime - 0.005, currentTime, _audioBuffer.duration - currentTime);
_audioSource.playbackRate.value = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment