5

in my app i need to decode an mp3 file into a pcm buffer. that's a lot of data so i downsample it to mono 22050Hz as i read and decode it.

at the moment i'm using javazoom jlayer decoder http://www.javazoom.net/javalayer/javalayer.html

its working but its slow, 30secs to decode a 3min song in run mode, ages in debug mode. on my windows machine using libmpg i can do that in about 1 second.

is there a faster way that anyone knows for sure is faster? i don't want to waste time implementing another method if its not significantly faster. thanks.

by the way, in my app, i need the whole thing downloaded to a pcm buffer in memory so i'm not interested in things that simply play mp3 files.

steveh
  • 1,352
  • 2
  • 27
  • 41

2 Answers2

1

This is the moment when you go Native in android!

-use NDK and find a fast c/c++ library (they are like 20x faster than jlayer, for example 9min sogn in 18sec)

-here are some libs that can be usefull:

http://www.mpg123.de/

www underbit.com/products/mad/

www oracle.com/technetwork/java/javase/download-137625.html (not sure does this one supports MP3toPCM)

lame.sourceforge.net/about.php (this one has an android opensource project on github that i hope is going to be very usefull to you! https://github.com/intervigilium/liblame)

alabrosk
  • 11
  • 1
1

JLayer is a conversion of the original Fraunhoffer mp3 C code. Sadly the person that converted it, has scattered a wide range of needless buffer copies throughout the code because he probably didn't understand very well what was happening (not a problem, those things happen). Yet, the result is a very slow mp3 decoder. Eventually we started to remove all needless buffer copies and added exact seekability to the JLayer source. The repository and a demo on how to use it can be found at http://bpmdj.yellowcouch.org/credits.html, section JLayer1.0.1. The result is about 2.5 times faster than the original.

  • 2
    The demos are bad. All I want is to decode MP3 to PCM. – NateS Jun 26 '17 at 23:16
  • I used this modified version of JLayer and benchmarked it: in my case (decoding a few mp3 mono tracks of a few seconds each) this version is not faster than the original one. Timings are roughly the same. – Stéphane Feb 22 '19 at 13:11