{"id":17445998,"url":"https://github.com/jamen/audio-decode-wasm","last_synced_at":"2025-09-10T23:42:34.937Z","repository":{"id":57153256,"uuid":"112649193","full_name":"jamen/audio-decode-wasm","owner":"jamen","description":"Decode streams of audio with WebAssembly.","archived":false,"fork":false,"pushed_at":"2018-02-19T09:11:45.000Z","size":974,"stargazers_count":26,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-09T01:48:26.344Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamen.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-30T19:03:40.000Z","updated_at":"2023-03-20T19:09:46.000Z","dependencies_parsed_at":"2022-09-06T11:21:24.946Z","dependency_job_id":null,"html_url":"https://github.com/jamen/audio-decode-wasm","commit_stats":null,"previous_names":["audiojs/audio-decode-wasm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jamen/audio-decode-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Faudio-decode-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Faudio-decode-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Faudio-decode-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Faudio-decode-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamen","download_url":"https://codeload.github.com/jamen/audio-decode-wasm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Faudio-decode-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274549292,"owners_count":25306358,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-17T18:19:58.097Z","updated_at":"2025-09-10T23:42:34.894Z","avatar_url":"https://github.com/jamen.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# audio-decode-wasm ![expirmental](https://img.shields.io/badge/stability-experimental-red.svg)\n\n**Note:** This doesn't work quite yet, but the structure is drafted out.\n\nA stream that decodes ArrayBuffers into [AudioBuffers](https://github.com/audiojs/audio-buffer).  The decoders are made in [WebAssembly](https://webassembly.org/) so they are portable (Node.js and browser) and decent speed.\n\n```js\nconst decoder = require('audio-decode-wasm')\n\n// Obtain codec module and initialize decoder:\nconst mod = await fetch('wav.wasm').then(req =\u003e WebAssembly.compileStreaming(res))\nconst decode = await decoder(mod)\n\n// Decode ArrayBuffers:\ndecode(arrayBuf, (err, audioBuf) =\u003e {\n  // ...\n})\n```\n\n## Install\n\n```sh\nnpm i -D audio-decode-wasm\n```\n\n## Usage\n\n### `decoder(mod) -\u003e Promise\u003cdecode\u003e`\n\nInitializes a decoder from a given [`WebAssembly.Module`].  The available ones\ncan be seen in [`src/`](src/).\n\n```js\nconst mod = new WebAssembly.Module(...)\n\ndecoder(mod).then(decode =\u003e {\n  // ...\n})\n```\n\n### `decode(arrayBuffer, done)`\n\nDecodes `arrayBuffer` and calls `done(err, audioBuffer)` when finished.\n\nTo stop or \"reset\" the stream send `decode(null)`.  \n\n```js\nconst decode = await decoder(mod)\n\nfetch('foo.wav')\n.then(res =\u003e res.arrayBuffer())\n.then(buf =\u003e {\n  decode(buf, (err, audio) =\u003e {\n    // ...\n  })\n})\n```\n\n### Using multiple modules\n\n```js\nPromise.all([\n  decoder(...),\n  decoder(...)  \n]).then(([ wav, mp3, ... ]) =\u003e {\n  // ...\n})\n```\n\n### How does it work?\n\nThe decoders are wrote in C and compiled with [Emscripten](https://github.com/kripken/emscripten).  The code is more restricted than a normal Emscripten runtime so it's cheap to load.\n\nEach C modules has the functions\n\n```c\nContext* open(unsigned char* input, float* output)\nvoid process(Context* context, int amount)\n```\n\nFrom JS you can create the context with `_open(input, output)`, where the parameters and return values are pointers on WebAssembly's memory, which JS can access and modify.\n\nThe `Context` from C looks like:\n\n```c\ntypedef struct {\n  unsigned char* input;\n  float* output;\n  uint16_t number_of_channels;\n  uint32_t sample_rate;\n  unsigned char params;\n  // ...\n} Context;\n```\n\nTo construct an `AudioBuffer` you need `numberOfChannels` and `sampleRate`, so JS imports a `set_params(int, int)` function which C can call.\n\nThe stream routine would look like this:\n\n 1. JS copies `ArrayBuffer` into WebAssembly's input buffer.\n 2. WebAssembly decodes it to planar float values on the output buffer.\n 3. JS copies the output buffer as `Float32Array`s into an `AudioBuffer`.\n 4. Repeat until stream is done.\n\n## Building\n\nRequires [Emscripten](https://github.com/kripken/emscripten), [Binaryen](https://github.com/webassembly), and [WABT](https://github.com/webassembly/wabt).  Then, using `make`:\n\n- `make` to create `dist/`\n- `make debug` to produce `dist/*.wat`\n- `make clean` to remove output\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Faudio-decode-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamen%2Faudio-decode-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Faudio-decode-wasm/lists"}