Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mp3 file time inaccurate #504

Open
achimmihca opened this issue Nov 11, 2024 · 5 comments
Open

mp3 file time inaccurate #504

achimmihca opened this issue Nov 11, 2024 · 5 comments

Comments

@achimmihca
Copy link
Collaborator

Actual behaviour

Change position in mp3 file is sometimes inaccurate with Unity.

This affects for example

  • "short song" and "medley"
  • "skip to next lyrics"
  • preview in song select
  • song editor because one skips back and forth in the song

In contrast, when playing the song from the start then the time position is correct.

Expected behaviour

Setting a new time for audio playback should be accurate.

Steps to reproduce

  • Reproducible (mark with x): [x] always, [ ] sometimes

Here is a minimum reproducable example: https://github.com/achimmihca/UnityAudioPositionIssueMp3

Hints

  • I opened a Unity bug report for this
  • Workaround: use ogg format, use libVLC backend
@AnsisMalins
Copy link
Collaborator

The only reliable way to scrub an audio file is to decompress all of it into memory. Maybe then compress it in memory with ADPCM. All else will be laggy at best, wrong at worst.

@basisbit
Copy link
Member

basisbit commented Nov 12, 2024

@AnsisMalins precise jumping is not a problem and not laggy when you can reliably calculate the position in the file stream. For cbr mp3, this is very easy to do. For vbr, the file needs to be "indexed", but not fully processed. libvlc does this automagically. UltraStar Deluxe also can correctly jump with vbr audio files when using the bass audio backend or when using ffmpeg and have audio and video in the same media file.

@achimmihca
Copy link
Collaborator Author

Unity confirmed the issue.
Fingers crossed that they fix this...

@jimmyhawkin
Copy link

Lets hope.

@achimmihca
Copy link
Collaborator Author

achimmihca commented Nov 18, 2024

I added a workaround in Melody Mania v1.4.2-beta6

  • streamAudio is set to false for mp3 files
  • advantage: correct accuracy because all audio samples are loaded upfront
  • disadvantage: takes a moment to load
    • Therefor, the workaround is only used in the SingScene but not for the SongSelectScene as it would make song browsing stutter
    • This surprises me as I would expect Unity to load the audio samples in the background. But it seems to be a blocking operation when streamAudio is false

This Unity bug would be less of an issue if there would be a way to load audio in Unity in a non-blocking way without setting streamAudio to true. Unfortunately, I think this is not possible.

See example repo on GitHub: https://github.com/achimmihca/UnityAudioPositionIssueMp3
Contributions welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants