Compressing Wav file to mp3
● 1. IntrodUCtion
First, I don't meant to give you informations about how to understand the mp3 algorithm. My goal is to eXPlain how to use an already existing encoder with BCB.
● 2. Choosing the mp3 encoder
There are tons of mp3 encoders. Some of them are free others are not. Some are fast but produce an awful result. Others are slow but with Excellent result and give a high audio quality. The ideal would be a free, reasonably fast encoder giving a high audio quality, all at the same time.
Enjoy! This pearl exists. But we have to look at it in the GNU world. There is a GNU project, called LAME, for Lame Ain't a Mp3 Encoder, under the GPL license. The official web site of the LAME project is http://www.mp3dev.org/mp3/
Moreover, as it is a GNU project, we have Access to the source and there is a version compiled for Win32 in a DLL.
Among all the other encoders, I want to quote two of them. The first, FRAUNHOFER, because it is a fast and excellent encoder : http://www.iis.fhg.de/ but it's not free though.
The second because it's a very fast encoder but the audio result is awful. So don't use it except if you are looking for a fast encoder. It's the encoder from Xing Tech : http://www.xingtech.com/
Note : The Lame encoder has a limitation. The sample rate must be 32000, 44100 or 48000.?
● 3. Some informations about the WAV format
A wav file is just a collection of chunks. There is a format chunk wich contains all the informations about the samples. For instance, the bitrate, the number of channels, if it's stereo or mono... There is also a chunk containing the data. In other Words, this chunk contains all the samples. In front of the file, there are 12 characters indicating that the file is a wav file.
The two chunks given above must be present in the file.
There could be other chunk but we just ignore them. They are not needed for our purpose. If you want to know more about wav file, take a look at http://www.wotsit.org/ for a complete description.
The format chunk :
struct FormatChunk
{
char chunkID[4];
long chunkSize;
short wFormatTag;
unsigned short wChannels;
unsigned long dwSamplesPerSec;
unsigned long dwAvgBytesPerSec;
unsigned short wBlockAlign;
unsigned short wBitsPerSample;
// Note: there may be additional fields here, depending upon wFormatTag.
};
Above, you can see the struct representing the format chunk. The chunkID is always "fmt " with an ending space (4 characters). It's the identification of the chunk. All other chunk have such an ID. The chunkSize parameter contains the number of bytes of the chunk, the ID and chunkSize excluded.