mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 14:02:29 -05:00
add missing docs: SoundPlayer, AudioEngine, Effect.name
This commit is contained in:
parent
a79684a720
commit
97e2996090
5 changed files with 81 additions and 7 deletions
|
@ -248,12 +248,21 @@ class AudioEngine {
|
|||
log.warn('the createPlayer method is no longer available, please use createBank');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an effect chain.
|
||||
* @returns {EffectChain} chain of effects defined by this AudioEngine
|
||||
*/
|
||||
createEffectChain () {
|
||||
const effects = new EffectChain(this, this.effects);
|
||||
effects.connect(this);
|
||||
return effects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sound bank and effect chain.
|
||||
* @returns {SoundBank} a sound bank configured with an effect chain
|
||||
* defined by this AudioEngine
|
||||
*/
|
||||
createBank () {
|
||||
return new SoundBank(this, this.createEffectChain());
|
||||
}
|
||||
|
|
|
@ -21,23 +21,75 @@ class SoundPlayer extends EventEmitter {
|
|||
constructor (audioEngine, {id, buffer}) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* Unique sound identifier set by AudioEngine.
|
||||
* @type {string}
|
||||
*/
|
||||
this.id = id;
|
||||
|
||||
/**
|
||||
* AudioEngine creating this sound player.
|
||||
* @type {AudioEngine}
|
||||
*/
|
||||
this.audioEngine = audioEngine;
|
||||
|
||||
/**
|
||||
* Decoded audio buffer from audio engine for playback.
|
||||
* @type {AudioBuffer}
|
||||
*/
|
||||
this.buffer = buffer;
|
||||
|
||||
/**
|
||||
* Output audio node.
|
||||
* @type {AudioNode}
|
||||
*/
|
||||
this.outputNode = null;
|
||||
|
||||
/**
|
||||
* VolumeEffect used to fade out playing sounds when stopping them.
|
||||
* @type {VolumeEffect}
|
||||
*/
|
||||
this.volumeEffect = null;
|
||||
|
||||
|
||||
/**
|
||||
* Target engine, effect, or chain this player directly connects to.
|
||||
* @type {AudioEngine|Effect|EffectChain}
|
||||
*/
|
||||
this.target = null;
|
||||
|
||||
/**
|
||||
* Internally is the SoundPlayer initialized with at least its buffer
|
||||
* source node and output node.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.initialized = false;
|
||||
|
||||
/**
|
||||
* Is the sound playing or starting to play?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.isPlaying = false;
|
||||
|
||||
/**
|
||||
* Timestamp sound is expected to be starting playback until. Once the
|
||||
* future timestamp is reached the sound is considered to be playing
|
||||
* through the audio hardware and stopping should fade out instead of
|
||||
* cutting off playback.
|
||||
* @type {number}
|
||||
*/
|
||||
this.startingUntil = 0;
|
||||
|
||||
/**
|
||||
* Rate to play back the audio at.
|
||||
* @type {number}
|
||||
*/
|
||||
this.playbackRate = 1;
|
||||
|
||||
// handleEvent is a EventTarget api for the DOM, however the web-audio-test-api we use
|
||||
// uses an addEventListener that isn't compatable with object and requires us to pass
|
||||
// this bound function instead
|
||||
// handleEvent is a EventTarget api for the DOM, however the
|
||||
// web-audio-test-api we use uses an addEventListener that isn't
|
||||
// compatable with object and requires us to pass this bound function
|
||||
// instead
|
||||
this.handleEvent = this.handleEvent.bind(this);
|
||||
}
|
||||
|
||||
|
@ -232,14 +284,15 @@ class SoundPlayer extends EventEmitter {
|
|||
return;
|
||||
}
|
||||
|
||||
// always do a manual stop on a taken / volume effect fade out sound player
|
||||
// take will emit "stop" as well as reset all of our playing statuses / remove our
|
||||
// nodes / etc
|
||||
// always do a manual stop on a taken / volume effect fade out sound
|
||||
// player take will emit "stop" as well as reset all of our playing
|
||||
// statuses / remove our nodes / etc
|
||||
const taken = this.take();
|
||||
taken.volumeEffect = new VolumeEffect(taken.audioEngine, taken, null);
|
||||
|
||||
taken.volumeEffect.connect(taken.target);
|
||||
// volumeEffect will recursively connect to us if it needs to, so this happens too:
|
||||
// volumeEffect will recursively connect to us if it needs to, so this
|
||||
// happens too:
|
||||
// taken.connect(taken.volumeEffect);
|
||||
|
||||
taken.finished().then(() => taken.dispose());
|
||||
|
|
|
@ -20,6 +20,10 @@ class PanEffect extends Effect {
|
|||
this.channelMerger = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the effect.
|
||||
* @type {string}
|
||||
*/
|
||||
get name () {
|
||||
return 'pan';
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ class PitchEffect extends Effect {
|
|||
this.ratio = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the effect.
|
||||
* @type {string}
|
||||
*/
|
||||
get name () {
|
||||
return 'pitch';
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ class VolumeEffect extends Effect {
|
|||
return 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the effect.
|
||||
* @type {string}
|
||||
*/
|
||||
get name () {
|
||||
return 'volume';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue