//=============================================================================
// vorbisdecoder.js v1.0.1
// This code is based on: http://nothings.org/stb_vorbis/
//=============================================================================
var VorbisDecoderModule = {};
VorbisDecoderModule["wasmBinary"] = Uint8Array.from(
  atob(
    "[encoded data, 62608 characters]"
  ),
  function (c) {
    return c.charCodeAt(0);
  }
);
var __dirname = null;
var Module =
  typeof VorbisDecoderModule !== "undefined" ? VorbisDecoderModule : {};
var moduleOverrides = {};
var key;
for (key in Module) {
  if (Module.hasOwnProperty(key)) {
    moduleOverrides[key] = Module[key];
  }
}
var arguments_ = [];
var thisProgram = "./this.program";
var quit_ = function (status, toThrow) {
  throw toThrow;
};
var ENVIRONMENT_IS_WEB = false;
var ENVIRONMENT_IS_WORKER = false;
var ENVIRONMENT_IS_NODE = false;
var ENVIRONMENT_IS_SHELL = false;
ENVIRONMENT_IS_WEB = typeof window === "object";
ENVIRONMENT_IS_WORKER = typeof importScripts === "function";
ENVIRONMENT_IS_NODE =
  typeof process === "object" &&
  typeof process.versions === "object" &&
  typeof process.versions.node === "string";
ENVIRONMENT_IS_SHELL =
  !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
var scriptDirectory = "";
function locateFile(path) {
  if (Module["locateFile"]) {
    return Module["locateFile"](path, scriptDirectory);
  }
  return scriptDirectory + path;
}
var read_, readAsync, readBinary, setWindowTitle;
var nodeFS;
var nodePath;
if (ENVIRONMENT_IS_NODE) {
  if (ENVIRONMENT_IS_WORKER) {
    scriptDirectory = require("path").dirname(scriptDirectory) + "/";
  } else {
    scriptDirectory = __dirname + "/";
  }
  read_ = function shell_read(filename, binary) {
    if (!nodeFS) nodeFS = require("fs");
    if (!nodePath) nodePath = require("path");
    filename = nodePath["normalize"](filename);
    return nodeFS["readFileSync"](filename, binary ? null : "utf8");
  };
  readBinary = function readBinary(filename) {
    var ret = read_(filename, true);
    if (!ret.buffer) {
      ret = new Uint8Array(ret);
    }
    assert(ret.buffer);
    return ret;
  };
  if (process["argv"].length > 1) {
    thisProgram = process["argv"][1].replace(/\\/g, "/");
  }
  arguments_ = process["argv"].slice(2);
  if (typeof module !== "undefined") {
    module["exports"] = Module;
  }
  process["on"]("uncaughtException", function (ex) {
    if (!(ex instanceof ExitStatus)) {
      throw ex;
    }
  });
  process["on"]("unhandledRejection", abort);
  quit_ = function (status) {
    process["exit"](status);
  };
  Module["inspect"] = function () {
    return "[Emscripten Module object]";
  };
} else if (ENVIRONMENT_IS_SHELL) {
  if (typeof read != "undefined") {
    read_ = function shell_read(f) {
      return read(f);
    };
  }
  readBinary = function readBinary(f) {
    var data;
    if (typeof readbuffer === "function") {
      return new Uint8Array(readbuffer(f));
    }
    data = read(f, "binary");
    assert(typeof data === "object");
    return data;
  };
  if (typeof scriptArgs != "undefined") {
    arguments_ = scriptArgs;
  } else if (typeof arguments != "undefined") {
    arguments_ = arguments;
  }
  if (typeof quit === "function") {
    quit_ = function (status) {
      quit(status);
    };
  }
  if (typeof print !== "undefined") {
    if (typeof console === "undefined") console = {};
    console.log = print;
    console.warn = console.error =
      typeof printErr !== "undefined" ? printErr : print;
  }
} else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  if (ENVIRONMENT_IS_WORKER) {
    scriptDirectory = self.location.href;
  } else if (document.currentScript) {
    scriptDirectory = document.currentScript.src;
  }
  if (scriptDirectory.indexOf("blob:") !== 0) {
    scriptDirectory = scriptDirectory.substr(
      0,
      scriptDirectory.lastIndexOf("/") + 1
    );
  } else {
    scriptDirectory = "";
  }
  {
    read_ = function shell_read(url) {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", url, false);
      xhr.send(null);
      return xhr.responseText;
    };
    if (ENVIRONMENT_IS_WORKER) {
      readBinary = function readBinary(url) {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, false);
        xhr.responseType = "arraybuffer";
        xhr.send(null);
        return new Uint8Array(xhr.response);
      };
    }
    readAsync = function readAsync(url, onload, onerror) {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", url, true);
      xhr.responseType = "arraybuffer";
      xhr.onload = function xhr_onload() {
        if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {
          onload(xhr.response);
          return;
        }
        onerror();
      };
      xhr.onerror = onerror;
      xhr.send(null);
    };
  }
  setWindowTitle = function (title) {
    document.title = title;
  };
} else {
}
var out = Module["print"] || console.log.bind(console);
var err = Module["printErr"] || console.warn.bind(console);
for (key in moduleOverrides) {
  if (moduleOverrides.hasOwnProperty(key)) {
    Module[key] = moduleOverrides[key];
  }
}
moduleOverrides = null;
if (Module["arguments"]) arguments_ = Module["arguments"];
if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
if (Module["quit"]) quit_ = Module["quit"];
var wasmBinary;
if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
var noExitRuntime;
if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
if (typeof WebAssembly !== "object") {
  err("no native wasm support detected");
}
function getValue(ptr, type, noSafe) {
  type = type || "i8";
  if (type.charAt(type.length - 1) === "*") type = "i32";
  switch (type) {
    case "i1":
      return HEAP8[ptr >> 0];
    case "i8":
      return HEAP8[ptr >> 0];
    case "i16":
      return HEAP16[ptr >> 1];
    case "i32":
      return HEAP32[ptr >> 2];
    case "i64":
      return HEAP32[ptr >> 2];
    case "float":
      return HEAPF32[ptr >> 2];
    case "double":
      return HEAPF64[ptr >> 3];
    default:
      abort("invalid type for getValue: " + type);
  }
  return null;
}
var wasmMemory;
var wasmTable = new WebAssembly.Table({
  initial: 3,
  maximum: 3 + 0,
  element: "anyfunc",
});
var ABORT = false;
var EXITSTATUS = 0;
function assert(condition, text) {
  if (!condition) {
    abort("Assertion failed: " + text);
  }
}
var UTF8Decoder =
  typeof TextDecoder !== "undefined" ? new TextDecoder("utf8") : undefined;
function UTF8ArrayToString(heap, idx, maxBytesToRead) {
  var endIdx = idx + maxBytesToRead;
  var endPtr = idx;
  while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr;
  if (endPtr - idx > 16 && heap.subarray && UTF8Decoder) {
    return UTF8Decoder.decode(heap.subarray(idx, endPtr));
  } else {
    var str = "";
    while (idx < endPtr) {
      var u0 = heap[idx++];
      if (!(u0 & 128)) {
        str += String.fromCharCode(u0);
        continue;
      }
      var u1 = heap[idx++] & 63;
      if ((u0 & 224) == 192) {
        str += String.fromCharCode(((u0 & 31) << 6) | u1);
        continue;
      }
      var u2 = heap[idx++] & 63;
      if ((u0 & 240) == 224) {
        u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
      } else {
        u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heap[idx++] & 63);
      }
      if (u0 < 65536) {
        str += String.fromCharCode(u0);
      } else {
        var ch = u0 - 65536;
        str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
      }
    }
  }
  return str;
}
function UTF8ToString(ptr, maxBytesToRead) {
  return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
}
var WASM_PAGE_SIZE = 65536;
var buffer, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
function updateGlobalBufferAndViews(buf) {
  buffer = buf;
  Module["HEAP8"] = HEAP8 = new Int8Array(buf);
  Module["HEAP16"] = HEAP16 = new Int16Array(buf);
  Module["HEAP32"] = HEAP32 = new Int32Array(buf);
  Module["HEAPU8"] = HEAPU8 = new Uint8Array(buf);
  Module["HEAPU16"] = HEAPU16 = new Uint16Array(buf);
  Module["HEAPU32"] = HEAPU32 = new Uint32Array(buf);
  Module["HEAPF32"] = HEAPF32 = new Float32Array(buf);
  Module["HEAPF64"] = HEAPF64 = new Float64Array(buf);
}
var DYNAMIC_BASE = 72928,
  DYNAMICTOP_PTR = 7232;
