fix sound loading

This commit is contained in:
Eric Rosenbaum 2016-10-17 15:41:56 -04:00
parent 7fb9551a1e
commit 67d805909b

View file

@ -46,35 +46,17 @@ function AudioEngine (sounds) {
AudioEngine.prototype.loadSounds = function (sounds) { AudioEngine.prototype.loadSounds = function (sounds) {
for (var i=0; i<sounds.length; i++) { for (var i=0; i<sounds.length; i++) {
var url = sounds[i].fileUrl; var url = sounds[i].fileUrl;
var sampler = new Tone.Sampler(url, function () { var sampler = new Tone.Sampler(url).toMaster();
this.soundSamplers[url] = sampler; this.soundSamplers.push(sampler);
}.bind(this)).toMaster();
} }
}; };
AudioEngine.prototype.playSound = function (soundNum) { AudioEngine.prototype.playSound = function (index) {
this.soundSamplers[soundNum].triggerAttack(); this.soundSamplers[index].triggerAttack();
}; };
AudioEngine.prototype.playSoundFromUrl = function (url) { AudioEngine.prototype.getSoundDuration = function (index) {
if (url) { return this.soundSamplers[index].player.buffer.duration;
// if we've loaded it already, play it
if (this.soundSamplers[url]) {
// this.soundSamplers[url].triggerAttack();
this.soundSamplers[url].player.start();
} else {
// else load, play, and store it
// this results in a delay the first time you play the sound
var sampler = new Tone.Sampler(url, function () {
sampler.triggerAttack();
this.soundSamplers[url] = sampler;
}.bind(this)).toMaster();
}
}
};
AudioEngine.prototype.getSoundDuration = function (url) {
return this.soundSamplers[url].player.buffer.duration;
}; };
AudioEngine.prototype.playNoteForBeats = function (note, beats) { AudioEngine.prototype.playNoteForBeats = function (note, beats) {
@ -132,7 +114,6 @@ AudioEngine.prototype.changeEffect = function (effect, value) {
this.reverb.wet.value = this._clamp(this.reverb.wet.value, 0, 1); this.reverb.wet.value = this._clamp(this.reverb.wet.value, 0, 1);
break; break;
case 'PITCH': case 'PITCH':
// this.pitchShift.pitch += value / 20;
break; break;
} }
}; };