scratch-audioengine
Advanced tools
Comparing version 0.1.0-prerelease.1479583259 to 0.1.0-prerelease.1479762203
{ | ||
"name": "scratch-audioengine", | ||
"version": "0.1.0-prerelease.1479583259", | ||
"version": "0.1.0-prerelease.1479762203", | ||
"description": "audio engine for scratch 3.0", | ||
@@ -5,0 +5,0 @@ "main": "dist.js", |
var log = require('./log'); | ||
var Tone = require('tone'); | ||
// var Soundfont = require('soundfont-player'); | ||
var SoundPlayer = require('./SoundPlayer'); | ||
var Soundfont = require('soundfont-player'); | ||
var Vocoder = require('./vocoder'); | ||
@@ -30,3 +31,3 @@ var ADPCMSoundLoader = require('./ADPCMSoundLoader'); | ||
// telephone effect - simulating the 'tinny' sound coming over a phone line | ||
// basically, a lowpass filter and a highpass filter | ||
// using a lowpass filter and a highpass filter | ||
this.telephone = new Tone.Effect(); | ||
@@ -90,6 +91,3 @@ var telephoneLP = new Tone.Filter(1200, 'lowpass', -24); | ||
for (var i=0; i<sounds.length; i++){ | ||
var player = {}; | ||
player.buffer = null; | ||
player.bufferSource = null; | ||
this.soundPlayers[i] = player; | ||
this.soundPlayers[i] = new SoundPlayer(this.effectsNode); | ||
} | ||
@@ -103,3 +101,3 @@ | ||
log.warn('attempting to load sound in adpcm format'); | ||
// create a closure to the sound index, to use when the | ||
// create a closure to store the sound index, to use when the | ||
// docder completes and resolves the promise | ||
@@ -110,7 +108,7 @@ (function () { | ||
loader.load(sounds[storedIndex].fileUrl).then(function (audioBuffer) { | ||
storedContext.soundPlayers[storedIndex].buffer = new Tone.Buffer(audioBuffer); | ||
storedContext.soundPlayers[storedIndex].setBuffer(new Tone.Buffer(audioBuffer)); | ||
}); | ||
}()); | ||
} else { | ||
this.soundPlayers[index].buffer = new Tone.Buffer(sounds[index].fileUrl); | ||
this.soundPlayers[index].setBuffer(new Tone.Buffer(sounds[index].fileUrl)); | ||
} | ||
@@ -122,29 +120,16 @@ | ||
AudioEngine.prototype.playSound = function (index) { | ||
// if the soundplayer exists and its buffer has loaded | ||
if (this.soundPlayers[index].buffer && this.soundPlayers[index].buffer.loaded) { | ||
// stop the sound if it's already playing | ||
var b = this.soundPlayers[index].bufferSource; | ||
if (b) { | ||
b.stop(); | ||
} | ||
// create a new buffer source to play the sound | ||
var bufferSource = new Tone.BufferSource(this.soundPlayers[index].buffer.get()); | ||
bufferSource.connect(this.effectsNode); | ||
bufferSource.start(); | ||
bufferSource.playbackRate.value = this._getPitchRatio(); | ||
this.soundPlayers[index].bufferSource = bufferSource; | ||
this.soundPlayers[index].start(); | ||
return new Promise(function (resolve) { | ||
// bufferSource.onended = resolve; // this works, but causes the block to display a | ||
// blocklydropdowncontent that says 'BufferSource' | ||
bufferSource.onended = function (){resolve();}; | ||
}); | ||
} | ||
var storedContext = this; | ||
return new Promise(function (resolve) { | ||
storedContext.soundPlayers[index].onEnded(resolve); | ||
}); | ||
}; | ||
AudioEngine.prototype.playNoteForBeats = function (note, beats) { | ||
// this.instrument.play( | ||
// note, Tone.context.currentTime, {duration : Number(beats)} | ||
// ); | ||
this.instrument.play( | ||
note, Tone.context.currentTime, {duration : Number(beats)} | ||
); | ||
/* | ||
// if the soundplayer exists and its buffer has loaded | ||
@@ -164,4 +149,4 @@ if (this.soundPlayers[this.instrumentNum] && this.soundPlayers[this.instrumentNum].buffer.loaded) { | ||
}); | ||
} | ||
*/ | ||
}; | ||
@@ -207,11 +192,8 @@ | ||
// } | ||
// stop sounds triggered with playSound | ||
if (this.soundPlayers && this.soundPlayers.length > 0) { | ||
for (var i=0; i<this.soundPlayers.length; i++) { | ||
var bufferSource = this.soundPlayers[i].bufferSource; | ||
if (bufferSource) { | ||
bufferSource.stop(); | ||
} | ||
} | ||
for (var i=0; i<this.soundPlayers.length; i++) { | ||
this.soundPlayers[i].stop(); | ||
} | ||
// stop soundfont notes | ||
@@ -298,2 +280,3 @@ if (this.instrument) { | ||
} | ||
var ratio = this._getPitchRatio(); | ||
@@ -306,6 +289,3 @@ this._setPlaybackRateForAllSoundPlayers(ratio); | ||
for (var i=0; i<this.soundPlayers.length; i++) { | ||
var s = this.soundPlayers[i].bufferSource; | ||
if (s && s.playbackRate) { | ||
s.playbackRate.value = rate; | ||
} | ||
this.soundPlayers[i].setPlaybackRate(rate); | ||
} | ||
@@ -320,3 +300,3 @@ }; | ||
this.instrumentNum = instrumentNum; | ||
/* | ||
return Soundfont.instrument(Tone.context, this.instrumentNames[instrumentNum]).then( | ||
@@ -328,3 +308,2 @@ function (inst) { | ||
); | ||
*/ | ||
}; | ||
@@ -331,0 +310,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
861972
20
24790
3
1