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

add mp3 support #782

Merged
merged 14 commits into from
Jun 8, 2023
Merged

add mp3 support #782

merged 14 commits into from
Jun 8, 2023

Conversation

dzosz
Copy link
Collaborator

@dzosz dzosz commented Apr 23, 2023

Summary of PR content:

@dzosz dzosz linked an issue Apr 23, 2023 that may be closed by this pull request
dzosz added 4 commits April 23, 2023 02:36
* provide unified interface for reading streamed memory
* reuse single filehandler buffer from MusicStream
drmp3 is a minimalistic mp3 decoder known from SDL2 mixer library
* reuse code from ogg decoder
* change interface to expose number of channels instead format
* code cleanup and const correctness
replace common buffer type with uint8_t
rts/System/Sound/OpenAL/Mp3Decoder.cpp Outdated Show resolved Hide resolved
rts/System/Sound/OpenAL/Mp3Decoder.cpp Outdated Show resolved Hide resolved
class Mp3Decoder
{
public:
long Read(uint8_t *buffer, int length, int , int , int , int *);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider naming the arguments, especially since it's not obvious what they are from context

Suggested change
long Read(uint8_t *buffer, int length, int , int , int , int *);
long Read(uint8_t *buffer, int length, int bigendianp, int word, int sgned, int *bitstream);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is the common interface for all decoders. mp3 decoder does not use unnamed variables.

rts/System/Sound/OpenAL/SoundBuffer.cpp Outdated Show resolved Hide resolved
rts/System/Sound/OpenAL/MusicStream.cpp Outdated Show resolved Hide resolved
rts/System/Sound/OpenAL/MusicStream.cpp Outdated Show resolved Hide resolved
Comment on lines +18 to +20
// this buffer gets recycled by each new stream, across *all* audio-channels
// as a result streams are limited to only ever being played within a single
// channel (currently BGMusic), but cause far less memory fragmentation
Copy link
Collaborator

Choose a reason for hiding this comment

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

this pre-existing limitation is pretty terrible, i have no idea to what extent this PR relies on it (so this is mostly an opportunistic remark) but regardless it would be good to gradually remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had this in mind but I did not want the scope of this PR outgrow the initial objective of adding mp3 support. I'm happy to work on it in separate issue if that's ok.

return;
}

if (fileBuffer.GetFileExt() == std::string_view{"mp3"}) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

does the string_view bring any benefit here over just fileBuffer.GetFileExt() == "mp3"?

Copy link
Collaborator Author

@dzosz dzosz Apr 25, 2023

Choose a reason for hiding this comment

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

Defensive programming. I wanted to avoid a case where we compare raw const char* without strcmp. Now GetFileExt is already a std::string but in case the return type changes to const char* the code without explicit string_view conversion would start failing.

rts/System/Sound/OpenAL/MusicStream.cpp Outdated Show resolved Hide resolved
} , decoder);
if (!loaded) {
LOG_L(L_ERROR, "[MusicStream::Play] Could not load file: %s", path.c_str());
source = 0; // invalidate
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps there could be a well-named Invalidate() that would abstract the source = 0 underneath?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this definitely should be changed. the class kind of reimplements std::optional within self but this can be fixed in next PR that separates MusicStream from SoundSource.

@lhog
Copy link
Collaborator

lhog commented Apr 25, 2023

Please add LICENSE.html of Dr mp3

@p2004a
Copy link
Collaborator

p2004a commented Apr 25, 2023

Out of curiosity: what is the motivation of adding old mp3 format at this time, when there are formats like opus that beat it at all dimensions and vorbis that is also AFAIK better than mp3 is already part of the engine?

@sprunk
Copy link
Collaborator

sprunk commented Apr 25, 2023

Are these formats better in availability of actual files? MP3's are still everywhere and it's good if people making games on the engine can just use them without having to convert or do any other extra steps.

@p2004a
Copy link
Collaborator

p2004a commented Apr 25, 2023

I thought that encoding to a good format is a very minor step in overall sound creation. Motivation of "we just want to allow people to drop in mp3s they already have to make it even easier" is fine. (The motivation is basically social and not technical)

@dzosz
Copy link
Collaborator Author

dzosz commented Apr 26, 2023

Please add LICENSE.html of Dr mp3

done

@lhog
Copy link
Collaborator

lhog commented May 5, 2023

I second what @sprunk said above. mp3 might not be the best, but it's pretty common and having it covered up should not be redundant. Let's target this one after the stable version has been released.

@lhog
Copy link
Collaborator

lhog commented Jun 3, 2023

Sorry for the long wait, is it ready for merge?

@dzosz
Copy link
Collaborator Author

dzosz commented Jun 3, 2023

Sorry for the long wait, is it ready for merge?

looks good

@lhog lhog merged commit a0fdd1f into beyond-all-reason:BAR105 Jun 8, 2023
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

Successfully merging this pull request may close these issues.

Add support of .mp3 format
4 participants