|
|
|
@@ -0,0 +1,49 @@ |
|
|
|
let audioDict = {}; |
|
|
|
|
|
|
|
// play some sound |
|
|
|
|
|
|
|
function playAudio(name) { |
|
|
|
if (audioDict[name] == undefined) { |
|
|
|
console.log(name + " is not loaded yet, dingus"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
let src = audioContext.createBufferSource(); |
|
|
|
|
|
|
|
src.buffer = audioDict[name]; |
|
|
|
|
|
|
|
src.connect(audioContext.destination); |
|
|
|
|
|
|
|
src.start(0); |
|
|
|
} |
|
|
|
|
|
|
|
// asynchronously load an audio file |
|
|
|
|
|
|
|
function loadAudio(name) { |
|
|
|
let xhr = new XMLHttpRequest(); |
|
|
|
|
|
|
|
xhr.open("GET", audioBaseUrl + name, true); |
|
|
|
|
|
|
|
console.log(audioBaseUrl + name); |
|
|
|
xhr.responseType = "arraybuffer"; |
|
|
|
console.log("a"); |
|
|
|
|
|
|
|
xhr.onload = function() { |
|
|
|
let data = xhr.response; |
|
|
|
console.log("FDSEW"); |
|
|
|
|
|
|
|
audioContext.decodeAudioData(data, function(buffer) { |
|
|
|
console.log("SADFDS"); |
|
|
|
audioDict[name] = buffer; |
|
|
|
}, function(e){ console.log("Error with decoding audio data" + e.err);}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
xhr.send(); |
|
|
|
} |
|
|
|
|
|
|
|
function initAudio() { |
|
|
|
audioContext = new (window.AudioContext || window.webkitAudioContext)(); |
|
|
|
|
|
|
|
console.log(audioContext); |
|
|
|
} |