var log = require('./log'); var Tone = require('tone'); var Soundfont = require('soundfont-player'); function AudioEngine (sounds) { // tone setup this.tone = new Tone(); // effects setup // each effect has a single parameter controlled by the effects block this.delay = new Tone.FeedbackDelay(0.25, 0.5); this.panner = new Tone.Panner(); this.reverb = new Tone.Freeverb(); this.pitchShiftRatio; // the effects are chained to an effects node for this clone, then to the master output // so audio is sent from each player or instrument, through the effects in order, then out // note that the pitch effect works differently - it sets the playback rate for each player this.effectsNode = new Tone.Gain(); this.effectsNode.chain(this.delay, this.panner, this.reverb, Tone.Master); // reset effects to their default parameters // this.clearEffects(); // load sounds this.soundPlayers = []; 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', 'tenor_sax', 'flute', 'pan_flute', 'bassoon', 'choir_aahs', 'vibraphone', 'music_box', 'steel_drums', 'marimba', 'lead_1_square', 'fx_4_atmosphere']; this.setInstrument(0); // theremin setup this.theremin = new Tone.Synth(); this.portamentoTime = 0.25; this.thereminVibrato = new Tone.Vibrato(4, 0.5); this.theremin.chain(this.thereminVibrato, this.effectsNode); this.thereminTimeout; this.thereminIsPlaying = false; } AudioEngine.prototype.loadSounds = function (sounds) { for (var i=0; i