Repository navigation
fix(audio-context): Android scheduling clock, targeted disconnect, close, channel mixing and worklet wakeups - #284
Merged
Conversation
…ose, 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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong (Android)
nativeAttachPanner,nativeAttachBiquadandnativeAttachPlaybackRateexported their 2-arg overloads under the short JNI name. That name also binds the 4-arg overloads, so output/input were lost. For example, a splitter output connected to a filter filtered the wrong channel.disconnect(target|output)always disconnected everything. It called JavadisconnectTo/disconnectOutput, which don't exist, then fell back to a full disconnect.AudioContext.close()only suspended the shared engine. The context's voices kept playing in the next context. This caused 'gain follows setValueAtTime…', 'oscillator sounds only between…' and the two realtime worklet specs to fail.bufferwas set after creation was created on the realtime engine, so an offline render never played it. Its realtime voice was also invisible toclose().voiceDelay_was never cleared. Disconnecting a source from aDelayNodeleft it routed through the delay.channelCount, so in a mono context a stereo source reached the worklet as its mono mix. Only mono and stereo were handled.BiquadFilterNode.typehad no getter or setter.What changed
currentTimereads the same clock.nativeAttachGainalready does.disconnectcalls the existing Java overloads. Every node's targeteddisconnectgoes throughAudioContext.disconnectNode, which sends a newCMD_DETACH_FROM. That command clears only the voice's gain, filter or panner slots, delay route or worklet route that hold the target, at the given output.AudioContextInstance.closeAsyncstops the context's tracks and frees its gains, filters, panners and destination. Buffers are kept. The engine suspends only when no realtime context is left open.switchBufferSourcecreates the new voice in its context's engine and registers it with the context.voiceDelay_.speakerMixhelper implements the Web Audio speaker up/down-mix for mono, stereo, quad and 5.1. Other channel counts mix discretely. Buffer sources, worklet outputs and mono sources all use it.channelCount, so the ring gets each input already mixed.WorkletWakerregisters aneventfdon the Worker thread's looper. The engine writes to it after each requested quantum and when a worklet closes, and the Worker's drain runs on its own thread.Atomics.notifyisn't an option because the render thread can't call it. Where the waker isn't available (iOS), the bridge keeps polling. In a 400-quantum offline render with an input worklet, time dropped from about 1000 ms to about 130 ms.BiquadFilterNode.typegets/sets through newAudioBiquadNode.getType/setType.Specs
New:
audio.offline.renderaudio.schedulingaudio.workletResults:
audiosuite (Pixel 9 Pro emulator): 43 passed, 0 failed, 2 skipped. Before: 32 passed, 5 failed. The 2 skips areconnect(AudioParam), which Android doesn't support.audiosuite (simulator): 43 passed, 0 failed, 2 skipped. These are the 39 existing specs plus the 4 new ones that run on iOS.