mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 22:12:48 -05:00
loading all sounds on project load
This commit is contained in:
parent
037166dbc9
commit
1f4ef3fd19
1 changed files with 12 additions and 9 deletions
21
src/index.js
21
src/index.js
|
@ -1,7 +1,7 @@
|
||||||
var Tone = require('tone');
|
var Tone = require('tone');
|
||||||
var Soundfont = require('soundfont-player');
|
var Soundfont = require('soundfont-player');
|
||||||
|
|
||||||
function AudioEngine () {
|
function AudioEngine (sounds) {
|
||||||
|
|
||||||
// tone setup
|
// tone setup
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@ function AudioEngine () {
|
||||||
|
|
||||||
// sound urls - map each url to its tone.sampler
|
// sound urls - map each url to its tone.sampler
|
||||||
this.soundSamplers = [];
|
this.soundSamplers = [];
|
||||||
|
this.loadSounds(sounds);
|
||||||
|
|
||||||
// soundfont setup
|
// soundfont setup
|
||||||
|
|
||||||
// instrument names used by Musyng Kite soundfont, in order to
|
// instrument names used by Musyng Kite soundfont, in order to
|
||||||
// match scratch instruments
|
// match scratch instruments
|
||||||
|
@ -42,6 +43,15 @@ function AudioEngine () {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioEngine.prototype.loadSounds = function (sounds) {
|
||||||
|
for (var i=0; i<sounds.length; i++) {
|
||||||
|
var url = sounds[i].fileUrl;
|
||||||
|
var sampler = new Tone.Sampler(url, function () {
|
||||||
|
this.soundSamplers[url] = sampler;
|
||||||
|
}.bind(this)).toMaster();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
AudioEngine.prototype.playSound = function (soundNum) {
|
AudioEngine.prototype.playSound = function (soundNum) {
|
||||||
this.soundSamplers[soundNum].triggerAttack();
|
this.soundSamplers[soundNum].triggerAttack();
|
||||||
};
|
};
|
||||||
|
@ -144,13 +154,6 @@ AudioEngine.prototype.clearEffects = function () {
|
||||||
|
|
||||||
// };
|
// };
|
||||||
|
|
||||||
AudioEngine.prototype.loadSounds = function (sounds) {
|
|
||||||
for (var sound in sounds) {
|
|
||||||
var sampler = new Tone.Sampler(sound.fileUrl).toMaster();
|
|
||||||
this.soundSamplers[sound.fileUrl] = sampler;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
AudioEngine.prototype._clamp = function (input, min, max) {
|
AudioEngine.prototype._clamp = function (input, min, max) {
|
||||||
return Math.min(Math.max(input, min), max);
|
return Math.min(Math.max(input, min), max);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue