scratch-audio
Advanced tools
Comparing version 0.1.0-prerelease.20180625191752 to 0.1.0-prerelease.20180625194343
{ | ||
"name": "scratch-audio", | ||
"version": "0.1.0-prerelease.20180625191752", | ||
"version": "0.1.0-prerelease.20180625194343", | ||
"description": "audio engine for scratch 3.0", | ||
@@ -5,0 +5,0 @@ "main": "dist.js", |
@@ -112,3 +112,3 @@ const StartAudioContext = require('./StartAudioContext'); | ||
*/ | ||
get DECAY_TIME () { | ||
get DECAY_DURATION () { | ||
return 0.025; | ||
@@ -118,2 +118,13 @@ } | ||
/** | ||
* Some environments cannot smoothly change parameters immediately, provide | ||
* a small delay before decaying. | ||
* | ||
* @see {@link https://bugzilla.mozilla.org/show_bug.cgi?id=1228207} | ||
* @const {number} | ||
*/ | ||
get DECAY_WAIT () { | ||
return 0.05; | ||
} | ||
/** | ||
* Get the input node. | ||
@@ -120,0 +131,0 @@ * @return {AudioNode} - audio node that is the input for this effect |
@@ -147,3 +147,3 @@ /** | ||
if (this._isPatch || this._lastPatch + this.audioEngine.DECAY_TIME < this.audioEngine.currentTime) { | ||
if (this._isPatch || this._lastPatch + this.audioEngine.DECAY_DURATION < this.audioEngine.currentTime) { | ||
this.outputNode.connect(target.getInputNode()); | ||
@@ -150,0 +150,0 @@ } |
@@ -69,12 +69,5 @@ const Effect = require('./Effect'); | ||
this.leftGain.gain.setTargetAtTime( | ||
leftVal, | ||
this.audioEngine.audioContext.currentTime, | ||
this.audioEngine.DECAY_TIME | ||
); | ||
this.rightGain.gain.setTargetAtTime( | ||
rightVal, | ||
this.audioEngine.audioContext.currentTime, | ||
this.audioEngine.DECAY_TIME | ||
); | ||
const {currentTime, DECAY_WAIT, DECAY_DURATION} = this.audioEngine; | ||
this.leftGain.gain.setTargetAtTime(leftVal, currentTime + DECAY_WAIT, DECAY_DURATION); | ||
this.rightGain.gain.setTargetAtTime(rightVal, currentTime + DECAY_WAIT, DECAY_DURATION); | ||
} | ||
@@ -81,0 +74,0 @@ |
@@ -45,5 +45,5 @@ const Effect = require('./Effect'); | ||
const {gain} = this.outputNode; | ||
const {audioContext: {currentTime}, DECAY_TIME} = this.audioEngine; | ||
gain.setValueAtTime(gain.value, currentTime); | ||
gain.linearRampToValueAtTime(value / 100, currentTime + DECAY_TIME); | ||
const {currentTime, DECAY_WAIT, DECAY_DURATION} = this.audioEngine; | ||
gain.setValueAtTime(gain.value, currentTime + DECAY_WAIT); | ||
gain.linearRampToValueAtTime(value / 100, currentTime + DECAY_WAIT + DECAY_DURATION); | ||
} | ||
@@ -50,0 +50,0 @@ |
@@ -101,3 +101,3 @@ const {EventEmitter} = require('events'); | ||
get isStarting () { | ||
return this.isPlaying && this.startingUntil > this.audioEngine.audioContext.currentTime; | ||
return this.isPlaying && this.startingUntil > this.audioEngine.currentTime; | ||
} | ||
@@ -275,3 +275,4 @@ | ||
this.startingUntil = this.audioEngine.audioContext.currentTime + this.audioEngine.DECAY_TIME; | ||
const {currentTime, DECAY_DURATION} = this.audioEngine; | ||
this.startingUntil = currentTime + DECAY_DURATION; | ||
@@ -303,3 +304,4 @@ this.emit('play'); | ||
taken.volumeEffect.set(0); | ||
taken.outputNode.stop(this.audioEngine.audioContext.currentTime + this.audioEngine.DECAY_TIME); | ||
const {currentTime, DECAY_WAIT, DECAY_DURATION} = this.audioEngine; | ||
taken.outputNode.stop(currentTime + DECAY_WAIT + DECAY_DURATION); | ||
} | ||
@@ -306,0 +308,0 @@ |
@@ -23,6 +23,6 @@ /* global Uint8Array Promise */ | ||
audioEngine = new AudioEngine(audioContext); | ||
// sound will be 0.1 seconds long | ||
audioContext.DECODE_AUDIO_DATA_RESULT = audioContext.createBuffer(2, 4410, 44100); | ||
// sound will be 0.2 seconds long | ||
audioContext.DECODE_AUDIO_DATA_RESULT = audioContext.createBuffer(2, 8820, 44100); | ||
audioContext.DECODE_AUDIO_DATA_FAILED = false; | ||
const data = new Uint8Array(44100); | ||
const data = new Uint8Array(0); | ||
return audioEngine.decodeSoundPlayer({data}).then(result => { | ||
@@ -92,3 +92,3 @@ soundPlayer = result; | ||
audioContext.$processTo(audioEngine.DECAY_TIME / 2); | ||
audioContext.$processTo(audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION / 2); | ||
const engineInputs = help.engineInputs; | ||
@@ -99,3 +99,3 @@ t.notEqual(engineInputs[0].gain.value, 1, 'gain value should not be 1'); | ||
audioContext.$processTo(audioEngine.DECAY_TIME); | ||
audioContext.$processTo(audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.001); | ||
t.deepEqual(help.engineInputs, [{ | ||
@@ -135,3 +135,3 @@ name: 'GainNode', | ||
// fast forward to one ms before decay time | ||
audioContext.$processTo(audioEngine.DECAY_TIME - 0.001); | ||
audioContext.$processTo(audioEngine.DECAY_DURATION - 0.001); | ||
soundPlayer.play(); | ||
@@ -142,4 +142,4 @@ | ||
// now at DECAY_TIME, we should meet a new player as the old one is taken/stopped | ||
audioContext.$processTo(audioEngine.DECAY_TIME); | ||
// now at DECAY_DURATION, we should meet a new player as the old one is taken/stopped | ||
audioContext.$processTo(audioEngine.DECAY_DURATION); | ||
@@ -165,3 +165,3 @@ t.equal(soundPlayer.isStarting, false, 'player.isStarting now false'); | ||
// go past debounce time and play again | ||
audioContext.$processTo(audioEngine.DECAY_TIME); | ||
audioContext.$processTo(audioEngine.DECAY_DURATION); | ||
@@ -189,7 +189,8 @@ return Promise.resolve() | ||
audioContext.$processTo(audioContext.currentTime + 0.001); | ||
const {currentTime} = audioContext; | ||
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + 0.001); | ||
t.notEqual(help.engineInputs[0].gain.value, 1, | ||
'old sound connected to gain node which will fade'); | ||
audioContext.$processTo(audioContext.currentTime + audioEngine.DECAY_TIME + 0.001); | ||
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.001); | ||
t.equal(soundPlayer.outputNode.$state, 'PLAYING'); | ||
@@ -201,3 +202,3 @@ t.equal(firstPlayNode.$state, 'FINISHED'); | ||
t.equal(log.length, 1); | ||
audioContext.$processTo(audioContext.currentTime + 0.2); | ||
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.3); | ||
@@ -204,0 +205,0 @@ // wait for a micro-task loop to fire our previous events |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
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
579897
4413