Audio locked on App start. No head tracked audio. Often starts hard panned to left or right

My balance is set a 0.00, right in the middle and the audio is only coming from the left (all other native apps like disney+ etc sounds just fine). Its only the unity app throwing the audio from my left side. I’ll try to test later the app provided above.

Yeah, the VR issue seems to be different from the one with MR/volume apps. I still haven’t been able to replicate the issue in a VR app :frowning:

I can confirm my balance is at 0 too. I’m going to create a TestFlight for my repro soon, so we can all give it a go easily. @mtschoen I’ll also try your test project soon, just a little tied up during the day today

We are having users complain about one sided audio in our app as well. An uninstall and reinstall seemed to fix it for one user

I’ve uploaded my repro project to TestFlight. I’ll post the public link here once it’s approved…

@mtschoen: I tried opening your “metaltest” project but its appears to be missing the mp3 file

Can you update your folder with the correct asset and I’ll try again? Thanks!!

Here’s the TestFlight link:

Curious if this repros for others watching this thread (I’m away from home so haven’t confirmed it myself)

Just tried it on my device with visionOS 1.0.3. Still can’t repro. I hear the sound equally out of both ears. I’m updating my other device to latest 1.1 and we’ll see what I see there.

OK I think I’m finally seeing the issue now on 1.1, but it’s super random. Sometimes it’s louder in the right ear, sometimes in the left, and sometimes it’s balanced for a second, but then the safety dialog comes up, and it pans to the left. The right ear is still playing when it’s louder in the left, and sometimes the balance is just subtly off. If I cup my hand over my ears, I can hear always audio in both.

As @Naninja pointed out, I’ve found that uninstalling and re-installing the app sometimes fixes the issue. I also found that it will go away after restarting the device. I also get the same result when running the metaltest app, which strongly indicates that this is a platform bug. I have a theory as to why it’s happening, and why I hadn’t noticed it until now. If I launch your app from the TestFlight UI, (the Open button) the issue occurs pretty reliably. I even tried having the window slightly to the left, or slightly to the right, and as far as I could tell, that determined which side of my head the VR audio sounded like it was coming from. Then if I launched metaltest after launching your test app, I’d hear the audio coming from the same direction. So I think maybe users “in the wild” are hearing the same thing. If they open the app with the App Store UI, maybe they have the store window off to the side, and for some reason the spatial audio is “remembering” that window location and using it as the source.

I’m going to submit some feedback to Apple and raise this with them. Thanks for patiently working through this with me. It’s been pretty hard to track down!

2 Likes

Oh yeah P.S. I re-uploaded metaltest with a self-contained version. I forgot the MP3 was referencing some other path on my machine. Whoops! :sweat_smile:

The same old link should work but here it is again just in case.

1 Like

Great, glad you were able to repro. And does indeed seem like an OS level issue given the problem does repro in your metaltest example. I have filed an issue with Apple and will engage with them directly about this as well. Thanks for all the help!!

Also started running into this as well. I’m glad it’s getting looked at.

1 Like

I have this problem too. Does anyone NOT have this problem? If so, what are you doing differently than us?

Also started running into this as well.

Hey folks. I’m happy to share that we have a workaround! Our friends at Apple let us know about an API that can be used to control how the OS handles spatial audio for your app. You can call setIntendedSpatialExperience at app launch and indicate that you want to bypass spatial audio. To be clear, this will bypass visionOS spatial audio, but Unity spatial audio will still work. What was happening is that our stereo output was being re-spatialized by visionOS, and we don’t want that.

I’ll be adding this to our mainline soon, but in the meantime you can apply this workaround on your own projects by adding the following code on line 141 of Classes/UnityAppController.mm (in the startUnity method) in the generated Xcode project:
[audioSession setIntendedSpatialExperience:AVAudioSessionSpatialExperienceBypassed options:@{} error:nil];

I added this before the existing code that was there: [audioSession addObserver: self forKeyPath: @"outputVolume" options: 0 context: nil];. It can probably go after as well. As far as I can tell, this completely eliminates the audio panning issue.

Hope this helps!

6 Likes

I can confirm it works for me. Thank you @mtschoen .

1 Like

Fixed for me too ! Thanks !!

Alternatively, you don’t need to touch Classes/UnityAppController.mm.

You can also modify UnityMain.swift (com.unity.xr.visionos/Runtime/Plugins/visionos/UnityLibrary.swift)
We want to show a swift window at first and want it to have VisionOS spatial audio.
So when we go into full VR we then call a function to initiate the bypass to Unity/fmods spatialization.

For example:

    func setupSpatialAudioSessionBypass() {
        do {
            let session = AVAudioSession.sharedInstance()
            try session.setIntendedSpatialExperience(.bypassed)
        } catch {
            fatalError("Failed to reconfigure active shared session.")
        }
    }

This function can be called after

UnityVisionOS_SetLayerRenderer(layerRenderer)

and before

layerRenderer.onSpatialEvent = { eventCollection in

Any thoughts on how this could be done on the Unity side of things so it gets included in builds?

You should be able to follow @egleiser’s advice above to add this workaround in UnityLibrary.swift and modify a local copy of the com.unity.xr.visionos package. Alternatively, you can actually modify UnityAppController.mm in the Unity installation on your mac (for example, under /Applications/Unity/Hub/Editor/2022.3.21f1/PlaybackEngines/VisionOSPlayer/Trampoline/Classes/UnityAppController.mm for 2022.3.21f1 installed via Hub) to include this hotfix. That’s what gets copied into your Xcode builds.

Is it possible to use visionOS spatial audio correctly? As that is happening by default anyway?