Repository navigation
Commit f18e91e
authored
feat(audio-context): render the Android audio graph as a real node graph (#285)
* fix(audio-context): Android scheduling clock, targeted disconnect, close, channel mixing and worklet wakeups
- Realtime blocks run on a frame clock instead of the device timestamp, which jittered between
callbacks, so a source's position and gain automation drifted apart (tens of frames).
- nativeAttachPanner/Biquad/PlaybackRate export their 2-arg overloads under the long JNI name;
the short name also bound the 4-arg overloads and dropped output/input.
- AudioNode.disconnect calls the Java overloads (disconnectOutput/disconnectTo didn't exist, so
every targeted disconnect was a full one). A new CMD_DETACH_FROM clears only the voice slots
holding the target.
- Closing a realtime AudioContext stops and frees its voices and nodes; the shared engine only
suspends once no realtime context is open. Buffer sources whose buffer is set after creation
are now created in their context's engine and tracked by it (offline ones were created on the
realtime engine and never rendered).
- An empty gain attach clears voiceDelay_.
- Buffer sources and worklet outputs up/down-mix with the Web Audio speaker rules (mono, stereo,
quad, 5.1), so a stereo buffer in a mono context plays (L+R)/2.
- Worklet inputs render at each input's own channelCount from each source's own channels.
- The worklet Worker is woken by an eventfd on its looper per requested quantum instead of a
2 ms poll (Atomics.notify can't come from the render thread). 400 offline quanta with an
input worklet: ~1000 ms -> ~130 ms.
- BiquadFilterNode.type has a getter/setter on Android.
* feat(audio-context): render the Android audio graph as a real node graph
Android flattened every connection onto the source voices: one gain, filter and
panner slot per voice output, with DelayNode and worklet inputs in side maps.
A node feeding a delay or a worklet played only there, a source couldn't fan out
to two gains, chained gains replaced each other, wiring depended on the order of
connect calls, a DelayNode couldn't sit in a feedback loop, and
source.disconnect(firstGain) left a gain chain playing.
The engine now keeps the graph itself (audio_graph.cpp). connect/disconnect go
straight to native as edges; each 128-frame quantum renders the nodes in
topological order, each input summing its connections at its computed channel
count with the Web Audio up/down-mix rules. Tarjan's SCCs find cycles: a cycle
through a DelayNode reads the delay line before its input is written (delay at
least one quantum), a cycle without one is muted. node.connect(AudioParam) adds
the source's mono mix to gain-style and panner params every frame. Realtime
callbacks play from a quantum FIFO; offline renders a quantum per call.
Nodes the app frees while something still plays into them stay until it stops.1 parent 16ff853 commit f18e91e
31 files changed
Lines changed: 2372 additions & 4668 deletions
File tree
- packages/audio-context
- platforms/android
- src-native/android/audiocontext/src/main
- cpp
- java/org/nativescript/audiocontext
- typings
- tools/demo/canvas/spec
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
153 | 158 | | |
154 | 159 | | |
155 | 160 | | |
| |||
159 | 164 | | |
160 | 165 | | |
161 | 166 | | |
162 | | - | |
163 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
164 | 174 | | |
165 | 175 | | |
166 | 176 | | |
| |||
218 | 228 | | |
219 | 229 | | |
220 | 230 | | |
221 | | - | |
222 | | - | |
| 231 | + | |
223 | 232 | | |
224 | 233 | | |
225 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
133 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
137 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
138 | 191 | | |
139 | 192 | | |
140 | 193 | | |
141 | 194 | | |
142 | | - | |
| 195 | + | |
143 | 196 | | |
144 | 197 | | |
145 | | - | |
146 | | - | |
147 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
148 | 202 | | |
149 | 203 | | |
150 | 204 | | |
| |||
153 | 207 | | |
154 | 208 | | |
155 | 209 | | |
156 | | - | |
| 210 | + | |
157 | 211 | | |
158 | 212 | | |
159 | 213 | | |
| |||
162 | 216 | | |
163 | 217 | | |
164 | 218 | | |
165 | | - | |
166 | | - | |
167 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
168 | 225 | | |
169 | 226 | | |
170 | 227 | | |
| |||
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
0 commit comments