/MP3Sharp

MP3 decoder in managed .NET code.

Primary LanguageC#GNU Lesser General Public License v3.0LGPL-3.0

MP3Sharp

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

SETUP

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.
stream.Close();

So simple!

LICENSE

MP3Sharp is licensed under the LGPL Version 3.

CREDITS

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.

FUTURE IMPROVEMENT

  • 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).