scratch-audio
Advanced tools
Comparing version 0.1.0-prerelease.1511362862 to 0.1.0-prerelease.1513803406
{ | ||
"name": "scratch-audio", | ||
"version": "0.1.0-prerelease.1511362862", | ||
"version": "0.1.0-prerelease.1513803406", | ||
"description": "audio engine for scratch 3.0", | ||
@@ -5,0 +5,0 @@ "main": "dist.js", |
@@ -8,7 +8,8 @@ /** | ||
/** | ||
* @param {AudioContext} audioContext - a webAudio context | ||
* @param {AudioEngine} audioEngine - the audio engine. | ||
* @constructor | ||
*/ | ||
constructor (audioContext) { | ||
this.audioContext = audioContext; | ||
constructor (audioEngine) { | ||
this.audioEngine = audioEngine; | ||
this.audioContext = this.audioEngine.audioContext; | ||
this.value = 0; | ||
@@ -41,4 +42,7 @@ | ||
// See e.g. https://docs.cycling74.com/max7/tutorials/13_panningchapter01 | ||
this.leftGain.gain.value = Math.cos(p * Math.PI / 2); | ||
this.rightGain.gain.value = Math.sin(p * Math.PI / 2); | ||
const leftVal = Math.cos(p * Math.PI / 2); | ||
const rightVal = Math.sin(p * Math.PI / 2); | ||
this.leftGain.gain.setTargetAtTime(leftVal, 0, this.audioEngine.DECAY_TIME); | ||
this.rightGain.gain.setTargetAtTime(rightVal, 0, this.audioEngine.DECAY_TIME); | ||
} | ||
@@ -45,0 +49,0 @@ |
@@ -31,3 +31,3 @@ const StartAudioContext = require('startaudiocontext'); | ||
this.pitchEffect = new PitchEffect(); | ||
this.panEffect = new PanEffect(this.audioEngine.audioContext); | ||
this.panEffect = new PanEffect(this.audioEngine); | ||
@@ -125,3 +125,4 @@ // Chain the audio effects together | ||
this.pitchEffect.set(0, this.activeSoundPlayers); | ||
this.effectsNode.gain.value = 1; | ||
if (this.audioEngine === null) return; | ||
this.effectsNode.gain.setTargetAtTime(1.0, 0, this.audioEngine.DECAY_TIME); | ||
} | ||
@@ -134,3 +135,4 @@ | ||
setVolume (value) { | ||
this.effectsNode.gain.value = value / 100; | ||
if (this.audioEngine === null) return; | ||
this.effectsNode.gain.setTargetAtTime(value / 100, 0, this.audioEngine.DECAY_TIME); | ||
} | ||
@@ -171,2 +173,12 @@ } | ||
/** | ||
* A short duration, for use as a time constant for exponential audio parameter transitions. | ||
* See: | ||
* https://developer.mozilla.org/en-US/docs/Web/API/AudioParam/setTargetAtTime | ||
* @const {number} | ||
*/ | ||
get DECAY_TIME () { | ||
return 0.001; | ||
} | ||
/** | ||
* Decode a sound, decompressing it into audio samples. | ||
@@ -173,0 +185,0 @@ * Store a reference to it the sound in the audioBuffers dictionary, indexed by soundId |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
487861
2452