@ain1084/audio-worklet-stream 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +23 -16
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -129,9 +129,6 @@ export default defineNuxtConfig({
129
129
 
130
130
  ## Usage
131
131
 
132
- <details>
133
- <summary>Click to expand usage details</summary>
134
-
135
132
  ### Overview
136
133
 
137
134
  This library continuously plays audio sample frames using AudioWorkletNode. The audio sample frames need to be supplied externally via a ring buffer. The library provides functionality to retrieve the number of written and read (played) frames and allows stopping playback at a specified frame.
@@ -161,34 +158,40 @@ const clicked = async () => {
161
158
 
162
159
  As outlined in the overview, OutputStreamNode requires external audio samples. These samples must be written to a ring buffer, and there are several methods to achieve this.
163
160
 
161
+ **Note:** The diagrams are simplified for ease of understanding and may differ from the actual implementation.
162
+
164
163
  #### Manual
165
164
 
166
- - This method involves manually writing to the ring buffer. Use the `OutputStreamFactory.createManualBufferNode` method, specifying the number of channels and frames.
167
- - When the OutputStreamNode is first constructed, the ring buffer is empty. Typically, you need to write to the ring buffer before starting playback. While the node is playing, you must continue writing to the ring buffer to prevent audio frame depletion.
165
+ ![manual](./images/manual.drawio.svg)
166
+
167
+ - This method involves manually writing to the ring buffer. Use the `OutputStreamFactory.createManualBufferNode` method, specifying the number of channels and frames to create an `OutputStreamNode`. The `FrameBufferWriter`, used for writing to the ring buffer, is also returned by this method along with the `OutputStreamNode`.
168
+ - When the `OutputStreamNode` is first constructed, the ring buffer is empty. You must write to the buffer before starting playback to avoid audio gaps. While the node is playing, you must continue writing to the ring buffer to prevent audio frame depletion (which would cause silence).
168
169
  - If the audio frames run out, the stream playback continues with the node outputting silence.
169
- - To stop the stream playback, call the `stop()` method of OutputStreamNode. You can specify the frame at which to stop playback. If you want to play all the written frames, you can specify the total number of written frames, which can be obtained via the FrameBufferWriter.
170
+ - To stop the stream playback, call the `stop()` method of `OutputStreamNode`. You can specify the frame at which to stop playback. For example, calling stop() with a frame count stops playback at that exact frame. If you want to play all the written frames, you can specify the total number of written frames, which can be obtained via the `FrameBufferWriter`.
170
171
 
171
172
  #### Timed
172
173
 
173
- - This method writes to the ring buffer using a timer initiated on the UI thread. Create it using the `OutputStreamFactory.createTimedBufferNode()` method, specifying the number of channels, timer interval, and the FrameBufferFiller that supplies samples to the buffer.
174
- - Writing to the ring buffer is handled by the FrameBufferFiller. The timer periodically calls the `fill` method of the FrameBufferFiller, which supplies audio frames via the FrameBufferWriter.
174
+ ![timed](./images/timed.drawio.svg)
175
+
176
+ - This method writes to the ring buffer using a timer initiated on the UI thread. Create it using the `OutputStreamFactory.createTimedBufferNode()` method, specifying the number of channels, the timer interval, and the `FrameBufferFiller` that supplies samples to the buffer.
177
+ - Writing to the ring buffer is handled by the FrameBufferFiller. The timer periodically calls the fill method of the `FrameBufferFiller`, which supplies audio frames via the `FrameBufferWriter`.
175
178
  - If the audio frames run out, the stream playback continues with the node outputting silence.
176
- - If the `fill` method of the FrameBufferFiller returns false, it indicates the end of the audio frame supply. Once OutputStreamNode outputs all the written frames, the stream automatically stops and disconnects.
179
+ - If the fill method of the `FrameBufferFiller` returns false, it indicates that no more audio frames are available. Once `OutputStreamNode` outputs all the written frames, the stream automatically stops and disconnects.
177
180
  - Like the Manual method, you can also stop playback at any time using the `stop()` method.
178
181
 
179
182
  #### Worker
180
183
 
184
+ ![worker](./images/worker.drawio.svg)
185
+
181
186
  - Similar to the Timed method, this method uses a timer to write to the ring buffer, but the timer runs within a Worker. This approach reduces the impact of UI thread throttling, providing more stable playback.
182
187
  - Create it using the `OutputStreamFactory.createWorkerBufferNode()` method.
183
188
  - Writing to the ring buffer occurs within the Worker.
184
- - While the ring buffer writing is still managed by the FrameBufferFiller, the instance must be created and used within the Worker.
185
- - The instantiation of the FrameBufferFiller implementation class is done within the Worker.
186
- - You need to create a custom Worker, but helper implementations are available, simplifying this process. Essentially, you only need to specify the FrameBufferFiller implementation class within the Worker.
187
- - Depending on how you implement the FrameBufferFiller class, you can use the same implementation as the Timed method.
188
-
189
- </details>
189
+ - While the ring buffer writing is still managed by the `FrameBufferFiller`, the instance must be created and used within the Worker.
190
+ - The `FrameBufferFiller` implementation is instantiated within the Worker.
191
+ - You need to create a custom Worker. However, helper implementations are available to simplify this process. Essentially, you only need to specify the `FrameBufferFiller` implementation class within the Worker.
192
+ - Depending on how you implement the `FrameBufferFiller` class, you can use the same implementation as the Timed method.
190
193
 
191
- ## Buffer Underrun Handling
194
+ ### Buffer Underrun Handling
192
195
 
193
196
  - When the buffer becomes empty, silent audio is output instead of throwing an error.
194
197
  - The AudioNode continues to operate and consume CPU resources even during silent output.
@@ -236,6 +239,10 @@ The actual values may slightly differ from the above because they are rounded up
236
239
 
237
240
  </details>
238
241
 
242
+ ## API Documentation
243
+
244
+ You can find the full API documentation [here](https://ain1084.github.io/audio-worklet-stream/).
245
+
239
246
  ## Example
240
247
 
241
248
  <details>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ain1084/audio-worklet-stream",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",