var INITIAL_INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 1048576;
if (Module["wasmMemory"]) {
  wasmMemory = Module["wasmMemory"];
} else {
  wasmMemory = new WebAssembly.Memory({
    initial: INITIAL_INITIAL_MEMORY / WASM_PAGE_SIZE,
    maximum: INITIAL_INITIAL_MEMORY / WASM_PAGE_SIZE,
  });
}
if (wasmMemory) {
  buffer = wasmMemory.buffer;
}
INITIAL_INITIAL_MEMORY = buffer.byteLength;
updateGlobalBufferAndViews(buffer);
HEAP32[DYNAMICTOP_PTR >> 2] = DYNAMIC_BASE;
function callRuntimeCallbacks(callbacks) {
  while (callbacks.length > 0) {
    var callback = callbacks.shift();
    if (typeof callback == "function") {
      callback(Module);
      continue;
    }
    var func = callback.func;
    if (typeof func === "number") {
      if (callback.arg === undefined) {
        Module["dynCall_v"](func);
      } else {
        Module["dynCall_vi"](func, callback.arg);
      }
    } else {
      func(callback.arg === undefined ? null : callback.arg);
    }
  }
}
var __ATPRERUN__ = [];
var __ATINIT__ = [];
var __ATMAIN__ = [];
var __ATPOSTRUN__ = [];
var runtimeInitialized = false;
function preRun() {
  if (Module["preRun"]) {
    if (typeof Module["preRun"] == "function")
      Module["preRun"] = [Module["preRun"]];
    while (Module["preRun"].length) {
      addOnPreRun(Module["preRun"].shift());
    }
  }
  callRuntimeCallbacks(__ATPRERUN__);
}
function initRuntime() {
  runtimeInitialized = true;
  callRuntimeCallbacks(__ATINIT__);
}
function preMain() {
  callRuntimeCallbacks(__ATMAIN__);
}
function postRun() {
  if (Module["postRun"]) {
    if (typeof Module["postRun"] == "function")
      Module["postRun"] = [Module["postRun"]];
    while (Module["postRun"].length) {
      addOnPostRun(Module["postRun"].shift());
    }
  }
  callRuntimeCallbacks(__ATPOSTRUN__);
}
function addOnPreRun(cb) {
  __ATPRERUN__.unshift(cb);
}
function addOnPostRun(cb) {
  __ATPOSTRUN__.unshift(cb);
}
var runDependencies = 0;
var runDependencyWatcher = null;
var dependenciesFulfilled = null;
function addRunDependency(id) {
  runDependencies++;
  if (Module["monitorRunDependencies"]) {
    Module["monitorRunDependencies"](runDependencies);
  }
}
function removeRunDependency(id) {
  runDependencies--;
  if (Module["monitorRunDependencies"]) {
    Module["monitorRunDependencies"](runDependencies);
  }
  if (runDependencies == 0) {
    if (runDependencyWatcher !== null) {
      clearInterval(runDependencyWatcher);
      runDependencyWatcher = null;
    }
    if (dependenciesFulfilled) {
      var callback = dependenciesFulfilled;
      dependenciesFulfilled = null;
      callback();
    }
  }
}
Module["preloadedImages"] = {};
Module["preloadedAudios"] = {};
function abort(what) {
  if (Module["onAbort"]) {
    Module["onAbort"](what);
  }
  what += "";
  out(what);
  err(what);
  ABORT = true;
  EXITSTATUS = 1;
  what = "abort(" + what + "). Build with -s ASSERTIONS=1 for more info.";
  throw new WebAssembly.RuntimeError(what);
}
function hasPrefix(str, prefix) {
  return String.prototype.startsWith
    ? str.startsWith(prefix)
    : str.indexOf(prefix) === 0;
}
var dataURIPrefix = "data:application/octet-stream;base64,";
function isDataURI(filename) {
  return hasPrefix(filename, dataURIPrefix);
}
var fileURIPrefix = "file://";
function isFileURI(filename) {
  return hasPrefix(filename, fileURIPrefix);
}
var wasmBinaryFile = "vorbisdecoder.wasm";
if (!isDataURI(wasmBinaryFile)) {
  wasmBinaryFile = locateFile(wasmBinaryFile);
}
function getBinary() {
  try {
    if (wasmBinary) {
      return new Uint8Array(wasmBinary);
    }
    if (readBinary) {
      return readBinary(wasmBinaryFile);
    } else {
      throw "both async and sync fetching of the wasm failed";
    }
  } catch (err) {
    abort(err);
  }
}
function getBinaryPromise() {
  if (
    !wasmBinary &&
    (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) &&
    typeof fetch === "function" &&
    !isFileURI(wasmBinaryFile)
  ) {
    return fetch(wasmBinaryFile, { credentials: "same-origin" })
      .then(function (response) {
        if (!response["ok"]) {
          throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
        }
        return response["arrayBuffer"]();
      })
      .catch(function () {
        return getBinary();
      });
  }
  return new Promise(function (resolve, reject) {
    resolve(getBinary());
  });
}
function createWasm() {
  var info = { a: asmLibraryArg };
  function receiveInstance(instance, module) {
    var exports = instance.exports;
    Module["asm"] = exports;
    removeRunDependency("wasm-instantiate");
  }
  addRunDependency("wasm-instantiate");
  function receiveInstantiatedSource(output) {
    receiveInstance(output["instance"]);
  }
  function instantiateArrayBuffer(receiver) {
    return getBinaryPromise()
      .then(function (binary) {
        return WebAssembly.instantiate(binary, info);
      })
      .then(receiver, function (reason) {
        err("failed to asynchronously prepare wasm: " + reason);
        abort(reason);
      });
  }
  function instantiateAsync() {
    if (
      !wasmBinary &&
      typeof WebAssembly.instantiateStreaming === "function" &&
      !isDataURI(wasmBinaryFile) &&
      !isFileURI(wasmBinaryFile) &&
      typeof fetch === "function"
    ) {
      fetch(wasmBinaryFile, { credentials: "same-origin" }).then(function (
        response
      ) {
        var result = WebAssembly.instantiateStreaming(response, info);
        return result.then(receiveInstantiatedSource, function (reason) {
          err("wasm streaming compile failed: " + reason);
          err("falling back to ArrayBuffer instantiation");
          instantiateArrayBuffer(receiveInstantiatedSource);
        });
      });
    } else {
      return instantiateArrayBuffer(receiveInstantiatedSource);
    }
  }
  if (Module["instantiateWasm"]) {
    try {
      var exports = Module["instantiateWasm"](info, receiveInstance);
      return exports;
    } catch (e) {
      err("Module.instantiateWasm callback failed with error: " + e);
      return false;
    }
  }
  instantiateAsync();
  return {};
}
__ATINIT__.push({
  func: function () {
    ___wasm_call_ctors();
  },
});
function ___assert_fail(condition, filename, line, func) {
  abort(
    "Assertion failed: " +
      UTF8ToString(condition) +
      ", at: " +
      [
        filename ? UTF8ToString(filename) : "unknown filename",
        line,
        func ? UTF8ToString(func) : "unknown function",
      ]
  );
}
function _emscripten_memcpy_big(dest, src, num) {
  HEAPU8.copyWithin(dest, src, src + num);
}
function abortOnCannotGrowMemory(requestedSize) {
  abort("OOM");
}
function _emscripten_resize_heap(requestedSize) {
  requestedSize = requestedSize >>> 0;
  abortOnCannotGrowMemory(requestedSize);
}
var asmLibraryArg = {
  a: ___assert_fail,
  b: _emscripten_memcpy_big,
  c: _emscripten_resize_heap,
  memory: wasmMemory,
  table: wasmTable,
};
var asm = createWasm();
Module["asm"] = asm;
var ___wasm_call_ctors = (Module["___wasm_call_ctors"] = function () {
  return (___wasm_call_ctors = Module["___wasm_call_ctors"] =
    Module["asm"]["d"]).apply(null, arguments);
});
var _stb_vorbis_close = (Module["_stb_vorbis_close"] = function () {
  return (_stb_vorbis_close = Module["_stb_vorbis_close"] =
    Module["asm"]["e"]).apply(null, arguments);
});
var _free = (Module["_free"] = function () {
  return (_free = Module["_free"] = Module["asm"]["f"]).apply(null, arguments);
});
var _stb_vorbis_decode_frame_pushdata = (Module[
  "_stb_vorbis_decode_frame_pushdata"
] = function () {
  return (_stb_vorbis_decode_frame_pushdata = Module[
    "_stb_vorbis_decode_frame_pushdata"
  ] =
    Module["asm"]["g"]).apply(null, arguments);
});
var _stb_vorbis_open_pushdata = (Module["_stb_vorbis_open_pushdata"] =
  function () {
    return (_stb_vorbis_open_pushdata = Module["_stb_vorbis_open_pushdata"] =
      Module["asm"]["h"]).apply(null, arguments);
  });
