{"id":21487080,"url":"https://github.com/dtinth/nes-apu-worklet","last_synced_at":"2025-06-14T08:35:31.074Z","repository":{"id":57109955,"uuid":"265327096","full_name":"dtinth/nes-apu-worklet","owner":"dtinth","description":"NES APU exposed as an HTML5 AudioWorklet. Generate 8-bit sounds fom Web Audio API! Powered by nes-js’s APU code.","archived":false,"fork":false,"pushed_at":"2020-05-19T22:58:58.000Z","size":23,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T16:41:47.644Z","etag":null,"topics":["audio-worklet","chiptune-synthesizer","nes","web-audio-api"],"latest_commit_sha":null,"homepage":"https://dtinth.github.io/nes-apu-worklet","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dtinth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-19T18:15:32.000Z","updated_at":"2025-02-05T14:34:41.000Z","dependencies_parsed_at":"2022-08-20T20:20:55.487Z","dependency_job_id":null,"html_url":"https://github.com/dtinth/nes-apu-worklet","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fnes-apu-worklet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fnes-apu-worklet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fnes-apu-worklet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtinth%2Fnes-apu-worklet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dtinth","download_url":"https://codeload.github.com/dtinth/nes-apu-worklet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244014186,"owners_count":20383716,"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","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":["audio-worklet","chiptune-synthesizer","nes","web-audio-api"],"created_at":"2024-11-23T13:26:18.738Z","updated_at":"2025-03-17T10:14:26.083Z","avatar_url":"https://github.com/dtinth.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nes-apu-worklet\n\n[NES APU](https://wiki.nesdev.com/w/index.php/APU) exposed as HTML5 AudioWorklet. Generate 8-bit sounds fom Web Audio API! Powered by [Takahiro’s nes-js](https://github.com/takahirox/nes-js/blob/master/src/Apu.js)’s [APU](https://github.com/takahirox/nes-js/blob/master/src/Apu.js) code (imported directly!).\n\n### \u0026rarr; [Demo](https://dtinth.github.io/nes-apu-worklet)\n\n## Usage\n\n```js\nimport { NesApuNode } from 'https://cdn.jsdelivr.net/npm/@dtinth/nes-apu-worklet@1/nes-apu-node.js'\nconst context = new AudioContext()\n```\n\n### Add a worklet module to your `AudioContext`\n\n```js\nawait context.audioWorklet.addModule(\n  'https://cdn.jsdelivr.net/npm/@dtinth/nes-apu-worklet@1/nes-apu-worklet.js',\n)\n```\n\n### Create a `NesApuNode`\n\n```js\nlet apu = new NesApuNode(context)\napu.connect(context.destination)\n```\n\n### Schedule writes to the APU registers\n\n```js\n//                      * Status register\n//                      |            * Disable DMC channel\n//                      |            |* Disable Noise channel\n//                      |            ||* Disable Triangle channel\n//                      |            |||* Disable Pulse 2 channel\n//                      |            ||||* Enable Pulse 1 channel\napu.storeRegisterAtTime(0x4015, 0b00000001, context.currentTime)\n//                      * Pulse 1\n//                      |         ** Duty cycle 12.5%\n//                      |         ||* Disable length counter (do not silence notes automatically)\n//                      |         |||* Use constant volume (no decay)\n//                      |         ||||**** Volume 15/15\napu.storeRegisterAtTime(0x4000, 0b00111111)\n//                      |         ******** = Timer low = 251\napu.storeRegisterAtTime(0x4002, 0b11111011)\n//                      |         ***** Length counter (disabled)\n//                      |         |||||*** = Timer high = 1\napu.storeRegisterAtTime(0x4003, 0b00000001)\n//                      Timer = 1 * 256 + 251 = 507\n//                      Frequency = 1789773 [CPU speed hz] / (16 * (507 [Timer] + 1))\n//                                = 220.1984498031496 hz (~A below Middle C)\n```\n\n## API\n\n### `const apu = new NesApuNode(audioContext)`\n\nCreates a new NES APU node.\n\n### `apu.storeRegisterAtTime(address, value, time)`\n\nEnqueues a command to write a value to the APU registers. Check out [Nesdev wiki](https://wiki.nesdev.com/w/index.php/APU#Registers) for reference of each register.\n\n### `apu.port.onmessage = fn`\n\nBe notified when data is written to the APU register. `fn` is called with `event` object.\n\n- `event.data.address` — Register address\n- `event.data.value` — Register value\n- `event.data.time` — Audio time\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtinth%2Fnes-apu-worklet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtinth%2Fnes-apu-worklet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtinth%2Fnes-apu-worklet/lists"}