Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Audio 3D audio hitches when teleporting

Discussion in 'Audio & Video' started by willqp, Jul 3, 2019.

  1. willqp

    willqp

    Joined:
    Dec 3, 2010
    Posts:
    12
    I'm working on a VR app that is using 3D audio. When the player teleports you can hear a blip in the audio. If you do it several times you can see the audio getting out of sync with the video. It doesn't happen with 2D audio or if the player moves smoothly to the new position, so it seems like the problem happens when the audio listener move delta is too big on one single frame. Are there some settings that could fix this? Is this a bug?
     
  2. nanaoftheyaw

    nanaoftheyaw

    Joined:
    Oct 28, 2014
    Posts:
    2
    I found the culprit. The Doppler effect. It doesn't update at the same time as the volume. Setting it to zero fixed it but that also means that the audio doesn't sound as realistic. Probably going to have to manually reintroduce the doppler effect to avoid that hitching like sound.
     
  3. sebastianzander

    sebastianzander

    Joined:
    Mar 22, 2018
    Posts:
    37
    I have the exact same problem. I use a floating origin in my game. Visually I have everything under control, meaning lagging cameras (I use Cinemachine) update immediately whenever the floating origin gets translated but I don't have a working solution for the mentioned audio hitches. I can differentiate the audio hitches into a Doppler effect and a volume component.

    I tried setting AudioSource.dopplerLevel = 0 just before the origin gets translated and reset it to its previous value right after the origin was translated. I can clearly hear that the Doppler effect due to the rapid change in translation and consequently interpreted high velocity is impeded. However, the volume dropout remains. For me, AudioListener seems to be the culprit, specifically. Although I translate the main camera (with the AudioListener attached) as well, the volume dropout unfortunately remains.

    Changing either AudioSource.spatialBlend or AudioSource.maxDistance for one or two frames around the translation doesn't convince me to be a nice solution, as then the volume would increase for a short time.
     
  4. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Hi, did you ever figure this out?
     
  5. sebastianzander

    sebastianzander

    Joined:
    Mar 22, 2018
    Posts:
    37
    Hi FlightOfOne. No, unfortunately I did not.
     
  6. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Another year on, has anybody got any solutions for this?

    Seems like we need an equivalent of Cinemachine's 'OnTargetObjectWarped' for audio sources/listeners, or a way to manually set their velocity.

    When does Unity even perform it's audio updates, particularly anything dealing with positions of sources/listeners? - it's not mentioned in the 'order of execution' docs. Is it guaranteed to happen between updates?

    If both an audio source and audio listener jump by the same distance in a frame, where does the doppler glitch actually come from, as the relative velocity between them should be unchanged?
     
    Last edited: Jun 6, 2023
  7. axelstewart

    axelstewart

    Joined:
    May 17, 2018
    Posts:
    14
    Hello all! I have also encountered this same issue.

    I will be attempting to solve it on Monday - as I am doing this for my job I will not be able to share my implementation.
    However, I can tell you my ideas:

    The first is based on what sebastian said:
    1. Create a script containing references to all AudioSources in the scene.
    2. When about to warp the origin, calculate the output volume of each AudioSource based on its falloff settings.
    3. Set all AudioSources' spatial mix to fully 2D and set their volume to the output volume calculated.
    4. Perform origin warp and start a timer.
    5. After timer expires, lerp the spatial mixes back to 3D and lerp their volumes back to their previous volumes. This is necessary because in the interim, objects may have moved, and a jump in volume could occur if we were to switch back immediately.

    The only other idea I have - which would create better-sounding results - is to fully virtualize the audio positioning - to essentially have a separate movement system for audio objects where the listener never moves from the origin, and all audio sources continuously move based on their parent object's relation to the camera.

    It goes without saying that both of these options are extremely distasteful, but I feel the need to say it anyway. If anyone has any ideas other than these, I would be deeply grateful to hear them.
     
  8. axelstewart

    axelstewart

    Joined:
    May 17, 2018
    Posts:
    14
    My solution ended up being a third option - to manually calculate what the volume and panning of each of the AudioSources would be, and use these to control a single pair of 2D AudioSources.
    Since I was dealing with crowd noises, I just split the stereo file I was using into two mono files, assigned one to each of the AudioSources, then attached each of these AudioSources to the mainCamera. My volume and pan calculations are being done in FixedUpdate, and that seems to be running often enough to satisfactorily sound smooth - if this wasn't sufficient, I might have had to create a custom update for it.

    Again, very distasteful to have to do this - I was set back a day by this problem, which required me to completely circumvent Unity's 3D sound system.

    This also is not a solution that includes the Doppler effect.
     
  9. Pheck

    Pheck

    Joined:
    Jul 9, 2009
    Posts:
    225
    I am having a similar issue which I cant find a solution for yet.
    Setting the audio to 2d didnt fix it for me.

    Unity 2022.3.5
    I have a character which moved with a rigidbody. There is a rain audio that smooth follows the player during storms and plays in 2d. (I also tried it not following and saw no improvement)
    When the player interacts with a object to "mount" it which causes a minor distance teleportation by updating the physics position, the audio cuts out for about half a second. Moving without using physics keeps the audio fine, but thats not an option for me in this case. :(

    Looking at the audio mixed and audio source, there is no change in volume etc.
    Not sure if this is the same issue you are seeing.
     
  10. Pheck

    Pheck

    Joined:
    Jul 9, 2009
    Posts:
    225
    Figured out the issue... but not a fix yet.

    When a physics object is teleported in unity, it causes the OnTriggerEnter/Exit to fire even if the object teleports a tiny distance and never exits the trigger.
    I have logic tied to entering and exiting volumes, like my rain areas. While in a rain area, it things the player exited then reentered that rain area and causes the audio to hickup.
    Something similar might be happening in other peoples setups... and something is very wrong with the teleportation causing enter/exit to spam when it shouldnt.
     
  11. axelstewart

    axelstewart

    Joined:
    May 17, 2018
    Posts:
    14
    It's good that you've identified this issue, but in my setup I have no OnTriggerEnter/Exit events - though the effects may be similar, I'm guessing that these are two different Unity bugs.