Skip to content
MP3 decoder in managed .NET code.
Branch: master
Clone or download
This branch is 22 commits ahead of ZaneDubya:master.

Latest commit

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 Ported MP3Sharp to netstandard2.0 and the new csproj format. Jun 20, 2017
MP3Sharp Rebuild package in release mode. Oct 9, 2019
XNA4Sample MP3Stream now automatically sets frequency on file open. Jul 14, 2015
.gitignore Update .gitignore. Jun 7, 2017
MP3Sharp.sln Split the solution into two. Jun 7, 2017
MP3Sharp.sln.DotSettings Added code style settings for the solution. Jan 4, 2018
XNA4Sample.sln Split the solution into two. Jun 7, 2017
license.txt Add LGPL license. Jul 2, 2015 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.