Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: MP3 looping issues  (Read 2754 times)

0 Members and 1 Guest are viewing this topic.

Biohazard90

  • Newbie
  • *
  • Posts: 1
    • View Profile
MP3 looping issues
« on: September 26, 2022, 09:22:38 pm »
Hi, I have encountered two different issues when looping mp3 files with minimp3 included by SFML through an sf::Music object. At least one of these issues is rooted in minimp3, the other I'm not sure because I don't know the nitty-gritty details of the mp3 format.

The first issue occurs after looping for the first time, the internal file offset in minimp3 becomes incorrect when SFML seeks the file to zero, I have provided a test file and proposed a fix in minimp3 here on github: https://github.com/lieff/minimp3/issues/101

To reproduce this issue, loop the file with an sf::Music object and wait for the second time it plays to reach the end, now it will stop instead of looping again.

The second issue is similar. minimp3 does not reach the expected end of the file and stops short of it, in turn SFML does not loop the file and just stops playing music. But in this case I'm not sure if the issue is fundamentally in minimp3 or SFML. From what I can tell, the expected sample count in minimp3 is higher than the data that is truly available, leading to it never reaching the end. I have attached a file that exhibits this issue on github as well: https://github.com/lieff/minimp3/issues/101#issuecomment-1258468004

To reproduce this second issue, loop the second file with an sf::Music object and it will already fail looping the first time.

I believe I managed to fix the first issue, but I'm not sure how to go about solving the second issue. Learning the mp3 format to correct the expected sample count may be daunting or might even require decoding the entire file before being able to know the correct count, so changing the looping logic in SFML to not compare with the expected number of samples may be simpler/more efficient. The issue may also be something else entirely though.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: MP3 looping issues
« Reply #1 on: September 27, 2022, 12:11:33 am »
Thanks for bringing this up!

Can you create an issue on GitHub with some example code?

Let's see if lieff picks up the issue in minimp3, last few times they were quite responsive and fixed things upstream for us. :)

I've seen a lot of weird MP3 playbacks even from popular audio players, so I wouldn't hold my breath that it's something that we will/can easily fix in SFML. As far as I know you can't precisely extract the samples count / play duration from the MP3 encoding and thus if the provided meta information is invalid, it might lead to issues.
We'll certainly try to have a look, but at the end of the day, one might just reencode broken tracks.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything