{"_id":"@drippy-music/opus-stream-decoder","_rev":"5-c9b82f6c9a8989ef4e38f94d88f69fa2","time":{"1.2.6":"2020-07-19T23:05:36.772Z","created":"2020-07-20T22:14:22.554Z","1.3.0":"2020-07-20T22:14:22.976Z","modified":"2022-04-05T05:39:51.306Z","1.3.1":"2020-07-21T00:25:49.148Z"},"name":"@drippy-music/opus-stream-decoder","dist-tags":{"latest":"1.3.1"},"versions":{"1.3.0":{"name":"@drippy-music/opus-stream-decoder","version":"1.3.0","description":"Decode Opus audio streams immediately in chunks","main":"dist/opus-stream-decoder.js","repository":{"type":"git","url":"git+https://github.com/AnthumChris/opus-stream-decoder.git"},"keywords":["Opus","audio","decoder","stream","streams","libopus","libopusfile","Ogg Opus","WebAssembly","Wasm"],"author":{"name":"AnthumChris"},"license":"MIT","bugs":{"url":"https://github.com/AnthumChris/opus-stream-decoder/issues"},"homepage":"https://github.com/AnthumChris/opus-stream-decoder#readme","gitHead":"4e93f411ad0ab5199f1efd482cc313b42da9a2e3","_id":"@drippy-music/opus-stream-decoder@1.3.0","_nodeVersion":"12.18.2","_npmVersion":"6.14.6","dist":{"integrity":"sha512-zmbXwTZ0bgtwqKU+3RRFE6bUHOcmgvCKeHI84fdIgJShhYMI6Fb7WBRRrZ41f215KMm1XyXoOAsQ+1Ob6aHfLw==","shasum":"ab896bc1bc20d39771096ca42b0fd0a1a1a84994","tarball":"https://registry.npmjs.org/@drippy-music/opus-stream-decoder/-/opus-stream-decoder-1.3.0.tgz","fileCount":8,"unpackedSize":283112,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfFhc/CRA9TVsSAnZWagAAFfgP/jsvwjWHepPpJM6vv/iV\nPsx3O2h4QJD8GFliixHy4hvb8GVvpGngKSc7GZe3tvDyVQ4Rz0K7ssXEDLzW\nNwaMZTyRb1ufP/1Q8C/G1Cu3Pa1FwkfbEItE1yfJGNDo+Mk2Zvp6C7P7xTTK\nyaDGBYeQa5Xjk/sLQNPxfr2s9OSJlDWZFIIEk0EiejKSLVAqjRWcxPj1pne+\nI953Xptd9HRXAkK/qm6nfkVeDfrNIN5o7Y1Ciyf+ota5oEMQWxoOXHOxivuE\n48pkBlHZUb1vryBbBNK9CJtqI6gbmURLvgj+ktKVIzn6HJQMNj7iPZdhOiqj\nDseR1j4vmgxUpbGNDz5B0cZbaPt1hP+v8qRnKotZkttW5yaRiXiE7j6FrKhK\nQv/zTheZuNX+zhTpisVs6qfRkLhHb1slKGX/MjEd6CzN1iFSQLdReORt9uRk\nFZMnMxy949QUT1lk3f7JFvFTbLY1WLgYuP//O7Wg4oIYBKWvV0BWmW9iGKYb\n+nmxkmw3/xwrHXRAqkFjew/a2d2zMyJvgsLwMk9wCJDK4MgKD6TFLgJPFAg3\n5eR5uLSHGf3YvbpaDwCpG64jb3NNUFxmCzFInM+5lyx3805leZ99ZBPHSMH4\nNNI7nP1trMeBxySMjq92fhWBXCDy8k7IIzekuhAQal6eN5zUhnae6+fxAFH5\n+bJb\r\n=Q6Z8\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFD+kX2vRLCgFq5CXD7a57H+/9PaDZjv22oaf86eQYjfAiEAhV/rUYMGTBuowlhg3P5rvEC3vJW8c0bHJ00abOQXw4A="}]},"maintainers":[{"name":"vitormac","email":"vitormac3@gmail.com"}],"_npmUser":{"name":"vitormac","email":"vitormac3@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/opus-stream-decoder_1.3.0_1595283262799_0.4956789452889905"},"_hasShrinkwrap":false},"1.3.1":{"name":"@drippy-music/opus-stream-decoder","version":"1.3.1","description":"Decode Opus audio streams immediately in chunks","main":"dist/opus-stream-decoder.js","repository":{"type":"git","url":"git+https://github.com/AnthumChris/opus-stream-decoder.git"},"keywords":["Opus","audio","decoder","stream","streams","libopus","libopusfile","Ogg Opus","WebAssembly","Wasm"],"author":{"name":"AnthumChris"},"license":"MIT","bugs":{"url":"https://github.com/AnthumChris/opus-stream-decoder/issues"},"homepage":"https://github.com/AnthumChris/opus-stream-decoder#readme","gitHead":"84ee87bf1d79e9f640d588e8d138811f7eb4f37a","_id":"@drippy-music/opus-stream-decoder@1.3.1","_nodeVersion":"12.18.2","_npmVersion":"6.14.6","dist":{"integrity":"sha512-0wyy1d7H2XOm0+g2aBaWYx089oxfM/qJyTP1N88/1m0LzWa8CNDmZofiDmHyFf6RRhY3+QRF8U9K2Br6NHX7tg==","shasum":"ee0a3f50c12a919b478fc38e477c86b708eb18d3","tarball":"https://registry.npmjs.org/@drippy-music/opus-stream-decoder/-/opus-stream-decoder-1.3.1.tgz","fileCount":5,"unpackedSize":277890,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfFjYNCRA9TVsSAnZWagAAhg4QAIHJLgJY3n4yRI0fC5X6\n/nO9p3wcJrYe9quayO61lBS5ozENrOs2AGrR/3kJhIGXoU6+PaVmTwsLhgay\nBJrtIcEwNxDA4om1dUKGwIy3qgUp5Ge+NvYNd0zeo1mhNeIZW3f2f/u4x7De\ny4F+b2FVkbgS8wncYgPkhFcmgWnbU+W2lCiThOVrvVeq33XEK5Nmcn2NVl0U\nFpFH3crRSJXEQrBfaYGjUMQgWFxp/6NPK7Nq292G/3O4eIwVv5+fPXVoG0x0\nlSLQnTVt0B9sezyfC/KLzD3QgEBK0T//85oK5xPepBLxO6Nx4Zw6yn9gLnpw\nl/xWCj5iPxaDtQdUwDdo3zmP3SAVyLce0vWXHnppxZEPv0K1qTK6s5uUWffo\nGLvWv72lf2wY2HOVxfViIWCBj9o96o+2Wf3eHtniedIK6rfkDpA+F1dmm2pf\nvdS7TvcZnuNVmwdTIlv+wCJnrFzP9QO0l+8M+Wzg6DG11pasFu6X1cST4pn+\n+ZQphd2e/yTvRU7XmZQ/B6+xKfpj5bWGMaUx7+hFTTIPraIfUiRMBSilTwHM\nhca7aU40QxDpJZj72ERSzU9wQhrKJP0uGc4lH5q6V+dDIJ4AOFg/QSaf59gX\nM3G/QQDDjftbdNoDCHY3HidPH+3ZgToa+O/AWGdZWabtMLR9An7/XuHqrsMG\nzNw+\r\n=bPT2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCZ5ijN+US97aTjy3qORzNu/E7v7PBDPwPN9Dx2hdDaKgIgJpL2pAN8UhoUPQvFw/fbAO0qDH99CiTewjwpdDg9wQw="}]},"maintainers":[{"name":"vitormac","email":"vitormac3@gmail.com"}],"_npmUser":{"name":"vitormac","email":"vitormac3@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/opus-stream-decoder_1.3.1_1595291148821_0.48464749431057985"},"_hasShrinkwrap":false}},"maintainers":[{"name":"vitormac","email":"vitormac3@gmail.com"}],"description":"Decode Opus audio streams immediately in chunks","homepage":"https://github.com/AnthumChris/opus-stream-decoder#readme","keywords":["Opus","audio","decoder","stream","streams","libopus","libopusfile","Ogg Opus","WebAssembly","Wasm"],"repository":{"type":"git","url":"git+https://github.com/AnthumChris/opus-stream-decoder.git"},"author":{"name":"AnthumChris"},"bugs":{"url":"https://github.com/AnthumChris/opus-stream-decoder/issues"},"license":"MIT","readme":"`OpusStreamDecoder` is an Emscripten JavaScript WebAssembly (Wasm) library for immediately decoding Ogg Opus audio streams (URLs or files) in chunks without waiting for the complete file to download, copy, or read. [`libopusfile`](https://opus-codec.org/docs/opusfile_api-0.7/index.html) is the underlying C library used for decoding.  `OpusStreamDecoder` provides a lightweight JavaScript API for decoding Opus audio streams at near-native speeds.\n\n_Note: This repository was forked from [AnthumChris/fetch-stream-audio](https://github.com/AnthumChris/fetch-stream-audio) to decouple `OpusStreamDecoder` as a standalone Wasm decoder.  It will be integrated back into demo as a git submodule for [fetch-stream-audio #4](https://github.com/AnthumChris/fetch-stream-audio/issues/4)._\n\n# Usage\n\nPre-compiled binaries and full examples are included in the `dist/` folder.  The `OpusStreamDecoder` API was designed to be simple and the pseudocode below explains its complete usage:\n\nIf using a front-end build system, you can obtain `OpusStreamDecoder` via `require` or `import` syntaxes:\n\n```js\nconst { OpusStreamDecoder } = require('opus-stream-decoder');\nimport { OpusStreamDecoder } from 'opus-stream-decoder';\n```\n\nOtherwise, include the script before you instantiate `OpusStreamDecoder`.\n\n```javascript\n<script src=\"opus-stream-decoder.js\"></script>\n<script>\n  // instantiate with onDecode callback that fires when OggOpusFile data is decoded\n  const decoder = new OpusStreamDecoder({onDecode});\n\n  // Loop through your Opusdata callingdecode() multiple times. Pass a Uint8Array\n  try {\n    while(...) {\n      decoder.ready.then(_ => decoder.decode(UINT8_DATA_TO_DECODE));\n    }\n  } catch (e) {\n    decoder.ready.then(_ => decoder.free());\n  }\n\n  // free up the decoder's memory in WebAssembly (also resets decoder for reuse)\n  decoder.ready.then(_ => decoder.free());\n\n  // after free() is called, you could reuse the decoder for another file\n  try { ... decoder.ready.then(_ => decoder.decode(UINT8_DATA_TO_DECODE) } ...\n\n  /* Receives decoded Float32Array PCM audio in left/right arrays.\n   * sampleRate is always 48000 and both channels would always contain data if\n   * samplesDecoded > 0.  Mono Opus files would decoded identically into both\n   * left/right channels and multichannel Opus files would be downmixed to 2 channels.\n   */\n  function onDecode({left, right, samplesDecoded, sampleRate}) {\n    console.log(`Decoded ${samplesDecoded} samples`);\n    // play back the left/right audio, write to a file, etc\n  }\n</script>\n```\n\nAfter instantiating `OpusStreamDecoder`, `decode()` should be called repeatedly until you're done reading the stream.  You __must__ start decoding from the beginning of the file.  Otherwise, a valid Ogg Opus file will not be discovered by `libopusfile` for decoding.  `decoder.ready` is a Promise that resolves once the underlying WebAssembly module is fetched from the network and instantiated, so ensure you always wait for it to resolve.  `free()` should be called when done decoding, when `decode()` throws an error, or if you wish to \"reset\" the decoder and begin decoding a new file with the same instance.  `free()` releases the allocated Wasm memory.\n\n#### Performance\nTo achieve optimum decoding performance, `OpusStreamDecoder` should ideally be run in a Web Worker to keep CPU decoding computations on a sepearate browser thread. (_TODO: provide web worker example._)\n\nAdditionally, `onDecode` will be called thousands of times while decoding Opus files. Keep your `onDecode` callbacks lean.  The multiple calls result intentionally because of Opus' unmatched low-latency decoding advantage ([read more](https://opus-codec.org/comparison/#bitratelatency-comparison))—audio is decoded as soon as possible .  For example, a 60-second Opus file encoded with a 20ms frame/packet size would yield 3,000 `onDecode` calls (60 * 1000 / 20), because the underlying `libopusfile` C decoding function [`op_read_float_stereo()`](https://opus-codec.org/docs/opusfile_api-0.7/group__stream__decoding.html#ga9736f96563500c0978f56f0fd6bdad83) currently decodes one frame at a time during my tests.\n\n# Building\n\nThe `dist/` folder will contain all required files, tests, and examples after building.\n\n### Download Ogg, Opus, and Opusfile C libraries:\n```\n$ git submodule update --init\n```\n\n_TODO: consider moving this to Makefile_\n\n### Install Emscripten\n\nEmscripten is used to compile the C libraries to be compatible with WebAssembly.  This repo was tested with 1.39.5.\n\n* [Emscripten Installation Instructions](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#installation-instructions)\n\n### Run the Build\n\n```\n$ make clean dist\n```\n\nThe Emscripten module builds in a few seconds, but most of the work will be spent configuring the dependencies `libopus`, `libogg`, and `libopusfile`. You may see the warnings (not errors) below, which don't prevent the build from succeeding.  It is not known whether these warnings adversly affect runtime use.\n\n- Don't have the functions lrint() and lrintf ()\n- Replacing these functions with a standard C cast\n- implicit conversion from 'unsigned int' to 'float'\n\n\n### Build Errors\n\n#### Error: \"autoreconf: command not found\"\n\n`$ brew install automake`\n\n#### \"./autogen.sh: No such file or directory\"\n\n`$ brew install autogen`\n\n# Tests & Examples\n\nTwo tests exist that will decode an Ogg Opus File with `OpusStreamDecoder`.  Both tests output \"decoded _N_ samples.\" on success.\n\n### NodeJS Test\n\nThis test writes two decoded left/right PCM audio data to files in `tmp/`. [Install NodeJS](https://nodejs.org/en/download/) and run:\n```\n$ make test-wasm-module\n```\n\n### HTML Browser Test\n\nThis test uses `fetch()` to decode a URL file stream in chunks.  Serve the `dist/` folder from a web server and open `test-opus-stream-decoder.html` in the browser.  HTTP/HTTPS schemes are required for Wasm to load—opening it directly with `file://` probably won't work.\n\nYou can also run `SimpleHTTPServer` and navigate to http://localhost:8000/test-opus-stream-decoder.html\n```\n$ cd dist\n$ python -m SimpleHTTPServer 8000\n```\n\n# Developing\n\n### Emscripten Wasm Module\n\nSee files `src/*.{js,html}` and use `$ make` and `$ make clean` to build into `dist/`\n\n### `OpusChunkDecoder` C interface\n\nSee C files `src/opus_chunkdecoder*` and use `$ make native-decode-test`, which allows you to compile and test almost instantly.  `native-decode-test` is a fast workflow that ensures things work properly independently of  Emscripten and Wasm before you integrate it.\n\nYou'll need to install `libopusfile` binaries natively on your system (on Mac use `$ brew install opusfile`).  Then, declare environment variables with the locations of the installed `libopusfile` dependencies required by `native-decode-test` before running:\n```\n$ export OPUS_DIR=/usr/local/Cellar/opus/1.2.1\n$ export OPUSFILE_DIR=/usr/local/Cellar/opusfile/0.10\n$ make native-decode-test\n```\n\nNote: If you see error \"fatal error: 'stdarg.h' file not found\", try running from a new terminal window that does not have Emscripten initialized.\n\n\n","readmeFilename":"README.md"}