Search Unity

Audio AudioSource.time and AudioSource.timeSamples returning doubled values in some frames

Discussion in 'Audio & Video' started by atalkingfish, Nov 30, 2019.

  1. atalkingfish

    atalkingfish

    Joined:
    Sep 17, 2018
    Posts:
    47
    I'm working on a rhythm game where I need to call the time of an audio clip every frame. The issue is that I'm getting some inaccurate results when using either. Specifically, every few frames or so, two frames will come and go and they will both return the same value as the frame before. This causes a weird visual stuttering in my game. I have tried to see if it is related to the fixed time interval, but adjusting that doesn't seem to change anything. Anyone have insights on this?
     
  2. atalkingfish

    atalkingfish

    Joined:
    Sep 17, 2018
    Posts:
    47
    After scouring the internet for a couple hours (before making this post), I started looking around at the project audio settings. It seems that changing the "DSP Buffer Size" from "Best Performance" to "Best Latency" solves this issue.
     
  3. jf065d

    jf065d

    Joined:
    May 28, 2018
    Posts:
    23
    Bump. I'm having this exact same issue, but adjusting DSP Buffer Size seems to have no effect. 2022.3.13f1
     
    Last edited: Jan 16, 2024
  4. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    407
    Hi @jf065d !

    A good way to time precisely your audio is to leverage `PlayScheduled` and specify an absolute moment in time for the sound to play.