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 #258

Open
erikd opened this Issue May 6, 2017 · 30 comments

Comments

Projects
None yet
@erikd
Owner

erikd commented May 6, 2017

The MP3 patents have now fully expired so libsndfile can now add support.

The best bet would be https://www.mpg123.de which is LGPL and has updates as recently as this year.

I (@erikd) don't have sufficient time and motivation to do this, but would be happy to guide someone else.

@evpobr

This comment has been minimized.

Show comment
Hide comment
@evpobr

evpobr May 7, 2017

Collaborator

Milestone?

Collaborator

evpobr commented May 7, 2017

Milestone?

@erikd

This comment has been minimized.

Show comment
Hide comment
@erikd

erikd May 7, 2017

Owner

Until some actually steps forward to offer to do this and actually has some code that is worth reviewing, it doesn't make sense to have a milestone.

Owner

erikd commented May 7, 2017

Until some actually steps forward to offer to do this and actually has some code that is worth reviewing, it doesn't make sense to have a milestone.

@dabfalcon

This comment has been minimized.

Show comment
Hide comment
@dabfalcon

dabfalcon May 10, 2017

I hope someone steps forward and this feature would be great.

dabfalcon commented May 10, 2017

I hope someone steps forward and this feature would be great.

@erikd

This comment has been minimized.

Show comment
Hide comment
@erikd

erikd May 10, 2017

Owner

It also seems that https://www.mpg123.de is a decoder only. All the other supported formats have both encode and decode so that would have to be the same for MP3 especially fore the CSound use case.

liblame may be the best bet.

Owner

erikd commented May 10, 2017

It also seems that https://www.mpg123.de is a decoder only. All the other supported formats have both encode and decode so that would have to be the same for MP3 especially fore the CSound use case.

liblame may be the best bet.

@evpobr

This comment has been minimized.

Show comment
Hide comment
@evpobr

evpobr May 10, 2017

Collaborator

Agreed, mpg123 and LAME are the best.

Bad thing i will be buzy all the summer.

Collaborator

evpobr commented May 10, 2017

Agreed, mpg123 and LAME are the best.

Bad thing i will be buzy all the summer.

@dabfalcon

This comment has been minimized.

Show comment
Hide comment
@dabfalcon

dabfalcon May 11, 2017

Bad thing I'm too n00b. How hard is it?
I'm good with PHP / web / did a course on C++.

dabfalcon commented May 11, 2017

Bad thing I'm too n00b. How hard is it?
I'm good with PHP / web / did a course on C++.

@erikd

This comment has been minimized.

Show comment
Hide comment
@erikd

erikd May 11, 2017

Owner

This is definitely more difficult than using libsndfile as a library, mainly because the libsndfile API was specifically designed to be easy to use.

I would also rank this as more difficult than adding Opus support, because it requires you to hook up two libraries, one for decoding and one for encoding.

Owner

erikd commented May 11, 2017

This is definitely more difficult than using libsndfile as a library, mainly because the libsndfile API was specifically designed to be easy to use.

I would also rank this as more difficult than adding Opus support, because it requires you to hook up two libraries, one for decoding and one for encoding.

@faroit

This comment has been minimized.

Show comment
Hide comment
@faroit

faroit May 18, 2017

Also interesting, from this recent statement:

However, the end of the mp3 licensing program does not automatically mean that all mp3 technology is available license-free now. Apart from the core mp3 patents included in the licensing program, there might still be some implementation–specific patents (or patents for other functional enhancements) that have not expired. Thus, manufacturers will have to check the situation regarding their intended products first before including mp3.

faroit commented May 18, 2017

Also interesting, from this recent statement:

However, the end of the mp3 licensing program does not automatically mean that all mp3 technology is available license-free now. Apart from the core mp3 patents included in the licensing program, there might still be some implementation–specific patents (or patents for other functional enhancements) that have not expired. Thus, manufacturers will have to check the situation regarding their intended products first before including mp3.

@jpffitch

This comment has been minimized.

Show comment
Hide comment
@jpffitch

jpffitch Jun 4, 2017

uuuuuuIn csound at present we use a Russian library libmpadec for reading. Seems OK. Is it worth investigating? I should add that it has not been changed by the author for years but i have tweaked it, and have developer status for it. Code in csound tree and on sourceforge

jpffitch commented Jun 4, 2017

uuuuuuIn csound at present we use a Russian library libmpadec for reading. Seems OK. Is it worth investigating? I should add that it has not been changed by the author for years but i have tweaked it, and have developer status for it. Code in csound tree and on sourceforge

