You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`worklet`|`(Array<Float32Array>, number) => void`| The worklet to be executed. |
68
68
|`bufferLength`|`number`| The size of the buffer that will be passed to the worklet on each call. |
69
69
|`inputChannelCount`|`number`| The number of channels that the node expects as input (it will get min(expected, provided)). |
70
+
|`workletRuntime`|`AudioWorkletRuntime`| The kind of runtime to use for the worklet. See [worklet runtimes](/docs/worklets/worklets-introduction#what-kind-of-worklets-are-used-in-react-native-audio-api) for details. |
|`worklet`|`(Array<Float32Array>, number, number, number) => void`| The worklet to be executed. |
89
+
|`workletRuntime`|`AudioWorkletRuntime`| The kind of runtime to use for the worklet. See [worklet runtimes](/docs/worklets/worklets-introduction#what-kind-of-worklets-are-used-in-react-native-audio-api) for details. |
90
+
91
+
#### Errors
92
+
93
+
| Error type | Description |
94
+
| :---: | :---- |
95
+
|`Error`|`react-native-worklet` is not found as dependency. |
|`worklet`|`(Array<Float32Array>, Array<Float32Array>, number, number) => void`| The worklet to be executed. |
106
+
|`workletRuntime`|`AudioWorkletRuntime`| The kind of runtime to use for the worklet. See [worklet runtimes](/docs/worklets/worklets-introduction#what-kind-of-worklets-are-used-in-react-native-audio-api) for details. |
107
+
108
+
#### Errors
109
+
110
+
| Error type | Description |
111
+
| :---: | :---- |
112
+
|`Error`|`react-native-worklet` is not found as dependency. |
Copy file name to clipboardExpand all lines: packages/audiodocs/docs/worklets/introduction.mdx
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,9 +26,27 @@ Simply put, a worklet is a piece of code that can be executed on a runtime diffe
26
26
27
27
## What kind of worklets are used in react-native-audio-api?
28
28
29
-
All of our worklets are currently executed on the UI runtime provided by the `RNWorklets` library.
29
+
We support two types of worklet runtimes, each optimized for different use cases:
30
30
31
-
This allows the use of Reanimated utilities and features inside the worklets. Our main goal is to enable seamless integration with the UI - for example, creating animations from audio data.
31
+
### UIRuntime
32
+
Worklets executed on the UI runtime provided by the `RNWorklets` library. This allows the use of Reanimated utilities and features inside the worklets. The main goal is to enable seamless integration with the UI - for example, creating animations from audio data.
33
+
34
+
**Use UIRuntime when:**
35
+
- You need to update UI elements from audio data
36
+
- Creating visualizations or animations based on audio
37
+
- Integrating with Reanimated shared values
38
+
- Performance is less critical than UI responsiveness
39
+
40
+
### AudioRuntime
41
+
Worklets executed on the audio rendering thread for maximum performance and minimal latency. This runtime is optimized for real-time audio processing where timing is critical.
42
+
43
+
**Use AudioRuntime when:**
44
+
- Performance and low latency are crucial
45
+
- Processing audio in real-time without dropouts
46
+
- Generating audio with precise timing
47
+
- Audio processing doesn't need to interact with UI
48
+
49
+
You can specify the runtime type when creating worklet nodes using the `workletRuntime` parameter.
32
50
33
51
## How to use worklets in react-native-audio-api mindfully?
It has no own properties but inherits from `AudioNode`.
48
+
It has no own properties but inherits from [`AudioNode`](/docs/core/audio-node).
49
49
50
50
## Methods
51
-
It has no own methods but inherits from `AudioNode`.
51
+
It has no own methods but inherits from [`AudioNode`](/docs/core/audio-node).
52
52
53
53
## Known Issue
54
-
It might happen that the worklet side effect is not visible on the UI. For example you have some animated style which depends on some shared value modified in the worklet.
54
+
It might happen that the worklet side effect is not visible on the UI (when you are using UIRuntime kind). For example you have some animated style which depends on some shared value modified in the worklet.
55
55
This is happening because microtask queue is not always being flushed properly, bla bla bla...
56
56
57
57
To workaround this issue just add this line at the end of your worklet callback function:
0 commit comments