Repository navigation
Conversation
Play a preloaded clip once, at a world position or head-locked, with no component mounted for it. A component per cue created a native sound and loaded the clip each time on the main thread. Needs the renderer's SoundData.playOneShot. 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.
A fire-and-forget sound API for cues an app fires often, so it does not mount a component per cue. Workaround ID for the apps:
viroreact-quest-spatial-one-shots. The renderer side is ReactVision/virocore#477.Not tested on a device. No Quest was available.
examples/quest-sound-one-shotsis the scene to check it with.This does not build until the renderer AAR is rebuilt. The bridge calls
SoundData.playOneShot, which is added in virocore#477 and is not in theviro_renderer-release.aarchecked into this repository. Merge and build virocore#477 first, then rebuild both AARs here.Why
Soak Squad moved its one-shot sounds off
ViroSound/ViroSpatialSoundbecause each cue mounted a renderer sound: per mount, its Quest logcats show the clip being copied out of the app and a media player being prepared on the Android main thread. Cues grow with the number of enemies and the game lagged.The API
ViroSound.preloadSounds, by its key. No component, nothing to unmount.truewhen the clip was handed to the audio engine,falsewhen it was not (not preloaded, or no scene mounted). Never rejects, so it can be called and forgotten.falsewith one console warning, and on the web it resolvesfalse. Neither has a one-shot path yet.How
SoundModule.playOneShot(name, position, options, promise)looks the clip up in the preloaded map and callsSoundData.playOneShoton the activeViroContext.VRTScene.setViroContextrecords the context of the scene mounted most recently, held weakly.components/Utilities/ViroSoundOneShot.tsis the shared JavaScript; the two statics call it.Depends on
preloadSoundsfails there forrequire()d clips until that PR's fix, and a one-shot needs a preloaded clip. This PR does not repeat that fix, to avoid both PRs changing the same lines.Limits
Verification
npx jest: 1129 tests pass, 5 of them new (__test__/soundOneShot.test.ts). 23 suites fail to load, the same 23 as ondevelop: they need the siblingviro-web-renderercheckout.tsc --noEmit: no errors outside the web files, which need the same checkout.SoundModuleandVRTScenecompile withjavacagainst React Native 0.88.1's classes and the bridge classes, withSoundDatacompiled from virocore#477.To check on a Quest 3
With
examples/quest-sound-one-shots(add two short clips; none are shipped), release build,adb logcat -s ReactNativeJS Viro:preloadreportsresult: truefor both clips.refusedstays 0.Copied resourceline per clip, and noAVPlayerlines while cues fire.worst tick lateness msstays low and the frame rate does not drop as cues build up.Generated by Claude Code