@ain1084/audio-worklet-stream 0.1.3 → 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 +101 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
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.
9
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
+
10
12
  ## Features
11
13
 
12
14
  - **Manual Buffer Writing**: Provides the ability to manually write audio frames to a buffer.
@@ -15,6 +17,20 @@ This library provides a way to work with audio worklets and streams using modern
15
17
  - **Vite Integration**: Leverages Vite for easy worker loading and configuration without complex setup.
16
18
  - **Audio Worklet Integration**: Seamlessly integrates with the Web Audio API's Audio Worklet for real-time audio processing.
17
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
+
18
34
  ## Prerequisites
19
35
 
20
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.
@@ -219,6 +235,91 @@ The provided example demonstrates how to use the library to manually write audio
219
235
 
220
236
  For more details, refer to the `example/README.md`.
221
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
+
222
323
  ## Future Plans and Known Issues
223
324
 
224
325
  ### Future Plans
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ain1084/audio-worklet-stream",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",