| @@ -1,5 +1,6 @@ | |||||
| let playing = []; | let playing = []; | ||||
| let looping = {}; | let looping = {}; | ||||
| let loopGains = {}; | |||||
| let waiting = {}; | let waiting = {}; | ||||
| @@ -45,8 +46,8 @@ function playSfx(name) { | |||||
| src.start(0); | src.start(0); | ||||
| } | } | ||||
| function playLoop(name) { | |||||
| if (audioDict[name] == undefined) { | |||||
| function playLoop(name, volume=1) { | |||||
| if (audioDict[name] === undefined) { | |||||
| if (waiting[name]) { | if (waiting[name]) { | ||||
| waiting[name].push({ | waiting[name].push({ | ||||
| @@ -59,6 +60,8 @@ function playLoop(name) { | |||||
| console.error(name + " is not loaded yet, dingus"); | console.error(name + " is not loaded yet, dingus"); | ||||
| return; | return; | ||||
| } | } | ||||
| loopGains[name].gain.value = volume; | |||||
| // if already playing, just keep going | // if already playing, just keep going | ||||
| if (looping[name] && !looping[name].done) { | if (looping[name] && !looping[name].done) { | ||||
| @@ -68,7 +71,8 @@ function playLoop(name) { | |||||
| let src = audioContext.createBufferSource(); | let src = audioContext.createBufferSource(); | ||||
| src.buffer = audioDict[name]; | src.buffer = audioDict[name]; | ||||
| src.connect(gainControl); | |||||
| src.connect(loopGains[name]); | |||||
| loopGains[name].connect(gainControl); | |||||
| looping[name] = src; | looping[name] = src; | ||||
| @@ -132,6 +136,8 @@ function loadAudio(name, flush=false) { | |||||
| return; | return; | ||||
| } | } | ||||
| loopGains[name] = audioContext.createGain(); | |||||
| waiting[name] = []; | waiting[name] = []; | ||||
| // is the audio already stored locally? | // is the audio already stored locally? | ||||