はじめての Web Audio API
Eiji Kitamura (Google Developer Advocate)
HTML5 とか勉強会 #24
December 26, 2011
http://slides.agektmr.com/webaudio_basic/
Eiji Kitamura (Google Developer Advocate)
HTML5 とか勉強会 #24
December 26, 2011
http://slides.agektmr.com/webaudio_basic/



var c = new webkitAudioContext(); var source = c.createBufferSource(); // BufferSourceNode を生成 source.buffer = buffer; // 予め読み込んでおいたオーディオファイル source.connect(c.destination); // ノードを接続 source.noteOn(0); // 音声を再生
var g = c.createGainNode(); // GainNode を生成 g.gain.value = 0.5; // ボリュームを半分にする source.connect(g); // 音源を GainNode に接続 g.connect(c.destination); // GainNodeを出力に接続
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer'; // バイナリとして読み込む
// 読み込んだオーディオを非同期にデコード
xhr.onload = function() {
context.decodeAudioData(xhr.response, function(buffer) {
dogBarkingBuffer = buffer;
}, onError);
}
xhr.send();