diff --git a/package-lock.json b/package-lock.json index 1bd42ada..8178b274 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,8 @@ "version": "0.1.0", "license": "BSD-3-Clause", "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", @@ -884,15 +883,6 @@ "node": ">= 4.5.0" } }, - "node_modules/audio-context": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/audio-context/-/audio-context-1.0.1.tgz", - "integrity": "sha512-b7ZmHGyjcAI3KmshPa4YSPxPbjglZQtKfZtzqhUfE3VeoANTsNffywkmujI32Sj31Aku/aB9s3BW4r3nmTF88g==", - "deprecated": "Depends on Web-Audio-API implementation. Use either web-audio-api, web-audio-js or web-audio-engine package.", - "dependencies": { - "global": "^4.3.1" - } - }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -4021,15 +4011,6 @@ "node": ">= 6" } }, - "node_modules/global": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/global/-/global-4.4.0.tgz", - "integrity": "sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w==", - "dependencies": { - "min-document": "^2.19.0", - "process": "^0.11.10" - } - }, "node_modules/global-modules": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/global-modules/-/global-modules-2.0.0.tgz", @@ -5675,14 +5656,6 @@ "node": ">= 0.6" } }, - "node_modules/min-document": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.0.tgz", - "integrity": "sha512-9Wy1B3m3f66bPPmU5hdA4DR4PB2OfDU/+GS3yAB7IQozE3tqXaVv2zOjgla7MEGSRv95+ILmOuvhLkOK6wJtCQ==", - "dependencies": { - "dom-walk": "^0.1.0" - } - }, "node_modules/minilog": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/minilog/-/minilog-3.1.0.tgz", @@ -6574,6 +6547,7 @@ "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "dev": true, "engines": { "node": ">= 0.6.0" } @@ -7793,10 +7767,10 @@ "node": ">=8" } }, - "node_modules/startaudiocontext": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/startaudiocontext/-/startaudiocontext-1.2.1.tgz", - "integrity": "sha512-ooOQhOAoCwzMIRwWd9j7xF8kAMo1Wv7Zfw+q6dWDW5gxJUKx15HJXWDg89GMDqfdle9xsqPv+uioneX+bI643g==" + "node_modules/@turbowarp/startaudiocontext": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@turbowarp/startaudiocontext/-/startaudiocontext-1.0.0.tgz", + "integrity": "sha512-BJ7EVYVwuTH/Tr6tEaLaXA5TCi8qKxNWsxohNqxIEDzykN+FscgOALhEMUlNc6vgcmOi7yQFJ82Prx9bnY5DgA==" }, "node_modules/static-extend": { "version": "0.1.2", @@ -12090,11 +12064,6 @@ "esutils": "^2.0.2" } }, - "dom-walk": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.2.tgz", - "integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==" - }, "domain-browser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-1.2.0.tgz", @@ -16112,11 +16081,6 @@ } } }, - "startaudiocontext": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/startaudiocontext/-/startaudiocontext-1.2.1.tgz", - "integrity": "sha512-ooOQhOAoCwzMIRwWd9j7xF8kAMo1Wv7Zfw+q6dWDW5gxJUKx15HJXWDg89GMDqfdle9xsqPv+uioneX+bI643g==" - }, "static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", diff --git a/package.json b/package.json index a7eeb9f0..70d326c8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/ADPCMSoundDecoder.js b/src/ADPCMSoundDecoder.js index 82ee9be7..9509170b 100644 --- a/src/ADPCMSoundDecoder.js +++ b/src/ADPCMSoundDecoder.js @@ -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) { @@ -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 @@ -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; @@ -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; @@ -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; diff --git a/src/AudioEngine.js b/src/AudioEngine.js index 2f6b66ac..703d1fc4 100644 --- a/src/AudioEngine.js +++ b/src/AudioEngine.js @@ -1,5 +1,4 @@ const StartAudioContext = require('./StartAudioContext'); -const AudioContext = require('audio-context'); const log = require('./log'); const uid = require('./uid'); @@ -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. diff --git a/src/SoundBank.js b/src/SoundBank.js index 6142db1c..542d861a 100644 --- a/src/SoundBank.js +++ b/src/SoundBank.js @@ -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(); } } diff --git a/src/StartAudioContext.js b/src/StartAudioContext.js index 6959d198..5c7418d4 100644 --- a/src/StartAudioContext.js +++ b/src/StartAudioContext.js @@ -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') { diff --git a/src/effects/PitchEffect.js b/src/effects/PitchEffect.js index 51d581d5..78f78c58 100644 --- a/src/effects/PitchEffect.js +++ b/src/effects/PitchEffect.js @@ -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]); } } diff --git a/webpack.config.js b/webpack.config.js index e37c8f78..81d3d5a7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -23,8 +23,6 @@ module.exports = { }] }, externals: { - 'audio-context': true, - 'minilog': true, - 'startaudiocontext': true + 'audio-context': true } };