Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoundBank #92

Merged
50 changes: 33 additions & 17 deletions src/AudioEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ const log = require('./log');
const uid = require('./uid');

const ADPCMSoundDecoder = require('./ADPCMSoundDecoder');
const AudioPlayer = require('./AudioPlayer');
const Loudness = require('./Loudness');
const SoundPlayer = require('./GreenPlayer');
const SoundPlayer = require('./SoundPlayer');

const EffectChain = require('./effects/EffectChain');
const PanEffect = require('./effects/PanEffect');
const PitchEffect = require('./effects/PitchEffect');
const VolumeEffect = require('./effects/VolumeEffect');

const SoundBank = require('./SoundBank');

/**
* Wrapper to ensure that audioContext.decodeAudioData is a promise
Expand Down Expand Up @@ -63,6 +69,12 @@ class AudioEngine {
* @type {Loudness}
*/
this.loudness = null;

/**
* Array of effects applied in order, left to right,
* Left is closest to input, Right is closest to output
*/
this.effects = [PanEffect, PitchEffect, VolumeEffect];
}

/**
Expand Down Expand Up @@ -178,27 +190,23 @@ class AudioEngine {

/**
* Retrieve the audio buffer as held in memory for a given sound id.
* @param {!string} soundId - the id of the sound buffer to get
* @return {AudioBuffer} the buffer corresponding to the given sound id.
* @todo remove this
*/
getSoundBuffer (soundId) {
getSoundBuffer () {
// todo: Deprecate audioBuffers. If something wants to hold onto the
// buffer, it should. Otherwise buffers need to be able to release their
// decoded memory to avoid running out of memory which is possible with
// enough large audio buffers as they are full 16bit pcm waveforms for
// each audio channel.
return this.audioBuffers[soundId];
log.warn('The getSoundBuffer function is no longer available. Use soundBank.getSoundPlayer().buffer.');
}

/**
* Add or update the in-memory audio buffer to a new one by soundId.
* @param {!string} soundId - the id of the sound buffer to update.
* @param {AudioBuffer} newBuffer - the new buffer to swap in.
* @return {string} The uid of the sound that was updated or added
* @todo remove this
*/
updateSoundBuffer (soundId, newBuffer) {
this.audioBuffers[soundId] = newBuffer;
return soundId;
updateSoundBuffer () {
log.warn('The updateSoundBuffer function is no longer available. Use soundBank.getSoundPlayer().buffer.');
}

/**
Expand All @@ -225,13 +233,21 @@ class AudioEngine {
}

/**
* Create an AudioPlayer. Each sprite or clone has an AudioPlayer.
* It includes a reference to the AudioEngine so it can use global
* functionality such as playing notes.
* @return {AudioPlayer} new AudioPlayer instance
* Deprecated way to create an AudioPlayer
* @todo remove this
*/
createPlayer () {
return new AudioPlayer(this);
log.warn('the createPlayer method is no longer available, please use createBank');
}

createEffectChain () {
const effects = new EffectChain(this, this.effects);
effects.connect(this);
return effects;
}

createBank () {
return new SoundBank(this, this.createEffectChain());
}
}

Expand Down
152 changes: 0 additions & 152 deletions src/AudioPlayer.js

This file was deleted.

Loading