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EA,MAAM,wBACN,IAEJ,CAEA,GACF,EAUA,QAAQ,UAAU,MAAQ,SAAU,GAClC,MAAM,WACN,KAAK,QAAQ,GACb,EAAO,KAAK,SAAU,KAAK,QAC7B,EAUA,QAAQ,UAAU,QAAU,SAAU,GACpC,MAAM,aACN,EAAO,eAAe,SAAU,KAAK,QACvC,EASA,QAAQ,UAAU,OAAS,WACzB,MAAM,YACN,KAAK,KAAK,SACV,KAAK,OAAM,EACb,EAWA,QAAQ,UAAU,MAAQ,SAAU,GAElC,GADA,MAAM,YAAa,GACf,KAAK,QAAS,OAAO,MAAM,qBAE3B,KAAK,eACH,IAAU,IAEZ,MAAM,mCACN,QAAQ,MAAM,KAAK,eAIrB,MAAM,mCACN,QAAQ,MAAM,KAAK,cACnB,KAAK,aAAe,MAEpB,MAAM,oEAGR,KAAK,SAAU,EACf,KAAK,KAAK,QACZ","file":"/npm/zplayer@0.4.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/zplayer@0.4.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\n/**\n * Module dependencies.\n */\n\nvar os = require('os');\nvar debug = require('debug')('speaker');\nvar binding = require('bindings')('binding');\nvar inherits = require('util').inherits;\nvar Writable = require('readable-stream/writable');\n\n// determine the native host endianness, the only supported playback endianness\nvar endianness = 'function' == os.endianness ?\n                 os.endianness() :\n                 'LE'; // assume little-endian for older versions of node.js\n\n/**\n * Module exports.\n */\n\nexports = module.exports = Speaker;\n\n/**\n * Export information about the `mpg123_module_t` being used.\n */\n\nexports.api_version = binding.api_version;\nexports.description = binding.description;\nexports.module_name = binding.name;\n\n/**\n * Returns the `MPG123_ENC_*` constant that corresponds to the given \"format\"\n * object, or `null` if the format is invalid.\n *\n * @param {Object} format - format object with `channels`, `sampleRate`, `bitDepth`, etc.\n * @return {Number} MPG123_ENC_* constant, or `null`\n * @api public\n */\n\nexports.getFormat = function getFormat (format) {\n  var f = null;\n  if (format.bitDepth == 32 && format.float && format.signed) {\n    f = binding.MPG123_ENC_FLOAT_32;\n  } else if (format.bitDepth == 64 && format.float && format.signed) {\n    f = binding.MPG123_ENC_FLOAT_64;\n  } else if (format.bitDepth == 8 && format.signed) {\n    f = binding.MPG123_ENC_SIGNED_8;\n  } else if (format.bitDepth == 8 && !format.signed) {\n    f = binding.MPG123_ENC_UNSIGNED_8;\n  } else if (format.bitDepth == 16 && format.signed) {\n    f = binding.MPG123_ENC_SIGNED_16;\n  } else if (format.bitDepth == 16 && !format.signed) {\n    f = binding.MPG123_ENC_UNSIGNED_16;\n  } else if (format.bitDepth == 24 && format.signed) {\n    f = binding.MPG123_ENC_SIGNED_24;\n  } else if (format.bitDepth == 24 && !format.signed) {\n    f = binding.MPG123_ENC_UNSIGNED_24;\n  } else if (format.bitDepth == 32 && format.signed) {\n    f = binding.MPG123_ENC_SIGNED_32;\n  } else if (format.bitDepth == 32 && !format.signed) {\n    f = binding.MPG123_ENC_UNSIGNED_32;\n  }\n  return f;\n}\n\n/**\n * Returns `true` if the given \"format\" is playable via the \"output module\"\n * that was selected during compilation, or `false` if not playable.\n *\n * @param {Number} format - MPG123_ENC_* format constant\n * @return {Boolean} true if the format is playable, false otherwise\n * @api public\n */\n\nexports.isSupported = function isSupported (format) {\n  if ('number' !== typeof format) format = exports.getFormat(format);\n  return (binding.formats & format) === format;\n}\n\n/**\n * The `Speaker` class accepts raw PCM data written to it, and then sends that data\n * to the default output device of the OS.\n *\n * @param {Object} opts options object\n * @api public\n */\n\nfunction Speaker (opts) {\n  if (!(this instanceof Speaker)) return new Speaker(opts);\n\n  // default lwm and hwm to 0\n  if (!opts) opts = {};\n  if (null == opts.lowWaterMark) opts.lowWaterMark = 0;\n  if (null == opts.highWaterMark) opts.highWaterMark = 0;\n\n  Writable.call(this, opts);\n\n  // chunks are sent over to the backend in \"samplesPerFrame * blockAlign\" size.\n  // this is necessary because if we send too big of chunks at once, then there\n  // won't be any data ready when the audio callback comes (experienced with the\n  // CoreAudio backend)\n  this.samplesPerFrame = 1024;\n\n  // the `audio_output_t` struct pointer Buffer instance\n  this.audio_handle = null;\n\n  // flipped after close() is called, no write() calls allowed after\n  this._closed = false;\n\n  // set PCM format\n  this._format(opts);\n\n  // bind event listeners\n  this._format = this._format.bind(this);\n  this.on('finish', this._flush);\n  this.on('pipe', this._pipe);\n  this.on('unpipe', this._unpipe);\n}\ninherits(Speaker, Writable);\n\n/**\n * Calls the audio backend's `open()` function, and then emits an \"open\" event.\n *\n * @api private\n */\n\nSpeaker.prototype._open = function () {\n  debug('open()');\n  if (this.audio_handle) {\n    throw new Error('_open() called more than once!');\n  }\n  // set default options, if not set\n  if (null == this.channels) {\n    debug('setting default %o: %o', 'channels', 2);\n    this.channels = 2;\n  }\n  if (null == this.bitDepth) {\n    var depth = this.float ? 32 : 16;\n    debug('setting default %o: %o', 'bitDepth', depth);\n    this.bitDepth = depth;\n  }\n  if (null == this.sampleRate) {\n    debug('setting default %o: %o', 'sampleRate', 44100);\n    this.sampleRate = 44100;\n  }\n  if (null == this.signed) {\n    debug('setting default %o: %o', 'signed', this.bitDepth != 8);\n    this.signed = this.bitDepth != 8;\n  }\n\n  var format = exports.getFormat(this);\n  if (null == format) {\n    throw new Error('invalid PCM format specified');\n  }\n\n  if (!exports.isSupported(format)) {\n    throw new Error('specified PCM format is not supported by \"' + binding.name + '\" backend');\n  }\n\n  // calculate the \"block align\"\n  this.blockAlign = this.bitDepth / 8 * this.channels;\n\n  // initialize the audio handle\n  // TODO: open async?\n  this.audio_handle = new Buffer(binding.sizeof_audio_output_t);\n  var r = binding.open(this.audio_handle, this.channels, this.sampleRate, format);\n  if (0 !== r) {\n    throw new Error('open() failed: ' + r);\n  }\n\n  this.emit('open');\n  return this.audio_handle;\n};\n\n/**\n * Set given PCM formatting options. Called during instantiation on the passed in\n * options object, on the stream given to the \"pipe\" event, and a final time if\n * that stream emits a \"format\" event.\n *\n * @param {Object} opts\n * @api private\n */\n\nSpeaker.prototype._format = function (opts) {\n  debug('format(object keys = %o)', Object.keys(opts));\n  if (null != opts.channels) {\n    debug('setting %o: %o', 'channels', opts.channels);\n    this.channels = opts.channels;\n  }\n  if (null != opts.bitDepth) {\n    debug('setting %o: %o', \"bitDepth\", opts.bitDepth);\n    this.bitDepth = opts.bitDepth;\n  }\n  if (null != opts.sampleRate) {\n    debug('setting %o: %o', \"sampleRate\", opts.sampleRate);\n    this.sampleRate = opts.sampleRate;\n  }\n  if (null != opts.float) {\n    debug('setting %o: %o', \"float\", opts.float);\n    this.float = opts.float;\n  }\n  if (null != opts.signed) {\n    debug('setting %o: %o', \"signed\", opts.signed);\n    this.signed = opts.signed;\n  }\n  if (null != opts.samplesPerFrame) {\n    debug('setting %o: %o', \"samplesPerFrame\", opts.samplesPerFrame);\n    this.samplesPerFrame = opts.samplesPerFrame;\n  }\n  if (null == opts.endianness || endianness == opts.endianness) {\n    // no \"endianness\" specified or explicit native endianness\n    this.endianness = endianness;\n  } else {\n    // only native endianness is supported...\n    this.emit('error', new Error('only native endianness (\"' + endianness + '\") is supported, got \"' + opts.endianness + '\"'));\n  }\n};\n\n/**\n * `_write()` callback for the Writable base class.\n *\n * @param {Buffer} chunk\n * @param {String} encoding\n * @param {Function} done\n * @api private\n */\n\nSpeaker.prototype._write = function (chunk, encoding, done) {\n  debug('_write() (%o bytes)', chunk.length);\n\n  if (this._closed) {\n    // close() has already been called. this should not be called\n    return done(new Error('write() call after close() call'));\n  }\n  var b;\n  var self = this;\n  var left = chunk;\n  var handle = this.audio_handle;\n  if (!handle) {\n    // this is the first time write() is being called; need to _open()\n    try {\n      handle = this._open();\n    } catch (e) {\n      return done(e);\n    }\n  }\n  var chunkSize = this.blockAlign * this.samplesPerFrame;\n\n  function write () {\n    if (self._closed) {\n      debug('aborting remainder of write() call (%o bytes), since speaker is `_closed`', left.length);\n      return done();\n    }\n    b = left;\n    if (b.length > chunkSize) {\n      var t = b;\n      b = t.slice(0, chunkSize);\n      left = t.slice(chunkSize);\n    } else {\n      left = null;\n    }\n    debug('writing %o byte chunk', b.length);\n    binding.write(handle, b, b.length, onwrite);\n  }\n\n  function onwrite (r) {\n    debug('wrote %o bytes', r);\n    if (r != b.length) {\n      done(new Error('write() failed: ' + r));\n    } else if (left) {\n      debug('still %o bytes left in this chunk', left.length);\n      write();\n    } else {\n      debug('done with this chunk');\n      done();\n    }\n  }\n\n  write();\n};\n\n/**\n * Called when this stream is pipe()d to from another readable stream.\n * If the \"sampleRate\", \"channels\", \"bitDepth\", and \"signed\" properties are\n * set, then they will be used over the currently set values.\n *\n * @api private\n */\n\nSpeaker.prototype._pipe = function (source) {\n  debug('_pipe()');\n  this._format(source);\n  source.once('format', this._format);\n};\n\n/**\n * Called when this stream is pipe()d to from another readable stream.\n * If the \"sampleRate\", \"channels\", \"bitDepth\", and \"signed\" properties are\n * set, then they will be used over the currently set values.\n *\n * @api private\n */\n\nSpeaker.prototype._unpipe = function (source) {\n  debug('_unpipe()');\n  source.removeListener('format', this._format);\n};\n\n/**\n * Emits a \"flush\" event and then calls the `.close()` function on\n * this Speaker instance.\n *\n * @api private\n */\n\nSpeaker.prototype._flush = function () {\n  debug('_flush()');\n  this.emit('flush');\n  this.close(false);\n};\n\n/**\n * Closes the audio backend. Normally this function will be called automatically\n * after the audio backend has finished playing the audio buffer through the\n * speakers.\n *\n * @param {Boolean} flush - if `false`, then don't call the `flush()` native binding call. Defaults to `true`.\n * @api public\n */\n\nSpeaker.prototype.close = function (flush) {\n  debug('close(%o)', flush);\n  if (this._closed) return debug('already closed...');\n\n  if (this.audio_handle) {\n    if (false !== flush) {\n      // TODO: async most likely…\n      debug('invoking flush() native binding');\n      binding.flush(this.audio_handle);\n    }\n\n    // TODO: async maybe?\n    debug('invoking close() native binding');\n    binding.close(this.audio_handle);\n    this.audio_handle = null;\n  } else {\n    debug('not invoking flush() or close() bindings since no `audio_handle`');\n  }\n\n  this._closed = true;\n  this.emit('close');\n};\n"]}