Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 7 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
},
"homepage": "https://github.com/LLK/scratch-audio#readme",
"dependencies": {
"audio-context": "1.0.1",
"minilog": "^3.0.1",
"startaudiocontext": "1.2.1"
"@turbowarp/startaudiocontext": "^1.0.0",
"minilog": "^3.0.1"
},
"devDependencies": {
"babel-core": "6.26.3",
Expand Down
10 changes: 5 additions & 5 deletions src/ADPCMSoundDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ADPCMSoundDecoder {
* Decode an ADPCM sound stored in an ArrayBuffer and return a promise
* with the decoded audio buffer.
* @param {ArrayBuffer} audioData - containing ADPCM encoded wav audio
* @return {AudioBuffer} the decoded audio buffer
* @return {Promise.AudioBuffer} the decoded audio buffer
*/
decode (audioData) {

Expand Down Expand Up @@ -120,7 +120,7 @@ class ADPCMSoundDecoder {
this.bytesPerSecond = formatChunk.readUint32();
this.blockAlignment = 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.adpcmBlockSize = ((this.samplesPerBlock - 1) / 2) + 4; // block size in bytes

Expand Down Expand Up @@ -168,7 +168,7 @@ class ADPCMSoundDecoder {
const available = compressedData.getBytesAvailable();
const blocks = (available / blockSize) | 0;
// 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
// is full.
const subBlock = Math.max((available % blockSize) - 4, 0) * 2;
Expand Down Expand Up @@ -216,7 +216,7 @@ class ADPCMSoundDecoder {
// read 4-bit code and compute delta from previous sample
lastByte = compressedData.readUint8();
code = lastByte & 0xF;
delta = DELTA_TABLE[index * 16 + code];
delta = DELTA_TABLE[(index * 16) + code];
// compute next index
index += INDEX_TABLE[code];
if (index > 88) index = 88;
Expand All @@ -230,7 +230,7 @@ class ADPCMSoundDecoder {
// use 4-bit code from lastByte and compute delta from previous
// sample
code = (lastByte >> 4) & 0xF;
delta = DELTA_TABLE[index * 16 + code];
delta = DELTA_TABLE[(index * 16) + code];
// compute next index
index += INDEX_TABLE[code];
if (index > 88) index = 88;
Expand Down
14 changes: 12 additions & 2 deletions src/AudioEngine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const StartAudioContext = require('./StartAudioContext');
const AudioContext = require('audio-context');

const log = require('./log');
const uid = require('./uid');
Expand Down Expand Up @@ -35,13 +34,24 @@ const decodeAudioData = function (audioContext, buffer) {
});
};

/**
* @returns {AudioContext} A new audio context.
*/
const makeAudioContext = () => {
const AudioContext = window.AudioContext || window.webkitAudioContext;
if (!AudioContext) {
throw new Error('Browser does not support AudioContext');
}
return new AudioContext();
};

/**
* There is a single instance of the AudioEngine. It handles global audio
* properties and effects, loads all the audio buffers for sounds belonging to
* sprites.
*/
class AudioEngine {
constructor (audioContext = new AudioContext()) {
constructor (audioContext = makeAudioContext()) {
/**
* AudioContext to play and manipulate sounds with a graph of source
* and effect nodes.
Expand Down
2 changes: 1 addition & 1 deletion src/SoundBank.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class SoundBank {
this.soundEffects.forEach(effects => effects.dispose());
this.soundEffects.clear();
for (const soundId in this.soundPlayers) {
if (this.soundPlayers.hasOwnProperty(soundId)) {
if (Object.prototype.hasOwnProperty.call(this.soundPlayers, soundId)) {
this.soundPlayers[soundId].dispose();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/StartAudioContext.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// StartAudioContext assumes that we are in a window/document setting and messes with the unit
// tests, this is our own version just checking to see if we have a global document to listen
// to before we even try to "start" it. Our test api audio context is started by default.
const StartAudioContext = require('startaudiocontext');
const StartAudioContext = require('@turbowarp/startaudiocontext');

module.exports = function (context) {
if (typeof document !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion src/effects/PitchEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class PitchEffect extends Effect {
if (!players) return;

for (const id in players) {
if (players.hasOwnProperty(id)) {
if (Object.prototype.hasOwnProperty.call(players, id)) {
this.updatePlayer(players[id]);
}
}
Expand Down
4 changes: 1 addition & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ module.exports = {
}]
},
externals: {
'audio-context': true,
'minilog': true,
'startaudiocontext': true
'audio-context': true
}
};
Loading