{"_id":"@ain1084/audio-frame-buffer","_rev":"2-d8266aed6c8f12c0eeede96231079e5f","name":"@ain1084/audio-frame-buffer","dist-tags":{"latest":"0.2.0"},"versions":{"0.0.1":{"name":"@ain1084/audio-frame-buffer","version":"0.0.1","keywords":["audio","ring-buffer","audio-frame","multi-channel","buffer","typescript"],"author":{"name":"Seiji Ainoguchi","email":"seiji.ainoguchi@gmail.com"},"license":"(MIT OR Apache-2.0)","_id":"@ain1084/audio-frame-buffer@0.0.1","maintainers":[{"name":"ain1084","email":"seiji.ainoguchi@gmail.com"}],"homepage":"https://github.com/ain1084/audio-frame-buffer#readme","bugs":{"url":"https://github.com/ain1084/audio-frame-buffer/issues"},"dist":{"shasum":"e049383ce87627206bd1da8ae5666d5b17fc7ae2","tarball":"https://registry.npmjs.org/@ain1084/audio-frame-buffer/-/audio-frame-buffer-0.0.1.tgz","fileCount":35,"integrity":"sha512-uzqcRJAffeUluTrJxAMehKikeJhB3JC7+bk485jvXzAjAD2QawOzaXZOz2jX6USbUa40/pyScQWNdOQHUQtL/Q==","signatures":[{"sig":"MEUCIEwglIB36sSVYUcp6rsUhFojiGF0dTRNjsiN2Zl4DAg1AiEAg71PzZoIZf6uL5A1crhPvvGbdp1B/MDv05cbe4HvUpE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":73045},"types":"dist/index.d.ts","module":"dist/index.js","gitHead":"1f8f777ee7b18130252d59b07cebf56ee14c17ae","scripts":{"docs":"typedoc","lint":"eslint .","test":"vitest","build":"tsc","clean":"rm -rf dist docs","test:watch":"vitest --watch","prepublishOnly":"npm run clean && npm run build"},"_npmUser":{"name":"ain1084","email":"seiji.ainoguchi@gmail.com"},"repository":{"url":"git+https://github.com/ain1084/audio-frame-buffer.git","type":"git"},"_npmVersion":"10.8.3","description":"A specialized ring buffer for handling audio frame data, designed for multi-channel audio processing.","directories":{},"_nodeVersion":"22.9.0","dependencies":{"@ain1084/array-buffer-partitioner":"^0.0.4"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^9.14.0","vitest":"^2.1.4","typedoc":"^0.26.11","typescript":"^5.6.3","typescript-eslint":"^8.12.2","@stylistic/eslint-plugin":"^2.10.1","@typescript-eslint/parser":"^8.12.2"},"_npmOperationalInternal":{"tmp":"tmp/audio-frame-buffer_0.0.1_1730738534060_0.39750187338689336","host":"s3://npm-registry-packages"}},"0.1.0":{"name":"@ain1084/audio-frame-buffer","version":"0.1.0","keywords":["audio","ring-buffer","audio-frame","multi-channel","buffer","typescript"],"author":{"name":"Seiji Ainoguchi","email":"seiji.ainoguchi@gmail.com"},"license":"(MIT OR Apache-2.0)","_id":"@ain1084/audio-frame-buffer@0.1.0","maintainers":[{"name":"ain1084","email":"seiji.ainoguchi@gmail.com"}],"homepage":"https://github.com/ain1084/audio-frame-buffer#readme","bugs":{"url":"https://github.com/ain1084/audio-frame-buffer/issues"},"dist":{"shasum":"7b0350318d43c181aeef44dca760ed7c5de58f1b","tarball":"https://registry.npmjs.org/@ain1084/audio-frame-buffer/-/audio-frame-buffer-0.1.0.tgz","fileCount":35,"integrity":"sha512-e9G/4mn7lTIpj39utVqLPlk4+OAg4LAFyB7YMK9hatrvAD2cFbeljUuh1XgDgoztRPEiCPTlDQtDfSjwG5L0Mw==","signatures":[{"sig":"MEUCIF7zsIZbYRRPx0RpECCPpsWxNV/JjVsWBYQe/Xn2G8jEAiEA5QnQthMg9aqHGekV7dx0GnAywY02tM+kPO/cDGG20cY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":73494},"types":"dist/index.d.ts","module":"dist/index.js","gitHead":"8db35d65b4947e59fe1e4946eb782c3e440f08a3","scripts":{"docs":"typedoc","lint":"eslint .","test":"vitest","build":"tsc","clean":"rm -rf dist docs","test:watch":"vitest --watch","prepublishOnly":"npm run clean && npm run build"},"_npmUser":{"name":"ain1084","email":"seiji.ainoguchi@gmail.com"},"repository":{"url":"git+https://github.com/ain1084/audio-frame-buffer.git","type":"git"},"_npmVersion":"10.8.3","description":"A specialized ring buffer for handling audio frame data, designed for multi-channel audio processing.","directories":{},"_nodeVersion":"22.9.0","dependencies":{"@ain1084/array-buffer-partitioner":"^0.0.4"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^9.14.0","vitest":"^2.1.4","typedoc":"^0.26.11","typescript":"^5.6.3","typescript-eslint":"^8.12.2","@stylistic/eslint-plugin":"^2.10.1","@typescript-eslint/parser":"^8.12.2"},"_npmOperationalInternal":{"tmp":"tmp/audio-frame-buffer_0.1.0_1730762521024_0.46578510569531395","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@ain1084/audio-frame-buffer","version":"0.2.0","description":"A specialized ring buffer for handling audio frame data, designed for multi-channel audio processing.","module":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","clean":"rm -rf dist docs","prepublishOnly":"npm run clean && npm run build","test":"vitest","test:watch":"vitest --watch","docs":"typedoc","lint":"eslint ."},"keywords":["audio","ring-buffer","audio-frame","multi-channel","buffer","typescript"],"author":{"name":"Seiji Ainoguchi","email":"seiji.ainoguchi@gmail.com"},"license":"(MIT OR Apache-2.0)","repository":{"type":"git","url":"git+https://github.com/ain1084/audio-frame-buffer.git"},"bugs":{"url":"https://github.com/ain1084/audio-frame-buffer/issues"},"homepage":"https://github.com/ain1084/audio-frame-buffer#readme","dependencies":{"@ain1084/array-buffer-partitioner":"^0.0.4"},"devDependencies":{"@stylistic/eslint-plugin":"^2.10.1","@typescript-eslint/parser":"^8.13.0","eslint":"^9.14.0","typedoc":"^0.26.11","typescript":"^5.6.3","typescript-eslint":"^8.13.0","vitest":"^2.1.4"},"_id":"@ain1084/audio-frame-buffer@0.2.0","gitHead":"9c0bc94bf9397eaba881ff0d08bd798fdd7a918d","_nodeVersion":"22.9.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-N+XGUoGVk1OefB3oTEZG157X1PMTstkYRoQHSGANDsFIkvgreohTY89qZEpO0It4Taw5xvcRFsN35YJa8xib0g==","shasum":"e4effd02d2eacea468ea7ef1c9ebf6d5ac235ea5","tarball":"https://registry.npmjs.org/@ain1084/audio-frame-buffer/-/audio-frame-buffer-0.2.0.tgz","fileCount":31,"unpackedSize":72329,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIARIsJHaBr6RWjM2jlaYj3Vu6WRizVtiinw+iUmQDOq5AiEA2fF/wkeeHr7q2pe+zlG00eZ6UH2TCxc68ClXgXi3wJ8="}]},"_npmUser":{"name":"ain1084","email":"seiji.ainoguchi@gmail.com"},"directories":{},"maintainers":[{"name":"ain1084","email":"seiji.ainoguchi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/audio-frame-buffer_0.2.0_1730913138454_0.8925792812762947"},"_hasShrinkwrap":false}},"time":{"created":"2024-11-04T16:42:13.930Z","modified":"2024-11-06T17:12:18.847Z","0.0.1":"2024-11-04T16:42:14.289Z","0.1.0":"2024-11-04T23:22:01.201Z","0.2.0":"2024-11-06T17:12:18.673Z"},"bugs":{"url":"https://github.com/ain1084/audio-frame-buffer/issues"},"author":{"name":"Seiji Ainoguchi","email":"seiji.ainoguchi@gmail.com"},"license":"(MIT OR Apache-2.0)","homepage":"https://github.com/ain1084/audio-frame-buffer#readme","keywords":["audio","ring-buffer","audio-frame","multi-channel","buffer","typescript"],"repository":{"type":"git","url":"git+https://github.com/ain1084/audio-frame-buffer.git"},"description":"A specialized ring buffer for handling audio frame data, designed for multi-channel audio processing.","maintainers":[{"name":"ain1084","email":"seiji.ainoguchi@gmail.com"}],"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) => {\n  // `segment` provides methods to access frame data in a structured way.\n  for (let frame = 0; frame < segment.frameCount; frame++) {\n    for (let channel = 0; channel < 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) => {\n  // Write data to each frame and channel\n  for (let frame = 0; frame < segment.frameCount; frame++) {\n    for (let channel = 0; channel < 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.","readmeFilename":"README.md"}