working on sound font player

This commit is contained in:
Eric Rosenbaum committed 2016-10-04 14:19:04 -04:00
1 parent 086dd35329
commit 0db0783fe8
3 files changed
+10 -10

No files matched your search

+8 -7
View File
@@ -2,6 +2,10 @@ function AudioEngine () {
// soundfont setup
// instrument names used by Musyng Kite soundfont, in order to match scratch instruments
this.instrumentNames = ['acoustic_grand_piano', 'electric_piano_1', 'drawbar_organ', 'acoustic_guitar_nylon',
'electric_guitar_clean', 'acoustic_bass', 'pizzicato_strings', 'cello', 'trombone', 'clarinet'];
Soundfont.instrument(Tone.context, 'acoustic_grand_piano').then(function (piano) {
this.instrument = piano;
}.bind(this));
@@ -29,11 +33,6 @@ function AudioEngine () {
var drumFileNames = ['high_conga', 'small_cowbell', 'snare_drum', 'splash cymbal'];
this.drumSamplers = this._loadSoundFiles(drumFileNames);
// sound files
// var soundFileNames = ['meow','boing','cave','drip_drop','drum_machine','eggs','zoop'];
// this.soundSamplers = this._loadSoundFiles(soundFileNames);
// sound urls - map each url to its tone.sampler
this.soundSamplers = [];
}
@@ -63,8 +62,10 @@ AudioEngine.prototype.getSoundDuration = function (soundNum) {
};
AudioEngine.prototype.playNoteForBeats = function(note, beats) {
this.instrument.start(note, Tone.context.currentTime, beats); // duration not working
// this.instrument.play(note).stop(Tone.context.currentTime+beats);
};
AudioEngine.prototype.playNoteForBeats = function(note, beats) {
this.instrument.play(note, Tone.context.currentTime, {duration : Number(beats)});
};
AudioEngine.prototype.playDrumForBeats = function(drumNum, beats) {
+1 -1
View File
@@ -48,7 +48,7 @@ Scratch3SoundBlocks.prototype._getSoundUrl = function (soundName, util) {
return '';
}
}
return util.target.sprite.sounds[index].soundFile;
return util.target.sprite.sounds[index].fileUrl;
};
+1 -2
View File
@@ -68,7 +68,7 @@ function parseScratchObject (object, runtime, topLevel) {
var sound = object.sounds[i];
sprite.sounds.push({
format: sound.format,
soundFile: 'https://cdn.assets.scratch.mit.edu/internalapi/asset/'
fileUrl: 'https://cdn.assets.scratch.mit.edu/internalapi/asset/'
+ sound.md5 + '/get/',
rate: sound.rate,
sampleCount: sound.sampleCount,
@@ -76,7 +76,6 @@ function parseScratchObject (object, runtime, topLevel) {
name: sound.soundName
});
}
console.log(sprite.sounds);
}
// If included, parse any and all scripts/blocks on the object.
if (object.hasOwnProperty('scripts')) {