Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug When using Audioclip.length channels aren't taken into consideration

Discussion in 'Audio & Video' started by bobby55, Aug 20, 2022.

  1. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    Hi!, When i use Audiocip.length on an mp3 file with 2 channels with a duration of 4:30 instead of outputting 275.3437 it outputs 550.687 meaning the seconds haven't been divided by the number of channels

    The correct calculation should be
    SongSamples / (SongFrequency * SongChannels)
    But the current calculation seems to be
    SongSamples / SongFrequency
     
  2. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    I think (i still need to check)
    audiosource.timeSamples and audiosource.time seem to have the same problem aswell
     
  3. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    (Again i still need to check because i don't have time currently)
    Audioclip.GetData() seems to return half the intended samples when using a stereo audioclip - however a mono audioclip seems to work fine?
     
  4. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    On what Unity version are you on?
     
  5. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    i was on 2022.1.10f1
     
  6. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Can you test on the latest 2022.2 to see if the bug was fixed?
     
  7. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    @The_Island Sorry for the delay, i've been busy as of late so haven't been able to get round to doing this but i promise i haven't forgotten - i'll hopefully be able to test on 2022.2 soon.
     
  8. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    OK so the output from both 2021.3.8f1 and 2022.2 are the same and the bug no longer occurs! - must've been my code then.
     
    The_Island likes this.