Skip to content

Commit

Permalink
Merge pull request #92 from gnarf/soundbank-effectchain
Browse files Browse the repository at this point in the history
SoundBank
  • Loading branch information
mzgoddard committed Jun 21, 2018
2 parents 2126761 + 669ac5f commit 98eb914
Show file tree
Hide file tree
Showing 10 changed files with 624 additions and 489 deletions.
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

0 comments on commit 98eb914

Please sign in to comment.