var _malloc = (Module["_malloc"] = function () {
  return (_malloc = Module["_malloc"] = Module["asm"]["i"]).apply(
    null,
    arguments
  );
});
Module["asm"] = asm;
Module["getValue"] = getValue;
var calledRun;
function ExitStatus(status) {
  this.name = "ExitStatus";
  this.message = "Program terminated with exit(" + status + ")";
  this.status = status;
}
dependenciesFulfilled = function runCaller() {
  if (!calledRun) run();
  if (!calledRun) dependenciesFulfilled = runCaller;
};
function run(args) {
  args = args || arguments_;
  if (runDependencies > 0) {
    return;
  }
  preRun();
  if (runDependencies > 0) return;
  function doRun() {
    if (calledRun) return;
    calledRun = true;
    Module["calledRun"] = true;
    if (ABORT) return;
    initRuntime();
    preMain();
    if (Module["onRuntimeInitialized"]) Module["onRuntimeInitialized"]();
    postRun();
  }
  if (Module["setStatus"]) {
    Module["setStatus"]("Running...");
    setTimeout(function () {
      setTimeout(function () {
        Module["setStatus"]("");
      }, 1);
      doRun();
    }, 1);
  } else {
    doRun();
  }
}
Module["run"] = run;
if (Module["preInit"]) {
  if (typeof Module["preInit"] == "function")
    Module["preInit"] = [Module["preInit"]];
  while (Module["preInit"].length > 0) {
    Module["preInit"].pop()();
  }
}
noExitRuntime = true;
run();
class VorbisDecoder {
  constructor(context, decodeHandler, errorHandler) {
    VorbisDecoder.id = (VorbisDecoder.id || 0) % 1e3;
    this.id = VorbisDecoder.id++;
    this.context = context;
    this.decodeHandler = decodeHandler;
    this.errorHandler = errorHandler;
    VorbisDecoder.instances = VorbisDecoder.instances || [];
    VorbisDecoder.instances[this.id] = this;
  }
  destroy() {
    const message = { id: this.id, destroy: true };
    VorbisDecoder.worker.postMessage(message);
    delete VorbisDecoder.instances[this.id];
  }
  send(arrayBuffer, isLoaded) {
    const message = {
      id: this.id,
      arrayBuffer: arrayBuffer,
      isLoaded: isLoaded,
    };
    VorbisDecoder.worker.postMessage(message);
  }
  onMessage(message) {
    const channels = message.data.length;
    if (channels > 0) {
      const length = message.data[0].length;
      const buffer = this.context.createBuffer(
        channels,
        length,
        message.sampleRate
      );
      for (let i = 0; i < channels; i++) {
        buffer.getChannelData(i).set(message.data[i]);
      }
      this.decodeHandler(buffer);
    } else {
      this.errorHandler();
    }
  }
}
if (typeof WorkerGlobalScope === "function") {
  class VorbisWorkerDecoder {
    constructor(id) {
      this.v = null;
      this.id = id;
    }
    onMessage(message) {
      if (message.arrayBuffer) {
        if (this.isOpen()) {
          this.replace(message.arrayBuffer);
        } else {
          this.open(message.arrayBuffer);
        }
      }
      if (message.isLoaded) {
        this.isLoaded = message.isLoaded;
      }
      this.decode();
    }
    open(arrayBuffer) {
      this.arrayBuffer = arrayBuffer;
      this.isLoaded = false;
      this.byteOffset = 0;
      this.channels = 2;
      this.bufferMax = 8192;
      this.bufferPtr = Module._malloc(this.bufferMax);
      this.usedPtr = Module._malloc(4);
      this.outputPtr = Module._malloc(4);
      this.samplesPtr = Module._malloc(4);
      this.makeBuffer();
      this.v = Module._stb_vorbis_open_pushdata(
        this.bufferPtr,
        this.bufferSize,
        this.usedPtr,
        null,
        null
      );
      this.byteOffset += Module.getValue(this.usedPtr, "i32");
      this.channels = Module.getValue(this.v + 4, "i32");
      this.sampleRate = Module.getValue(this.v + 0, "i32");
      this.sampleScale = 1;
      if (this.sampleRate >= 8e3 && this.sampleRate < 22050) {
        this.sampleScale = Math.ceil(22050 / this.sampleRate);
      }
      this.totalSamples = 0;
      this.arrays = [];
      this.data = [];
      for (let i = 0; i < this.channels; i++) {
        this.arrays[i] = [];
        this.data[i] = null;
      }
    }
    isOpen() {
      return this.v !== null;
    }
    close() {
      if (this.isOpen()) {
        Module._stb_vorbis_close(this.v);
        Module._free(this.bufferPtr);
        Module._free(this.usedPtr);
        Module._free(this.outputPtr);
        Module._free(this.samplesPtr);
        this.v = null;
      }
      this.arrayBuffer = null;
      this.dispose();
    }
    dispose() {
      this.totalSamples = 0;
      for (let i = 0; i < this.channels; i++) {
        this.arrays[i] = [];
        this.data[i] = null;
      }
    }
    replace(arrayBuffer) {
      this.arrayBuffer = arrayBuffer;
    }
    makeBuffer() {
      const totalBytes = this.arrayBuffer.byteLength;
      const remainingBytes = totalBytes - this.byteOffset;
      this.bufferSize = Math.min(remainingBytes, this.bufferMax);
      const array = new Uint8Array(
        this.arrayBuffer,
        this.byteOffset,
        this.bufferSize
      );
      Module.HEAPU8.set(array, this.bufferPtr);
    }
    decodeFrame() {
      this.makeBuffer();
      const used = Module._stb_vorbis_decode_frame_pushdata(
        this.v,
        this.bufferPtr,
        this.bufferSize,
        null,
        this.outputPtr,
        this.samplesPtr
      );
      if (used > 0) {
        const output = Module.getValue(this.outputPtr, "i32");
        const samples = Module.getValue(this.samplesPtr, "i32");
        this.byteOffset += used;
        for (let i = 0; i < this.channels; i++) {
          const output_i = Module.getValue(output + i * 4, "i32");
          const array = new Float32Array(
            Module.HEAPU8.buffer,
            output_i,
            samples
          );
          this.arrays[i].push(this.resample(array));
        }
        this.totalSamples += samples;
        return true;
      } else {
        return false;
      }
    }
    decode() {
      if (this.isOpen()) {
        for (;;) {
          if (!this.decodeFrame()) {
            if (this.isLoaded) {
              this.sendBack();
              this.close();
            }
            break;
          }
          if (this.totalSamples >= this.sampleRate * 5) {
            this.sendBack();
            setTimeout(this.decode.bind(this));
            break;
          }
        }
      }
    }
    resample(array) {
      if (this.sampleScale === 1) {
        return array.slice();
      } else {
        const scale = this.sampleScale;
        const expanded = new Float32Array(array.length * scale);
        for (let i = 0; i < array.length; i++) {
          for (let j = 0; j < scale; j++) {
            expanded[i * scale + j] = array[i];
          }
        }
        return expanded;
      }
    }
    concatenate() {
      for (let i = 0; i < this.channels; i++) {
        this.data[i] = new Float32Array(this.totalSamples * this.sampleScale);
        let offset = 0;
        for (const array of this.arrays[i]) {
          this.data[i].set(array, offset);
          offset += array.length;
        }
      }
    }
    sendBack() {
      if (this.totalSamples > 0) {
        this.concatenate();
        const message = {
          id: this.id,
          sampleRate: this.sampleRate * this.sampleScale,
          data: this.data,
        };
        const transfer = [];
        for (let i = 0; i < this.channels; i++) {
          transfer.push(this.data[i].buffer);
        }
        postMessage(message, transfer);
        this.dispose();
      }
    }
  }
  VorbisWorkerDecoder.instances = [];
  self.addEventListener("message", (e) => {
    const id = e.data.id;
    const instances = VorbisWorkerDecoder.instances;
    if (!instances[id]) {
      instances[id] = new VorbisWorkerDecoder(id);
    }
    if (instances[id]) {
      instances[id].onMessage(e.data);
    }
    if (e.data.destroy) {
      instances[id].close();
      delete instances[id];
    }
  });
} else {
  VorbisDecoder.instances = [];
  VorbisDecoder.worker = new Worker(document.currentScript.src);
  VorbisDecoder.worker.addEventListener("message", (e) => {
    const instances = VorbisDecoder.instances;
    const id = e.data.id;
    if (instances[id]) {
      instances[id].onMessage(e.data);
    }
  });
}
