{"id":23330408,"url":"https://github.com/ain1084/audio-frame-buffer","last_synced_at":"2026-02-06T23:34:26.544Z","repository":{"id":261086659,"uuid":"883226887","full_name":"ain1084/audio-frame-buffer","owner":"ain1084","description":"A multi-channel ring buffer library for efficient audio frame buffering in Single Producer, Single Consumer (SPSC) scenarios. Optimized for audio data processing in multi-threaded environments.","archived":false,"fork":false,"pushed_at":"2024-11-26T13:10:14.000Z","size":118,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-31T15:34:49.965Z","etag":null,"topics":["audio-processing","ring-buffer","typescript","web-audio"],"latest_commit_sha":null,"homepage":"https://ain1084.github.io/audio-frame-buffer/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ain1084.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-04T15:40:24.000Z","updated_at":"2024-11-26T13:09:56.000Z","dependencies_parsed_at":"2025-07-23T21:49:13.699Z","dependency_job_id":null,"html_url":"https://github.com/ain1084/audio-frame-buffer","commit_stats":null,"previous_names":["ain1084/audio-frame-buffer"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ain1084/audio-frame-buffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ain1084%2Faudio-frame-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ain1084%2Faudio-frame-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ain1084%2Faudio-frame-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ain1084%2Faudio-frame-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ain1084","download_url":"https://codeload.github.com/ain1084/audio-frame-buffer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ain1084%2Faudio-frame-buffer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29180487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T23:15:33.022Z","status":"ssl_error","status_checked_at":"2026-02-06T23:15:09.128Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["audio-processing","ring-buffer","typescript","web-audio"],"created_at":"2024-12-20T22:17:37.275Z","updated_at":"2026-02-06T23:34:26.530Z","avatar_url":"https://github.com/ain1084.png","language":"TypeScript","readme":"# Audio Frame Buffer\n\n[![npm version](https://badge.fury.io/js/@ain1084%2Faudio-frame-buffer.svg)](https://badge.fury.io/js/@ain1084%2Faudio-frame-buffer)\n[![CI](https://github.com/ain1084/audio-frame-buffer/actions/workflows/ci.yml/badge.svg)](https://github.com/ain1084/audio-frame-buffer/actions?query=workflow%3Aci)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n`Audio Frame Buffer` is a multi-channel ring buffer library designed to handle audio frame data. This library is optimized for audio data buffering and is specifically designed for Single Producer, Single Consumer (SPSC) scenarios.\n\n## Features\n\n- **Multi-Channel Support**: Handles multi-channel audio data and allows buffer operations on a frame-by-frame basis.\n- **Thread-Safe Sharing**: Enables efficient audio processing in multithreaded environments by safely sharing data across threads through the `FrameBufferContext`.\n\n## Installation\n\n```bash\nnpm install @ain1084/audio-frame-buffer\n```\n\n## Basic Usage\n\nIn this example, we demonstrate how to:\n\n1. Create an `FrameBufferContext`, which contains the shared configuration and buffer used for audio processing.\n2. Initialize `FrameBufferReader` and `FrameBufferWriter` instances for reading and writing frame data.\n3. Use `read` and `write` methods with callbacks to process and store audio frames in blocks.\n\n### Creating an FrameBufferContext\n\n```typescript\nimport { createFrameBufferContext, FrameBufferParams } from '@ain1084/audio-frame-buffer'\n\nconst params: FrameBufferParams = {\n  frameCount: 1024,\n  channelCount: 2\n}\n\nconst context = createFrameBufferContext(params)\n```\n\n### Using FrameBufferReader / FrameBufferWriter\n\n```typescript\nimport { FrameBufferReader, FrameBufferWriter } from '@ain1084/audio-frame-buffer'\n\nconst reader = new FrameBufferReader(context)\nconst writer = new FrameBufferWriter(context)\n\n// Reading data\nconst framesRead = reader.read((segment, offset) =\u003e {\n  // `segment` provides methods to access frame data in a structured way.\n  for (let frame = 0; frame \u003c segment.frameCount; frame++) {\n    for (let channel = 0; channel \u003c segment.channels; channel++) {\n      const sample = segment.get(frame, channel)\n      // Process the sample as needed\n    }\n  }\n  return segment.frameCount // Return the number of frames processed\n})\n\n// Writing data\nconst framesWritten = writer.write((segment, offset) =\u003e {\n  // Write data to each frame and channel\n  for (let frame = 0; frame \u003c segment.frameCount; frame++) {\n    for (let channel = 0; channel \u003c segment.channels; channel++) {\n      segment.set(frame, channel, offset + frame * segment.channels + channel)\n    }\n  }\n  return segment.frameCount // Return the number of frames written\n})\n```\n\n### Differences from a Standard Ring Buffer\n\nUnlike standard ring buffers, which typically use `push/pop` operations for single-element access, `Audio Frame Buffer` is designed to read and write data **in blocks (multiple frames) using a callback function**. This design choice offers specific benefits for handling continuous data streams, like audio data:\n\n- **Efficiency**: Block-based processing reduces the overhead associated with single-frame operations.\n- **Real-Time Processing**: In audio processing, handling data in larger segments improves real-time performance.\n- **Seamless Wrapping**: When the ring buffer wraps around, readable/writable segments may be split into two parts within the buffer. The `read` and `write` operations handle this division automatically and return contiguous subarrays, so the user can access the segments without additional complexity.\n\n## API Documentation\n\nFor more detailed documentation on the API, including parameter descriptions and usage details, please refer to the [API Documentation](https://ain1084.github.io/audio-frame-buffer).\n\n## Important Notes\n\n- **SPSC**: This package is designed for Single Producer, Single Consumer (SPSC) use. Only one instance of each `Reader` and `Writer` should be created; multiple instances may result in unexpected behavior.\n- **Thread Safety**: `FrameBufferContext` uses `SharedArrayBuffer` to safely share data across multiple threads.\n- **Browser Requirements (COOP/COEP)**: To use `SharedArrayBuffer`, the following HTTP headers must be set:\n\n  - **COOP (Cross-Origin-Opener-Policy)**:\n\n    ```text\n    Cross-Origin-Opener-Policy: same-origin\n    ```\n\n  - **COEP (Cross-Origin-Embedder-Policy)**:\n\n    ```text\n    Cross-Origin-Embedder-Policy: require-corp\n    ```\n\n  These settings enable `SharedArrayBuffer` and allow for safe multi-threaded data sharing. For details, refer to the [MDN Web Docs - SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer).\n\n## Detailed API Reference\n\nFor a full API reference, please see the [documentation here](https://ain1084.github.io/audio-frame-buffer).\n\n## Contribution\n\nContributions are welcome! Please open an issue or submit a pull request on GitHub.\n\n## License\n\nThis project is licensed under multiple licenses:\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)  [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nYou can choose either license depending on your project needs.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fain1084%2Faudio-frame-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fain1084%2Faudio-frame-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fain1084%2Faudio-frame-buffer/lists"}