Pro Yearly is on sale from $80 to $50! »

WebAudio

 WebAudio

GET EXCITED AND PLAY!!

7b1746f5ae99453e6a67f022ec0d73bd?s=128

Tiffany Conroy

October 01, 2012
Tweet

Transcript

  1. WEBAUDIO

  2. WebAudio != <audio … >

  3. // create new <audio> var audioElement = new Audio();

  4. // create new WebAudio Context var context = new audioContext();

  5. // create new WebAudio Context var context = new webkitAudioContext();

  6. WICKED WEBAUDIO DEMOS http://chromium.googlecode.com/svn/trunk/samples/audio/samples.html

  7. PLAY

  8. audioElement.src = path // check/wait until you can play audioElement.play();

  9. var source = context.createBufferSource(); source.buffer = buffer; source.connect(context.destination); source.noteOn(at); //

    PLAY
  10. var source = context.createBufferSource(); source.buffer = buffer; source.connect(context.destination); source.noteOn(at); //

    PLAY
  11. var source = context.createBufferSource(); source.buffer = buffer; source.connect(context.destination); source.noteOn(at); //

    PLAY
  12. $.ajax({ url: "/path/to/my/sound/file", success: decodeAudioData, requestType: "arraybuffer" });

  13. $.ajax({ url: "/path/to/my/sound/file", success: decodeAudioData, requestType: "arraybuffer" }); NOPE

  14. var request = new XMLHttpRequest(); request.open("GET", "/path/to/sound"); request.responseType = "arraybuffer";

    request.onload = decodeAudioData; request.send();
  15. var request = new XMLHttpRequest(); request.open("GET", "/path/to/sound"); request.responseType = "arraybuffer";

    request.onload = decodeAudioData; request.send();
  16. var decodeAudioData = function() { context.decodeAudioData( request.response, decodeSuccess); };

  17. var decodeSuccess = function(buffer) { doSomething(buffer); };

  18. var decodeSuccess = function(buffer) { doSomething(buffer); };

  19. var decodeSuccess = function(buffer) { doSomething(buffer); };

  20. I MADE SOME FUNCTIONS github.com/theophani/load-sounds

  21. var loadSound = function(path, callback) { // load the sound

    sorta like I showed before };
  22. var loadSounds = function(paths, callback) { // load a bunch

    of sounds };
  23. var playSound = function(buffer) { // stuff with source and

    context };
  24. Tiffany Conroy github.com/theophani/load-sounds @theophani