Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Audio Audiosource.time innaccurate in Android?

Discussion in 'Audio & Video' started by SovietSpartan, May 20, 2017.

  1. SovietSpartan

    SovietSpartan

    Joined:
    May 2, 2014
    Posts:
    17
    Hello! I'm working on a Rythym game for Android where players can import their own songs with their own self made beatmaps.

    The game is about tapping some circles that approach a position as their "tap time" approaches. These circles have a tap time, which is the time where they are supposed to be tapped, and a spawn time, which is used to spawn the circles a few seconds before their tap time is reached so that they have time to move torwards their position.

    These circles use the following code to move:

    Code (CSharp):
    1.  initialTimeDiff = Mathf.Abs(currentSongTime - spawnTime); <---This is set on Start()
    2. currentTimeDiff = spawnTime - currentSongTime;                    
    3. transform.position = Vector3.Lerp(targetPos,spawnPos,currentTimeDiff/initialTimeDiff);
    This works perfectly on the Unity Editor, however, on Android is where i'm finding issues.

    Both doing Audiosource.time and Audiosource.clip.timesamples/Audiosource.clip.frequency give innacurate values.

    By "innaccurate" i mean that the values seem to not update as fast as they should. I made a test to see whether it was a performance issue or something by adding a Time.deltaTime timer and a Audiosource.clip.timesamples/Audiosource.clip.frequency timer next to each other and seeing which of the two updated faster.

    Time.deltaTime was updating as fast as expected, while the Audiosource timer was lagging behind a bit. Eventually the Time.deltaTime timer got out of sync with the song, so i had to discard using it for the game.

    This issue causes the circles in the game to move as if they were "lagging" while everything else runs smoothly. This affects both the timing where the player is supposed to tap them too.

    Anyone knows what is going on? I also found out that the issue got better by increasing the System Sample Rate to 96000 in the Audio settings, but i can't make it go farther than that, so the issue is still there. I made a post before, but didn't get any answers, so i decided to give it a shot and see if i could get help this time.

    Any helps is appreciated! >_<
     
  2. SovietSpartan

    SovietSpartan

    Joined:
    May 2, 2014
    Posts:
    17
    Bumping! No one else experiences this? Right now, i'm using the average value between Time.deltaTime and Audiosource.Time, however this is not 100% accurate to the song still.
    Is there a way to get the accurate audio time on Android?
     
  3. Jacowaco

    Jacowaco

    Joined:
    Aug 23, 2013
    Posts:
    3
    Hi Soviet, i'm experiencing the exact same issue. I know this post is old but did you find a way to solve it?