add missing docs: SoundPlayer, AudioEngine, Effect.name

This commit is contained in:
Michael "Z" Goddard 2018-06-22 14:43:37 -04:00
parent a79684a720
commit 97e2996090
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
5 changed files with 81 additions and 7 deletions

View file

@ -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());
}

View file

@ -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());

View file

@ -20,6 +20,10 @@ class PanEffect extends Effect {
this.channelMerger = null;
}
/**
* Return the name of the effect.
* @type {string}
*/
get name () {
return 'pan';
}

View file

@ -35,6 +35,10 @@ class PitchEffect extends Effect {
this.ratio = 1;
}
/**
* Return the name of the effect.
* @type {string}
*/
get name () {
return 'pitch';
}

View file

@ -12,6 +12,10 @@ class VolumeEffect extends Effect {
return 100;
}
/**
* Return the name of the effect.
* @type {string}
*/
get name () {
return 'volume';
}