@ain1084/audio-worklet-stream 0.1.2 → 0.1.4

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 +117 -4
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,14 @@
1
1
  # Audio Worklet Stream Library
2
2
 
3
+ [![npm version](https://badge.fury.io/js/@ain1084%2Faudio-worklet-stream.svg)](https://badge.fury.io/js/@ain1084%2Faudio-worklet-stream)
4
+ [![Documentation](https://github.com/ain1084/audio-worklet-stream/workflows/docs/badge.svg)](https://github.com/ain1084/audio-worklet-stream/actions?query=workflow%3Adocs)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
+
3
8
  This library provides a way to work with audio worklets and streams using modern web technologies. It allows for the manual writing of audio frames to a buffer and supports various buffer writing strategies.
4
9
 
10
+ This library was created for use in my project [fbdplay_wasm](https://github.com/ain1084/fbdplay_wasm). In this project, we utilize only a very limited set of WebAudio functionalities. It might lack features for general use.
11
+
5
12
  ## Features
6
13
 
7
14
  - **Manual Buffer Writing**: Provides the ability to manually write audio frames to a buffer.
@@ -10,6 +17,20 @@ This library provides a way to work with audio worklets and streams using modern
10
17
  - **Vite Integration**: Leverages Vite for easy worker loading and configuration without complex setup.
11
18
  - **Audio Worklet Integration**: Seamlessly integrates with the Web Audio API's Audio Worklet for real-time audio processing.
12
19
 
20
+ ## Confirmed Browser Support
21
+
22
+ |Feature|Chrome|Chrome (Android)|Firefox|Safari (macOS)|Safari (iOS)|Edge|Opera|
23
+ |:--|:--:|:--:|:--:|:--:|:--:|:--:|:--:|
24
+ |Basic Support|![Chrome](https://img.icons8.com/color/24/000000/chrome.png)|![Chrome](https://img.icons8.com/color/24/000000/chrome.png)|![Firefox](https://img.icons8.com/color/24/000000/firefox.png)|![Safari](https://img.icons8.com/color/24/000000/safari--v2.png)|![Safari](https://img.icons8.com/color/24/000000/safari--v2.png)|![Edge](https://img.icons8.com/color/24/000000/ms-edge.png)|![Opera](https://img.icons8.com/color/24/000000/opera.png)|
25
+ |Manual Buffer Writing|✅|✅|✅|✅|❓|✅|❓|
26
+ |Timer-Based Buffer Writing|✅|✅|✅|🔺|❓|✅|❓|
27
+ |Worker-Based Stability|✅|✅|✅|✅|❓|✅|❓|
28
+
29
+ ### Legend
30
+ - ✅: Confirmed and working without issues
31
+ - 🔺: Confirmed with limitations (e.g., unstable in background operation)
32
+ - ❓: Not yet confirmed
33
+
13
34
  ## Prerequisites
14
35
 
15
36
  - **Node.js** and **npm**: Make sure you have Node.js (version 20 or higher) and npm installed. This library hasn't been tested on versions below 20.
@@ -180,6 +201,7 @@ class Main {
180
201
  }
181
202
 
182
203
  // Start the audio stream
204
+ // Node’s streaming process (such as timer activation) does not start until start() is called.
183
205
  start() {
184
206
  if (!this.streamNode) throw new Error('Stream node not created');
185
207
  this.streamNode.connect(this.streamNode.context.destination);
@@ -187,9 +209,10 @@ class Main {
187
209
  }
188
210
 
189
211
  // Stop the audio stream
212
+ // stop() internally calls node.disconnect(). Since inter-thread communication may take some time, it returns a Promise.
190
213
  stop() {
191
214
  if (!this.streamNode) throw new Error('Stream node not created');
192
- this.streamNode.stop();
215
+ return this.streamNode.stop();
193
216
  }
194
217
  }
195
218
 
@@ -212,6 +235,91 @@ The provided example demonstrates how to use the library to manually write audio
212
235
 
213
236
  For more details, refer to the `example/README.md`.
214
237
 
238
+ ## Known Issues and Workarounds
239
+
240
+ *Note: Some content overlaps with previous sections.*
241
+
242
+ ### SSR and Import Errors with ESM Modules
243
+
244
+ When using `@ain1084/audio-worklet-stream` in a Nuxt 3 project, you may encounter issues during SSR (Server-Side Rendering) or when importing the package as an ESM module. This can result in errors like:
245
+
246
+ ```bash
247
+ [nuxt] [request error] [unhandled] [500] Cannot find module '/path/to/node_modules/@ain1084/audio-worklet-stream/dist/esm/events' imported from '/path/to/node_modules/@ain1084/audio-worklet-stream/dist/esm/index.js'
248
+ ```
249
+
250
+ ### Workarounds
251
+
252
+ 1. **Disable SSR for the Component**
253
+
254
+ You can disable SSR for the component that uses the package. This can be done by using `<client-only>`:
255
+
256
+ ```vue
257
+ <client-only>
258
+ <MyComponent />
259
+ </client-only>
260
+ ```
261
+
262
+ 2. **Use ssr: false in nuxt.config.ts**
263
+
264
+ You can disable SSR for the entire project in `nuxt.config.ts`:
265
+
266
+ ```typescript
267
+ export default defineNuxtConfig({
268
+ ssr: false,
269
+ // other configurations
270
+ })
271
+ ```
272
+
273
+ 3. **Use import.meta.server and import.meta.client**
274
+
275
+ For a more granular control, you can use `import.meta.server` and `import.meta.client` to conditionally import the module only on the client-side. Note that this method is more complex compared to 1 and 2:
276
+
277
+ ```typescript
278
+ if (import.meta.client) {
279
+ const { StreamNodeFactory } = await import('@ain1084/audio-worklet-stream');
280
+ // Use StreamNodeFactory
281
+ }
282
+ ```
283
+
284
+ ### Example Configuration
285
+
286
+ To ensure proper operation, it is essential to use `ssr: false` or `<client-only>` for components and to exclude `@ain1084/audio-worklet-stream` from Vite's optimization in your `nuxt.config.ts`:
287
+
288
+ ```typescript
289
+ export default defineNuxtConfig({
290
+ ssr: false, // or use <client-only> for specific components
291
+ vite: {
292
+ optimizeDeps: {
293
+ exclude: ['@ain1084/audio-worklet-stream'],
294
+ },
295
+ },
296
+ nitro: {
297
+ rollupConfig: {
298
+ external: '@ain1084/audio-worklet-stream',
299
+ },
300
+ },
301
+ // Ensure CORS settings for SharedArrayBuffer
302
+ server: {
303
+ headers: {
304
+ 'Cross-Origin-Embedder-Policy': 'require-corp',
305
+ 'Cross-Origin-Opener-Policy': 'same-origin',
306
+ },
307
+ },
308
+ })
309
+ ```
310
+
311
+ ### Future Plans and Known Issues
312
+
313
+ #### Future Plans
314
+ 1. **Enhanced Documentation**: Improve the documentation with more examples and detailed explanations.
315
+
316
+ #### Known Issues
317
+ 1. **Buffer Underruns**: Occasional buffer underruns under heavy CPU load.
318
+ 2. **Overhead at the Start of Playback**: The ring buffer is being generated each time. To mitigate this, we plan to add a simple memory management mechanism to reuse the memory allocated for the ring buffer.
319
+ 3. **Overhead during Worker Playback**: It seems that the Worker is being loaded every time playback starts (although it hits the cache). We plan to cache the Worker in memory and reuse it.
320
+
321
+ We are continuously working on these areas to improve the library. Contributions and suggestions are always welcome!
322
+
215
323
  ## Future Plans and Known Issues
216
324
 
217
325
  ### Future Plans
@@ -236,8 +344,13 @@ We are continuously working on these areas to improve the library. Contributions
236
344
 
237
345
  Contributions are welcome! Please open an issue or submit a pull request on GitHub.
238
346
 
239
- Unless 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.
240
-
241
347
  ## License
242
348
 
243
- This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
349
+ This project is licensed under multiple licenses:
350
+
351
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
352
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
353
+
354
+ You can choose either license depending on your project needs.
355
+
356
+ Unless 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ain1084/audio-worklet-stream",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",