Skip to content
MP3 decoder in managed .NET code.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Images Unimplifying... Jul 13, 2015
MP3Sharp.UnitTests Added sample mp3 and additional tests. Jul 16, 2015
MP3Sharp Merge remote-tracking branch 'origin/master' into renamed-variables Jul 17, 2015
.gitattributes Getting rid of awful icons. Jul 12, 2015
.gitignore Getting rid of awful icons. Jul 12, 2015
XNA4Sample.sln Breaking out OutputChannels to own file. Jul 13, 2015
license.txt Update Jul 15, 2015


Decode MP3 files to PCM bitstreams entirely in .NET managed code:


To use MP3Sharp, you will need: an audio device that accepts PCM data, an array of bytes to act as the PCM data buffer (default size is 4096 bytes), and a MP3 file. That's it!

The default interface to MP3Sharp is the MP3Stream class. An instance of MP3Stream takes a filepath to a MP3 file as a parameter and outputs PCM data:

// open the mp3 file.
MP3Stream stream = new MP3Stream(@"sample.mp3");
// Create the buffer.
byte[] buffer = new byte[4096];
// read the entire mp3 file.
int bytesReturned = 1;
int totalBytesRead = 0;
while (bytesReturned > 0)
    bytesReturned = stream.Read(buffer, 0, buffer.Length);
    totalBytesRead += bytesReturned;
// close the stream after we're done with it.

So simple!


MP3Sharp is licensed under the LGPL Version 3.


MP3Sharp is a port of JavaLayer, a MP3 decoder written by JavaZoom and released under the LGPL. JavaLayer was initially ported to C# by Robert Burke, in what he modestly describes as a 'half day project'. tekHedd added some significant speed optimizations. I've spent a few weeks of evenings cleaning up the code and reducing redundancies throughout. The sample MP3 file used in this project is by BenSound, and is included under the terms of the Creative Commons - Attribution - No Derivative Works license.


  • Many of the variables throughout the ported code are poorly named. I've done my best to clean them up, but don't know enough about the MP3 specification to suggest better names for most of them.
  • There is a large amount of dead code and variables that are assigned but never used, and thus significant area for improvement of decoding (using these variables properly) or optimization (removing them altogether).
You can’t perform that action at this time.