@jpffitch

This comment has been minimized.

Show comment
Hide comment
@jpffitch

jpffitch Jun 8, 2017

Is there a template for adding a new format or does one just edit, say, ogg.c to new code? Some time since I last tried (10 years) and things have changed.

jpffitch commented Jun 8, 2017

Is there a template for adding a new format or does one just edit, say, ogg.c to new code? Some time since I last tried (10 years) and things have changed.

@erikd

This comment has been minimized.

Show comment
Hide comment
@erikd

erikd Jun 8, 2017

Owner

Closest thing to a template is src/new.c.

Owner

erikd commented Jun 8, 2017

Closest thing to a template is src/new.c.

@eblanca

This comment has been minimized.

Show comment
Hide comment
@eblanca

eblanca Jun 13, 2017

For a wider view, i see on the decoding side there's much more: there is libmad which is very VERY stable and currently many distributions still provide it, not to mention its feature being based only on integer number calculation. This makes it very suitable for embedded systems, imho.
On the other hand, the writing/encoding side also offers many names to pick. If libsndfile will be able to read mpeg layer1/2/3 audio, then why offering layer3-only encoding? libtwolame provides layer2 encoding (layer2 is very often used even today, both into DVDs and into DVB streams) and for layer1, well, perhaps it may be also evaluated.

eblanca commented Jun 13, 2017

For a wider view, i see on the decoding side there's much more: there is libmad which is very VERY stable and currently many distributions still provide it, not to mention its feature being based only on integer number calculation. This makes it very suitable for embedded systems, imho.
On the other hand, the writing/encoding side also offers many names to pick. If libsndfile will be able to read mpeg layer1/2/3 audio, then why offering layer3-only encoding? libtwolame provides layer2 encoding (layer2 is very often used even today, both into DVDs and into DVB streams) and for layer1, well, perhaps it may be also evaluated.

@jpffitch

This comment has been minimized.

Show comment
Hide comment
@jpffitch

jpffitch Jun 13, 2017

Does the licence matter? GPL v LGPL ? With so many options I feel the need for guidance.

The mpg123 +lame plan looks like the mainsteam way to go, but I do not claim expertise in MP3.

jpffitch commented Jun 13, 2017

Does the licence matter? GPL v LGPL ? With so many options I feel the need for guidance.

The mpg123 +lame plan looks like the mainsteam way to go, but I do not claim expertise in MP3.

@erikd

This comment has been minimized.

Show comment
Hide comment
@erikd

erikd Jun 13, 2017

Owner

GPL is no good, but LGPL, BSD, MIT would all be fine.

Owner

erikd commented Jun 13, 2017

GPL is no good, but LGPL, BSD, MIT would all be fine.

@rjamorim

This comment has been minimized.

Show comment
Hide comment
@rjamorim

rjamorim Jun 29, 2017

not to mention its feature being based only on integer number calculation. This makes it very suitable for embedded systems, imho.

mpg123 can be built to perform only fixed-point math, and with better performance than MAD according to Thomas Orgis. Also, mpg123 has assembly optimizations for several architectures and SIMD flavors.

rjamorim commented Jun 29, 2017

not to mention its feature being based only on integer number calculation. This makes it very suitable for embedded systems, imho.

mpg123 can be built to perform only fixed-point math, and with better performance than MAD according to Thomas Orgis. Also, mpg123 has assembly optimizations for several architectures and SIMD flavors.

@eblanca

This comment has been minimized.

Show comment
Hide comment
@eblanca

eblanca Jul 4, 2017

mpg123 can be built to perform only fixed-point math

Didn't know this, great!

eblanca commented Jul 4, 2017

mpg123 can be built to perform only fixed-point math

Didn't know this, great!

@cvanwinkle

This comment has been minimized.

Show comment
Hide comment
@cvanwinkle

cvanwinkle Jul 31, 2017

FWIW, I've used mpg123 under LGPL in my program for MPEG-2 Audio Layer II decoding (aka MP2 audio) for a while and have validated that it decodes MP3 to my liking although we don't use it for that. So one nice thing about mpg123 is that it can decode several layers of MPEG audio and not just what is known as MP3. So assuming someone else does the work for wiring in mpg123 other than me (which is likely), it would be good to accommodate the other flavors as well.

cvanwinkle commented Jul 31, 2017

FWIW, I've used mpg123 under LGPL in my program for MPEG-2 Audio Layer II decoding (aka MP2 audio) for a while and have validated that it decodes MP3 to my liking although we don't use it for that. So one nice thing about mpg123 is that it can decode several layers of MPEG audio and not just what is known as MP3. So assuming someone else does the work for wiring in mpg123 other than me (which is likely), it would be good to accommodate the other flavors as well.

@erikd

This comment has been minimized.

Show comment
Hide comment
@erikd

erikd Jul 31, 2017

Owner

All the other formats supported by libsndfile support decoding and encoding. As I understand it mpg123 only does decoding, so something else will have to be used for the encoder, probably liblame.

Owner

erikd commented Jul 31, 2017

All the other formats supported by libsndfile support decoding and encoding. As I understand it mpg123 only does decoding, so something else will have to be used for the encoder, probably liblame.

@rjamorim

This comment has been minimized.

Show comment
Hide comment
@rjamorim

rjamorim Aug 1, 2017

Hello, Erik. Indeed, mpg123 only does decoding, and I strongly support using LAME for encoding. Back in 2004 I conduced a public listening test, and LAME got the best ranking (granted, it was a long time ago, but neither of the other encoders advanced much since then)
https://web.archive.org/web/20071016053926/http://www.rjamorim.com:80/test/mp3-128/results.html

Also, another reason I thought for choosing mpg123 over MAD (besides the licensing issue): MAD was last updated in 2004. mpg123 was last updated last week and the developer, Thomas Orgis, is very approachable.

rjamorim commented Aug 1, 2017

Hello, Erik. Indeed, mpg123 only does decoding, and I strongly support using LAME for encoding. Back in 2004 I conduced a public listening test, and LAME got the best ranking (granted, it was a long time ago, but neither of the other encoders advanced much since then)
https://web.archive.org/web/20071016053926/http://www.rjamorim.com:80/test/mp3-128/results.html

Also, another reason I thought for choosing mpg123 over MAD (besides the licensing issue): MAD was last updated in 2004. mpg123 was last updated last week and the developer, Thomas Orgis, is very approachable.

@foolswood

This comment has been minimized.

Show comment
Hide comment
@foolswood

foolswood Aug 3, 2017

Contributor

I am happy to have a go at this (unless someone else has started, in which case let me know).

Contributor

foolswood commented Aug 3, 2017

I am happy to have a go at this (unless someone else has started, in which case let me know).

@foolswood

This comment has been minimized.

Show comment
Hide comment
@foolswood

foolswood Aug 4, 2017

Contributor

Made a start (not working yet) over here: https://github.com/concert/libsndfile/tree/mp3.

Thinking about RDWR, that might be a bit tricky with the lame/mpg123 split, any thoughts on that (otherwise I might leave that mode unimplemented in the first attempt).

Contributor

foolswood commented Aug 4, 2017

Made a start (not working yet) over here: https://github.com/concert/libsndfile/tree/mp3.

Thinking about RDWR, that might be a bit tricky with the lame/mpg123 split, any thoughts on that (otherwise I might leave that mode unimplemented in the first attempt).

@foolswood

This comment has been minimized.

Show comment
Hide comment
@foolswood

foolswood Sep 20, 2017

Contributor

Read support PR is #322. At the moment I'm after shape review to see if I'm on the right track but hopefully it makes at least some sense :)

Contributor

foolswood commented Sep 20, 2017

Read support PR is #322. At the moment I'm after shape review to see if I'm on the right track but hopefully it makes at least some sense :)

@foolswood

This comment has been minimized.

Show comment
Hide comment
@foolswood

foolswood Sep 27, 2017

Contributor

Lame can use libsndfile for opening its input formats, so I'm concerned that using it as a decoder for libsndfile introduces a dependency loop. If lame were to split into liblame and the lame frontend (as I believe it is the latter that has the dependency) that would break the cycle. However given that's a big change and the last release was in 2012 I don't think that's likely.

Suggestions welcome.

Contributor

foolswood commented Sep 27, 2017

Lame can use libsndfile for opening its input formats, so I'm concerned that using it as a decoder for libsndfile introduces a dependency loop. If lame were to split into liblame and the lame frontend (as I believe it is the latter that has the dependency) that would break the cycle. However given that's a big change and the last release was in 2012 I don't think that's likely.

Suggestions welcome.

@foolswood

This comment has been minimized.

Show comment
Hide comment
@foolswood

foolswood Sep 28, 2017

Contributor

It has been suggested that including a copy of lame.h with libsndfile and loading at runtime with dlopen (and erroring if not found) makes it a runtime dependency and this may be a way to break the cycle.

@erikd Does this seem like an acceptable solution?

Contributor

foolswood commented Sep 28, 2017

It has been suggested that including a copy of lame.h with libsndfile and loading at runtime with dlopen (and erroring if not found) makes it a runtime dependency and this may be a way to break the cycle.

@erikd Does this seem like an acceptable solution?

@erikd

This comment has been minimized.

Show comment
Hide comment
@erikd

erikd Sep 28, 2017

Owner

Lame can use libsndfile for opening its input formats

The important part there is can. Ie its optional.

I'm concerned that using it as a decoder for libsndfile introduces a dependency loop.

Since is optional, there is no dependency loop.

last release was in 2012

I am really wary of depending a a piece of software that has not be updated since 2012.

Owner

erikd commented Sep 28, 2017

Lame can use libsndfile for opening its input formats

The important part there is can. Ie its optional.

I'm concerned that using it as a decoder for libsndfile introduces a dependency loop.

Since is optional, there is no dependency loop.

last release was in 2012

I am really wary of depending a a piece of software that has not be updated since 2012.

@rjamorim

This comment has been minimized.

Show comment
Hide comment
@rjamorim

rjamorim Sep 28, 2017

I am really wary of depending a a piece of software that has not be updated since 2012.

Lame is being updated again, release 3.100 should happen soon:
http://lame.cvs.sourceforge.net/viewvc/lame/lame/doc/html/history.html
(you can also check the mailing list to see the activity going on)

And either way, if you want to add open source MP3 encoding, there's little choice other than LAME - actively maintained or not.

rjamorim commented Sep 28, 2017

I am really wary of depending a a piece of software that has not be updated since 2012.

Lame is being updated again, release 3.100 should happen soon:
http://lame.cvs.sourceforge.net/viewvc/lame/lame/doc/html/history.html
(you can also check the mailing list to see the activity going on)

And either way, if you want to add open source MP3 encoding, there's little choice other than LAME - actively maintained or not.

@lieff

This comment has been minimized.

Show comment
Hide comment
@lieff

lieff Feb 12, 2018

There also libshine encoder https://github.com/toots/shine
It's included in modern linux distributions and still maintained.

lieff commented Feb 12, 2018

There also libshine encoder https://github.com/toots/shine
It's included in modern linux distributions and still maintained.

@evpobr evpobr added the help wanted label Mar 17, 2018

@ousia

This comment has been minimized.

Show comment
Hide comment
@ousia

ousia Jun 22, 2018

@lieff, although shine seems to be much faster than Lame, code is rather old and limited.

Lacking a psychoacoustic model may affect to file compression or sound quality (but I’m not an expert).

ousia commented Jun 22, 2018

@lieff, although shine seems to be much faster than Lame, code is rather old and limited.

Lacking a psychoacoustic model may affect to file compression or sound quality (but I’m not an expert).

@ousia

This comment has been minimized.

Show comment
Hide comment
@ousia

ousia Jun 22, 2018

@erikd, I have just discovered that lame-3.100 was released in October 2017 (http://lame.sourceforge.net/).

ousia commented Jun 22, 2018

@erikd, I have just discovered that lame-3.100 was released in October 2017 (http://lame.sourceforge.net/).

@kcat

This comment has been minimized.

Show comment
Hide comment
@kcat

kcat Aug 22, 2018

As an alternative to libmpg123 for decoding, there's minimp3. It's a much smaller code base (a single header, no external libraries), doesn't worry about a bunch of old micro-optimized assembly functions for 3/4/586 CPUs (that a modern compiler optimizer could probably outdo anyway), and performance is perfectly fine (utilizes SSE and NEON intrinsics when available). It's public domain (or CC0) so licensing isn't an issue. There's also currently a PR to get the "pure" floating-point samples generated from it, without clamping or 16-bit quantization noise from a float->short->float conversion.

kcat commented Aug 22, 2018

As an alternative to libmpg123 for decoding, there's minimp3. It's a much smaller code base (a single header, no external libraries), doesn't worry about a bunch of old micro-optimized assembly functions for 3/4/586 CPUs (that a modern compiler optimizer could probably outdo anyway), and performance is perfectly fine (utilizes SSE and NEON intrinsics when available). It's public domain (or CC0) so licensing isn't an issue. There's also currently a PR to get the "pure" floating-point samples generated from it, without clamping or 16-bit quantization noise from a float->short->float conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment