chore: lint fixes

This commit is contained in:
Christopher Willis-Ford 2023-12-15 14:44:01 -08:00
parent bcfd307e9b
commit 068aca6136
8 changed files with 47 additions and 48 deletions

View file

@ -89,7 +89,7 @@ class ADPCMSoundDecoder {
* Decode an ADPCM sound stored in an ArrayBuffer and return a promise * Decode an ADPCM sound stored in an ArrayBuffer and return a promise
* with the decoded audio buffer. * with the decoded audio buffer.
* @param {ArrayBuffer} audioData - containing ADPCM encoded wav audio * @param {ArrayBuffer} audioData - containing ADPCM encoded wav audio
* @return {AudioBuffer} the decoded audio buffer * @return {Promise.<AudioBuffer>} the decoded audio buffer
*/ */
decode (audioData) { decode (audioData) {
@ -99,7 +99,7 @@ class ADPCMSoundDecoder {
const riffStr = stream.readUint8String(4); const riffStr = stream.readUint8String(4);
if (riffStr !== 'RIFF') { if (riffStr !== 'RIFF') {
log.warn('incorrect adpcm wav header'); log.warn('incorrect adpcm wav header');
reject(); reject(new Error('incorrect adpcm wav header'));
} }
const lengthInHeader = stream.readInt32(); const lengthInHeader = stream.readInt32();
@ -110,7 +110,7 @@ class ADPCMSoundDecoder {
const wavStr = stream.readUint8String(4); const wavStr = stream.readUint8String(4);
if (wavStr !== 'WAVE') { if (wavStr !== 'WAVE') {
log.warn('incorrect adpcm wav header'); log.warn('incorrect adpcm wav header');
reject(); reject(new Error('incorrect adpcm wav header'));
} }
const formatChunk = this.extractChunk('fmt ', stream); const formatChunk = this.extractChunk('fmt ', stream);
@ -120,7 +120,7 @@ class ADPCMSoundDecoder {
this.bytesPerSecond = formatChunk.readUint32(); this.bytesPerSecond = formatChunk.readUint32();
this.blockAlignment = formatChunk.readUint16(); this.blockAlignment = formatChunk.readUint16();
this.bitsPerSample = formatChunk.readUint16(); this.bitsPerSample = formatChunk.readUint16();
formatChunk.position += 2; // skip extra header byte count formatChunk.position += 2; // skip extra header byte count
this.samplesPerBlock = formatChunk.readUint16(); this.samplesPerBlock = formatChunk.readUint16();
this.adpcmBlockSize = ((this.samplesPerBlock - 1) / 2) + 4; // block size in bytes this.adpcmBlockSize = ((this.samplesPerBlock - 1) / 2) + 4; // block size in bytes
@ -168,7 +168,7 @@ class ADPCMSoundDecoder {
const available = compressedData.getBytesAvailable(); const available = compressedData.getBytesAvailable();
const blocks = (available / blockSize) | 0; const blocks = (available / blockSize) | 0;
// Number of samples in full blocks. // Number of samples in full blocks.
const fullBlocks = blocks * (2 * (blockSize - 4)) + 1; const fullBlocks = (blocks * (2 * (blockSize - 4))) + 1;
// Number of samples in the last incomplete block. 0 if the last block // Number of samples in the last incomplete block. 0 if the last block
// is full. // is full.
const subBlock = Math.max((available % blockSize) - 4, 0) * 2; const subBlock = Math.max((available % blockSize) - 4, 0) * 2;
@ -216,7 +216,7 @@ class ADPCMSoundDecoder {
// read 4-bit code and compute delta from previous sample // read 4-bit code and compute delta from previous sample
lastByte = compressedData.readUint8(); lastByte = compressedData.readUint8();
code = lastByte & 0xF; code = lastByte & 0xF;
delta = DELTA_TABLE[index * 16 + code]; delta = DELTA_TABLE[(index * 16) + code];
// compute next index // compute next index
index += INDEX_TABLE[code]; index += INDEX_TABLE[code];
if (index > 88) index = 88; if (index > 88) index = 88;
@ -230,7 +230,7 @@ class ADPCMSoundDecoder {
// use 4-bit code from lastByte and compute delta from previous // use 4-bit code from lastByte and compute delta from previous
// sample // sample
code = (lastByte >> 4) & 0xF; code = (lastByte >> 4) & 0xF;
delta = DELTA_TABLE[index * 16 + code]; delta = DELTA_TABLE[(index * 16) + code];
// compute next index // compute next index
index += INDEX_TABLE[code]; index += INDEX_TABLE[code];
if (index > 88) index = 88; if (index > 88) index = 88;

View file

@ -95,7 +95,6 @@ class ArrayBufferStream {
*/ */
set position (value) { set position (value) {
this._position = value + this.start; this._position = value + this.start;
return value;
} }
/** /**

View file

@ -218,7 +218,7 @@ class AudioEngine {
*/ */
decodeSoundPlayer (sound) { decodeSoundPlayer (sound) {
return this._decodeSound(sound) return this._decodeSound(sound)
.then(([id, buffer]) => new SoundPlayer(this, {id, buffer})); .then(([id, buffer]) => new SoundPlayer(this, {id, buffer}));
} }
/** /**

View file

@ -44,9 +44,9 @@ class Loudness {
this.mic.connect(this.analyser); this.mic.connect(this.analyser);
this.micDataArray = new Float32Array(this.analyser.fftSize); this.micDataArray = new Float32Array(this.analyser.fftSize);
}) })
.catch(err => { .catch(err => {
log.warn(err); log.warn(err);
}); });
} }
// If the microphone is set up and active, measure the loudness // If the microphone is set up and active, measure the loudness

View file

@ -150,7 +150,7 @@ class SoundBank {
this.soundEffects.forEach(effects => effects.dispose()); this.soundEffects.forEach(effects => effects.dispose());
this.soundEffects.clear(); this.soundEffects.clear();
for (const soundId in this.soundPlayers) { for (const soundId in this.soundPlayers) {
if (this.soundPlayers.hasOwnProperty(soundId)) { if (Object.prototype.hasOwnProperty.call(this.soundPlayers, soundId)) {
this.soundPlayers[soundId].dispose(); this.soundPlayers[soundId].dispose();
} }
} }

View file

@ -2,7 +2,7 @@
* An effect on an AudioPlayer and all its SoundPlayers. * An effect on an AudioPlayer and all its SoundPlayers.
*/ */
class Effect { class Effect {
/** /**
* @param {AudioEngine} audioEngine - audio engine this runs with * @param {AudioEngine} audioEngine - audio engine this runs with
* @param {AudioPlayer} audioPlayer - audio player this affects * @param {AudioPlayer} audioPlayer - audio player this affects
* @param {Effect} lastEffect - effect in the chain before this one * @param {Effect} lastEffect - effect in the chain before this one

View file

@ -118,7 +118,7 @@ class PitchEffect extends Effect {
if (!players) return; if (!players) return;
for (const id in players) { for (const id in players) {
if (players.hasOwnProperty(id)) { if (Object.prototype.hasOwnProperty.call(players, id)) {
this.updatePlayer(players[id]); this.updatePlayer(players[id]);
} }
} }

View file

@ -157,51 +157,51 @@ tap.test('SoundPlayer', suite => {
audioContext.$processTo(audioEngine.DECAY_DURATION); audioContext.$processTo(audioEngine.DECAY_DURATION);
return Promise.resolve() return Promise.resolve()
.then(() => { .then(() => {
t.equal(soundPlayer.outputNode.$state, 'PLAYING'); t.equal(soundPlayer.outputNode.$state, 'PLAYING');
soundPlayer.play(); soundPlayer.play();
soundPlayer.finished().then(() => log.push('play 2 finished')); soundPlayer.finished().then(() => log.push('play 2 finished'));
// wait for a micro-task loop to fire our previous events // wait for a micro-task loop to fire our previous events
return Promise.resolve(); return Promise.resolve();
}) })
.then(() => { .then(() => {
t.equal(log[0], 'play 1 finished'); t.equal(log[0], 'play 1 finished');
t.notEqual(soundPlayer.outputNode, firstPlayNode, 'created new player node'); t.notEqual(soundPlayer.outputNode, firstPlayNode, 'created new player node');
t.equal(help.engineInputs.length, 2, 'there should be 2 players connected'); t.equal(help.engineInputs.length, 2, 'there should be 2 players connected');
t.equal(firstPlayNode.$state, 'PLAYING'); t.equal(firstPlayNode.$state, 'PLAYING');
t.equal(soundPlayer.outputNode.$state, 'PLAYING'); t.equal(soundPlayer.outputNode.$state, 'PLAYING');
t.equal(help.engineInputs[0].gain.value, 1, 'old sound connectect to gain node with volume 1'); t.equal(help.engineInputs[0].gain.value, 1, 'old sound connectect to gain node with volume 1');
const {currentTime} = audioContext; const {currentTime} = audioContext;
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + 0.001); audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + 0.001);
t.notEqual(help.engineInputs[0].gain.value, 1, t.notEqual(help.engineInputs[0].gain.value, 1,
'old sound connected to gain node which will fade'); 'old sound connected to gain node which will fade');
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.001); audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.001);
t.equal(soundPlayer.outputNode.$state, 'PLAYING'); t.equal(soundPlayer.outputNode.$state, 'PLAYING');
t.equal(firstPlayNode.$state, 'FINISHED'); t.equal(firstPlayNode.$state, 'FINISHED');
t.equal(help.engineInputs[0].gain.value, 0, 'faded old sound to 0'); t.equal(help.engineInputs[0].gain.value, 0, 'faded old sound to 0');
t.equal(log.length, 1); t.equal(log.length, 1);
audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.3); audioContext.$processTo(currentTime + audioEngine.DECAY_WAIT + audioEngine.DECAY_DURATION + 0.3);
// wait for a micro-task loop to fire our previous events // wait for a micro-task loop to fire our previous events
return Promise.resolve(); return Promise.resolve();
}) })
.then(() => { .then(() => {
t.equal(log[1], 'play 2 finished'); t.equal(log[1], 'play 2 finished');
t.equal(help.engineInputs.length, 1, 'old sound disconneted itself after done'); t.equal(help.engineInputs.length, 1, 'old sound disconneted itself after done');
t.equal(log.length, 2); t.equal(log.length, 2);
t.end(); t.end();
}); });
}); });
suite.end(); suite.end();