Click here to Skip to main content
Click here to Skip to main content

C# MP3 Compressor

By , 15 Oct 2012
 

Introduction

Please note - this tip is merely an update to the code published in the article C# MP3 Compressor. I did not write any of this original code, but I've found it very useful so I created this tip to fix a couple of bugs and provide a little more background on the RIFF format. 

The original project is a very useful example of MP3 compression and WAV to MP3 conversion, but I was experiencing problems with WAV files that contain additional chunks (e.g., BWAV format, stuff from ProTools, etc.). The WaveStream class made some unsafe assumptions about the structure of the RIFF data, so here is my fix for the problems I encountered.

As with the original, there is code from the article: A low level audio player in C# by Ianier Munoz. In fact, this is the only code I've changed.

The project has also been upgraded to VS2010.

Background

Here are a couple of useful articles about the RIFF file format:

Using the Code

The only changes are in the WaveStream.cs file, in the yeti.mmedia project.

There are two main bug fixes:

  1. It is no longer assumed that the "fmt" chunk will be the first data chunk after the RIFF header. It might well not be.
  2. The old code assumed that all the chunk headers would be DWORD (4 byte) aligned. This is not at all guaranteed, the RIFF format only mandates word (2 byte) alignment. In some cases, this would cause the chunks to be missed, and the file would fail to read.

The code now also accounts for cases where a chunk's data is an odd number of bytes long, in which case there should be a padding byte which is not counted in the chunk length field. Apparently. I've never seen this in a real life file, but if it occurs the code should handle it.

Additional Resources

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Beercolhol
United Kingdom United Kingdom
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionnot for windows 8 metromemberatmonline10 Oct '12 - 6:06 
AnswerRe: not for windows 8 metromemberBeercolhol15 Oct '12 - 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 15 Oct 2012
Article Copyright 2012 by Beercolhol
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid