MP3 Decoder Libraries Compared - by Wesley Moore

MP3 Decoder Libraries Compared

Published on

For my current software project I have the need to decode MP3 files for the purpose of producing an audio waveform. It doesn’t need to be overly accurate as the decoded samples will be displayed, not played. However it does need to be fast, as a typical use case for the application will be MP3 files of around 100Mb (full length CDs). The application is for Mac OS X, although the results of my testing below could be useful for other platforms.

Assisted by a code sample from Apple I wrote an initial version of the decoder that would read the source MP3 file and write the raw linear PCM data out to a file. I did this using the Core Audio framework built into Mac OS X. Once the program was working I tested it against some sample files and came to the conclusion that 4 seconds to decode a 3 min track was great but over 100 seconds for a full length CD, not so great.

I did some searching and came up with two other libraries that seemed well suited to the task of MP3 decoding, they were mpg123 (libmpg123) and MAD (libmad). mpg123 had claims of being very fast, mad claimed it was very accurate.


I built the two additional libraries with the default configuration options, except for libmad, which I added the --enable-speed option. With the help of example code I made programs out of each that were comparable to the first version for Core Audio. I.e. MP3 file in, 16-bit Linear PCM audio samples out.

To provide a benchmark I wrote a script that would run each of the three programs against a source MP3 file. Each program reported the elapsed time (via time(3)) and the processor time (via clock(3)) when it finished decoding. The programs were run one after another on the source file 10 times. Their PCM output was written to a new file for each invocation.


The tests were performed on my dual 1.8Ghz Power Mac G5 with 2Gb RAM running Mac OS X 10.5.2. I didn’t make any special attempt to quit all other running programs while I ran the tests but iTunes was paused and nothing was doing anything significant in the background. I also didn’t do anything on the computer while the tests were running.


The results of the tests for my sample MP3s is below. The individual times were averaged over the 10 runs for each library. The standard deviation of the processor time is also included to given an indication of how consistent the decoding time was.

Small File

Size 4,296,251 bytes
Bitrate 160 kbps
Channels 2 (Joint Stereo)
Length 3:34
Library Average Elapsed Time Average Processor Time Processor Time Std. Deviation
mpg123 2.30 1.71 0.95
Core Audio 4.10 3.63 0.27
mad 4.80 4.42 0.02

Medium Mono File

Size 83,091,456 bytes
Bitrate 320 kbps
Channels 1 (Mono)
Length 34:37
Library Average Elapsed Time Average Processor Time Processor Time Std. Deviation
mpg123 11.10 9.40 0.03
mad 26.90 24.60 0.03
Core Audio 33.60 30.33 1.18

Large File

Size 126,083,072 bytes
Bitrate 224 kbps
Channels 2 (Joint Stereo)
Length 1:15:02
Library Average Elapsed Time Average Processor Time Processor Time Std. Deviation
mpg123 37.00 32.21 0.19
Core Audio 84.00 78.34 0.34
mad 100.10 94.44 0.15

Large VBR File

Size 123,028,672 bytes
Bitrate 210 kbps (VBR)
Channels 2 (Joint Stereo)
Length 1:17:46
Library Average Elapsed Time Average Processor Time Processor Time Std. Deviation
mpg123 37.90 32.96 0.13
Core Audio 86.40 80.52 0.18
mad 104.30 98.43 0.10

Note: All files had a 44100 Hz sample rate.


The results speak for themselves, mpg123 lives up to its claim of being high performance. In all the tests it was consistently around twice as fast - a very impressive result. Its certainly the library I’ll be using. Of note it also has quite a nice API. Of the three Core Audio’s has the most tedious API but it is low level and capable of quite a bit more than what I was using it for.

Comment icon Stay in touch!

Follow me on Twitter or Mastodon, subscribe to the feed, or send me an email.