Repository navigation
Conversation
…he calling thread Every load of a sound from a res:/ path copied it out of the APK again, to the same cache file, on the calling thread, and each VROSoundDataGVR deleted that file when destroyed. The copy is made once on a background thread, shared and left in place. The data's status and delegate are now under a lock. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JoDeNibskBVXyR57tP3WdH
…eShot) For cues fired often. The clip is decoded into GVR audio on first play and kept; up to 8 plays of one clip sound at once. The work runs on a background thread. VROSoundGVR also preloads its file when its data becomes ready on any thread. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JoDeNibskBVXyR57tP3WdH
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.
Renderer side of a fire-and-forget sound API for apps that fire many short cues, and a fix for bundled sounds being copied out of the APK on every load. Workaround ID for the apps:
viroreact-quest-spatial-one-shots. The ViroReact side is ReactVision/viro#640.Not tested on a device, and not built. No Quest was available and there was no NDK where this was written, so
libviro_renderer.sohas not been built with these changes. The changed C++ was type-checked with hostclang++ -fsyntax-onlyas the Android platform against stubbed NDK headers, andSoundData.javacompiles withjavac. iOS and WASM, which shareVRODriver.hand the two GVR sound classes, were not compiled. CI's:viroreact:assembleDebugis the first real build.Why
Soak Squad moved its one-shot sounds (pops, chirps, splashes) off
ViroSound/ViroSpatialSoundonto another audio library, because each cue mounted a renderer sound. Its Quest logcats show, per mount,Viro: Copied resource res:/…andAVPlayer reset / preparedon the Android main thread. Cues grow with the number of enemies and the game lagged as they built up.Commit 1: bundled sounds are copied once (
VROSoundDataGVR)res:/sound was copied out of the APK to the cache directory on everyVROSoundDataGVR, on the calling thread. The Java side writes a fixed file name per resource, so every load rewrote the same file, and eachVROSoundDataGVRdeleted it on destruction while others were still using it.copyBundledResourceOncekeeps a process-wide map from resource to local path, makes the copy once under a lock, and leaves the file in place. The copy runs on a background thread.Commit 2: one-shots (
VROSoundGVR::playOneShot,VRODriver::playSoundOneShot,SoundData.playOneShot)SoundData.playOneShot(context, position, volume, rolloffModel, minDistance, maxDistance): spatial at a world position, or head-locked whenpositionis null.VROSoundGVR, no delegate, nothing to dispose. The clip is decoded into GVR audio withPreloadSoundfileon its first play and kept there, so later plays create a source from memory.VRODriver::playSoundOneShothas a default that returns false, so the iOS and web drivers are untouched and report "not played".VROSoundGVRnow preloads its file when its data becomes ready on any thread. It did so only when the data was already ready at setup, which is no longer the case for bundled resources after commit 1.Known limits
VROSoundGVR's destructor callsUnloadSoundfilefor its path. If an app unmounts aViroSpatialSoundthat used the same preloaded clip, GVR drops the decoded copy and later one-shots of that clip are streamed from the file. Still correct, less efficient. Not changed here.PreloadSoundfileor lazily is not documented in the header. Either way it is off the main thread.GVR audio
The audio engine here is Google's GVR SDK audio, which Google has discontinued;
libgvr_audio.sois a prebuilt binary that cannot be patched. Its successor, Resonance Audio, is open source, has the same model (preloaded files, sound objects, room effects), and would allow real source reuse and per-source callbacks. Replacing it is worth planning but is a larger change with its own device testing, and is not part of this PR.To check on a Quest 3
With
examples/quest-sound-one-shotsfrom viro#640, release build,adb logcat -s ReactNativeJS Viro:Copied resource res:/…line per clip for the whole run.AVPlayer reset/preparedlines while cues fire.ViroSoundandViroSpatialSoundcomponents with bundled sources still load and play (the readiness timing changed).🤖 Generated with Claude Code
https://claude.ai/code/session_01JoDeNibskBVXyR57tP3WdH