var Tone = require('tone'); var Soundfont = require('soundfont-player'); function AudioEngine (sounds) { // tone setup this.tone = new Tone(); // effects setup this.delay = new Tone.FeedbackDelay(0.25, 0.5); this.panner = new Tone.Panner(); this.reverb = new Tone.Freeverb(); this.clearEffects(); Tone.Master.chain(this.delay, this.panner, this.reverb); // drum sounds // var drumFileNames = ['high_conga', 'small_cowbell', // 'snare_drum', 'splash cymbal']; // this.drumSamplers = this._loadSoundFiles(drumFileNames); // sound urls - map each url to its tone.sampler this.soundSamplers = []; this.loadSounds(sounds); // 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, this.instrumentNames[0]).then( function (inst) { this.instrument = inst; this.instrument.connect(Tone.Master); }.bind(this) ); } AudioEngine.prototype.loadSounds = function (sounds) { for (var i=0; i