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

Certain MP3 files don't keep looping when using sf::Music #2215

Open
Biohazard90 opened this issue Sep 27, 2022 · 8 comments · May be fixed by #2995
Open

Certain MP3 files don't keep looping when using sf::Music #2215

Biohazard90 opened this issue Sep 27, 2022 · 8 comments · May be fixed by #2995

Comments

@Biohazard90
Copy link

Biohazard90 commented Sep 27, 2022

Certain MP3 files not looping

Certain mp3 files are not looping correctly when playing them with sf::Music and looping enabled. One of them doesn't loop at all (issue 1), the other stops looping after the first time (issue 2).

Your environment

  • Windows 10 Pro
  • SFML 2.6.X
  • VS 17.3.3 Pro, MSVC C++ 20
  • Static linking

Steps to reproduce

#include "sfml/Audio/Music.hpp"

#include <Windows.h>

using namespace std;

int main(int argc, char *argv[])
{
	sf::Music music;
	music.setLoop(true);
	music.setVolume(10);

	// This file stops playing after the first playthrough (issue 1)
	//if (music.openFromFile("SIERRA - UNBROKEN (mp3cut.net).mp3"))
	//	music.play();

	// This file stops playing after the second playthrough (issue 2)
	if (music.openFromFile("Feeling - Tung Wasabi (mp3cut.net).mp3"))
		music.play();
	
	MSG msg = {};
	while (GetMessage(&msg, 0, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return 0;
}

Expected behavior

The music should never stop playing.

Actual behavior

The file "SIERRA - UNBROKEN (mp3cut.net).mp3" stops playing after the first playthrough (issue 1), the file "Feeling - Tung Wasabi (mp3cut.net).mp3" stops playing after the second playthrough (issue 2).

Analysis

In both cases the problem is that SFML only loops a file if the expected EOF point is reached and minimp3 doesn't reach it, instead it fails reading more data.

Regarding issue 1, I believe the file may report the incorrect number of samples and minimp3 takes it at face value, then just stops streaming too early when EOF is reached. Since I currently needed a solution to this, I made a workaround for myself so SFML continues looping when EOF is reached too early: Biohazard90@bcd6798 Note, this is not a fix I am proposing, it's just to illustrate the issue and how I'm solving it since I cannot fix the mp3 files I'm working with.

Regarding issue 2, minimp3 seems to be incorrectly seeking to 0 and I proposed a fix here already: lieff/minimp3#101

Here are the two mp3 files that have these issues:
Example mp3 files

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.6.0 via automation Sep 27, 2022
@eXpl0it3r eXpl0it3r added this to the 2.6 milestone Sep 27, 2022
@eXpl0it3r eXpl0it3r moved this from Discussion to WIP in SFML 2.6.0 Sep 27, 2022
@karplucas
Copy link

SFML supports the audio file formats WAV, OGG/Vorbis and FLAC. Due to licensing issues MP3 is not supported.

@Biohazard90
Copy link
Author

SFML supports the audio file formats WAV, OGG/Vorbis and FLAC. Due to licensing issues MP3 is not supported.

No, MP3 is supported by SFML 2.6.X. The last patents have expired in 2017.

@karplucas
Copy link

karplucas commented Dec 1, 2022

You're right, didnt know it was added to SFML 2.6.x.

Reproduced your issue and checked whether AL was processing the stream buffers correctly and it is indicating that there are none being processed after the first loop. So loop looks to be working fine, but likely the seek to Time::Zero once the mp3 is finished is not working.

Not knowledgeable enough to edit minimp3, but I did try to verify your solution and did not see it working for me.

@eXpl0it3r
Copy link
Member

Looks like @lieff is currently not responding, as such, I don't see us fixing this for the up coming SFML 2.6 release and I'll move it to SFML 2.6.1 in hopes they come back at one point.

@eXpl0it3r eXpl0it3r removed this from WIP in SFML 2.6.0 Jan 22, 2023
@eXpl0it3r eXpl0it3r modified the milestones: 2.6, 2.6.1 Jan 22, 2023
@TiEul
Copy link

TiEul commented Jun 7, 2023

Hey @eXpl0it3r, at this point it is kind of safe to assume that minimp3 is abandoned, is it maybe possible that the SFML team creates a fork of it and maintains that separate fork for future bug fixes? I am not sure what the best-practice is in such a case, but it is a bit of a shame that this cannot be fixed due to an abandoned repo.

@Bromeon
Copy link
Member

Bromeon commented Jun 7, 2023

Hey @eXpl0it3r, at this point it is kind of safe to assume that minimp3 is abandoned, is it maybe possible that the SFML team creates a fork of it and maintains that separate fork for future bug fixes? I am not sure what the best-practice is in such a case, but it is a bit of a shame that this cannot be fixed due to an abandoned repo.

I don't think we have the capacity to maintain such a fork.

Maybe there have been other people forking already, are you aware of anything? Otherwise we'll probably need to look for alternatives. In that case (different MP3 backend), it's more likely that this lands in SFML 3 though.

@eXpl0it3r eXpl0it3r modified the milestones: 2.6.1, 2.6.2 Nov 4, 2023
@eXpl0it3r eXpl0it3r linked a pull request May 12, 2024 that will close this issue
5 tasks
@eXpl0it3r
Copy link
Member

I've tested the provided files with the dr_mp3 implementation and they loop without issues. dr_mp3 uses most of the minimp3 implementation with some API improvements and is written and maintained by the same person that wrote miniaudio and they're still quite active.

It's been a while but if anyone here wants to test the #2995 PR, @Biohazard90 / @TiEul

@TiEul
Copy link

TiEul commented May 13, 2024

@eXpl0it3r Thanks, we don't have the resources to verify it right now but we'll add it to our to-do list and we'll provide feedback here.

@eXpl0it3r eXpl0it3r linked a pull request May 14, 2024 that will close this issue
5 tasks
@eXpl0it3r eXpl0it3r changed the title Certain MP3 files don't keep looping when using sf::Music Certain MP3 files don't keep looping when using sf::Music May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants