diff --git a/Makefile b/Makefile index 9360e6c..6fd178b 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ build/*.min.js: build/Pxtone.js build/pxtnDecoder.js build/Pxtone.js: build/ mkdir -p temp && \ - browserify -t babelify -s Pxtone src/index.js --no-commondir --igv global -i web-audio-api -i iconv-lite -o temp/Pxtone.js && \ + browserify -t babelify -s Pxtone src/index.js --no-commondir --igv global -i web-audio-api -i text-encoding -o temp/Pxtone.js && \ echo "/*! PxtoneJS" v`node -pe "require('./package.json').version"` "http://git.io/PxtoneJS */" | cat - temp/Pxtone.js > build/Pxtone.js && \ $(RM) -rf temp diff --git a/src/Pxtone.js b/src/Pxtone.js index 1863120..727c2d6 100644 --- a/src/Pxtone.js +++ b/src/Pxtone.js @@ -3,6 +3,7 @@ import createDecoder from "./createDecoder"; import { checkAudioContext } from "./value"; + const _ = createPrivateStorage(); export default class Pxtone { diff --git a/src/createDecoder.js b/src/createDecoder.js index 54862f8..99cb8ad 100644 --- a/src/createDecoder.js +++ b/src/createDecoder.js @@ -3,8 +3,8 @@ import "./polyfill"; import textDecoder from "./textDecoder"; import { checkArguments, getAptSampleRate } from "./value"; -const Worker = global.Worker; +const Worker = global.Worker || (() => {}); function uint8SetAscii(offset, str) { const strLength = str.length; diff --git a/src/polyfill.js b/src/polyfill.js index d983ec9..2bc1a3e 100644 --- a/src/polyfill.js +++ b/src/polyfill.js @@ -3,13 +3,14 @@ import "promise-decode-audio-data"; // for node const AudioContext = require("web-audio-api").AudioContext; + if(AudioContext) { const ctx = new AudioContext(); ctx._kill(); const noop = () => {}; - const isPromiseBased = ctx.decodeAudioData(new Uint32Array([ 1179011410, 48, 1163280727, 544501094, 16, 131073, 44100, 176400, 1048580, 1635017060, 8, 0, 0, 0, 0 ]).buffer, noop, noop); + const isPromiseBased = ctx.decodeAudioData(new ArrayBuffer(), noop, noop); if(!isPromiseBased) { const original = AudioContext.prototype.decodeAudioData; diff --git a/src/textDecoder.js b/src/textDecoder.js index 56fc2e9..832a68a 100644 --- a/src/textDecoder.js +++ b/src/textDecoder.js @@ -1,5 +1,4 @@ -// load only in node -const decode = require("iconv-lite").decode; +const TextDecoder = global.TextDecoder || require("text-encoding").TextDecoder; export default function textDecoder(arraybuffer, charset = "shift_jis") { if(arraybuffer.byteLength === 1 && (new Uint8Array(arraybuffer))[0] === 255) @@ -19,8 +18,5 @@ export default function textDecoder(arraybuffer, charset = "shift_jis") { }; reader.readAsText(blob, charset); }); - }).catch(() => { - // iconv-lite for node - resolve(decode(new Buffer(arraybuffer), charset)); }); } \ No newline at end of file diff --git a/src/value.js b/src/value.js index 7133650..93ab7cc 100644 --- a/src/value.js +++ b/src/value.js @@ -1,6 +1,5 @@ const AudioContext = global.AudioContext || global.webkitAudioContext || require("web-audio-api").AudioContext; - export function checkArguments(ctx, type, buffer, ch, sps, bps) { let errStr = "Invalid arguments:"; let isErr = false;