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 reader support #1796

Closed
wants to merge 0 commits into from
Closed

MP3 reader support #1796

wants to merge 0 commits into from

Conversation

lieff
Copy link
Contributor

@lieff lieff commented May 10, 2021

This PR is related to the issue #1232 and adds mp3 reading support.
Also discussed on the forum
Example SFML/examples/sound/Sound.cpp is extended to play an mp3 file.

@lieff lieff mentioned this pull request May 10, 2021
2 tasks
Copy link
Member

@eXpl0it3r eXpl0it3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should update the comments on the these three openFrom* functions in the InputSoundFile header.
You may also add a comment regarding APEv2 causing potential issues.

////////////////////////////////////////////////////////////
/// \brief Open a sound file from a custom stream for reading
///
/// The supported audio formats are: WAV (PCM only), OGG/Vorbis, FLAC.
/// The supported sample sizes for FLAC and WAV are 8, 16, 24 and 32 bit.
///
/// \param stream Source stream to read from
///
/// \return True if the file was successfully opened
///
////////////////////////////////////////////////////////////
bool openFromStream(InputStream& stream);

cmake/Modules/FindMinimp3.cmake Outdated Show resolved Hide resolved
examples/sound/Sound.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/CMakeLists.txt Outdated Show resolved Hide resolved
src/SFML/Audio/SoundFileReaderMp3.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundFileReaderMp3.cpp Outdated Show resolved Hide resolved
@eXpl0it3r
Copy link
Member

You should also update the license.md to include the license for minimp3

@lieff lieff force-pushed the master branch 4 times, most recently from f50c7f1 to 8371a4c Compare May 11, 2021 11:06
@lieff lieff requested a review from eXpl0it3r May 11, 2021 11:59
Copy link
Member

@eXpl0it3r eXpl0it3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the two comments regarding use system deps and the windows.h conflict

@lieff lieff force-pushed the master branch 2 times, most recently from 4682f3a to 65293e7 Compare May 11, 2021 13:31
@lieff lieff requested a review from eXpl0it3r May 11, 2021 13:32
@eXpl0it3r eXpl0it3r requested a review from Bromeon May 11, 2021 13:47
Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the contribution!

I noticed a few smaller issues, but overall it looks good 🙂

CMakeLists.txt Outdated Show resolved Hide resolved
examples/sound/Sound.cpp Outdated Show resolved Hide resolved
include/SFML/Audio/InputSoundFile.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundFileReaderMp3.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundFileReaderMp3.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundFileReaderMp3.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundFileReaderMp3.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundFileReaderMp3.cpp Outdated Show resolved Hide resolved
examples/sound/Sound.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/SoundFileReaderMp3.cpp Outdated Show resolved Hide resolved
Comment on lines 74 to 78
m_io.read = readCallback;
m_io.seek = seekCallback;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of m_io remains uninitialized, since its type is a POD (plain old data) without constructor. This might lead to UB if one of the SoundFileReaderMp3 methods is called without a prior open() call, where m_io is fully initialized.

Also, m_decoder is not initialized.

Copy link
Contributor Author

@lieff lieff May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added memset initialize. Updated the PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the memory is zeroed, seek() and other operations are safe (i.e. fail properly)?
I don't know the implementation and assumptions of the underlying library.

Copy link
Contributor Author

@lieff lieff May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine, added tests for such case lieff/minimp3@b18d274 .
But calling open() method twice will lead to mem leak. Same for SoundFileReaderOgg as I can see. So calling it twice is forbidden? Or may be add protection against it?

src/SFML/Audio/SoundFileReaderMp3.cpp Outdated Show resolved Hide resolved
@eXpl0it3r
Copy link
Member

eXpl0it3r commented Nov 23, 2021

Woops, I screwed up, while trying to update the branch. Had to opened a new PR #1851 with the changes...
Sorry about that. 😓

@lieff
Copy link
Contributor Author

lieff commented Nov 23, 2021

Is something needed from my side? Looks like PR stuck on email delivery or something.

@eXpl0it3r
Copy link
Member

Nope, yeah seems like it somehow got lost, sorry about that.
I'll see to fix the typo as mentioned on the other PR and get the unity (not the engine) build to work.
If you want to take ownership of the PR again, then feel free to open one again, I messed up with updating the PR. 😓

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.6.0 via automation Dec 6, 2021
@eXpl0it3r eXpl0it3r added this to the 2.6 milestone Dec 6, 2021
@eXpl0it3r eXpl0it3r moved this from Discussion to Done in SFML 2.6.0 Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.6.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants