Libmad: is an open source High-precision MPEG Audio Decoder library that supports MPEG-1 (Layer I, Layer II and LAYERIII (i.e. MP3). Libmad provides 24-bit PCM output, fully fixed-point computing, and is ideal for use on platforms without floating-point support. With a series of APIs provided by Libmad, MP3 data decoding can be done very simply. In the Libmad source code file directory of the Mad.h file, you can see most of the library's data structure and APIs.
PCM coding: That is, pulse code modulation code.
PCM converts a continuous analog signal into a digital code by sampling, quantifying, and encoding three steps.
The main data structure in Libmad:
main data structure |
|
struct mad_stream |
|
|
Defines the audio sampling rate, the number of channels, and the PCM sampling data to initialize the audio |
struct mad_frame |
|
Mad uses the callback function mechanism to decode, and each callback function returns an enumerated type Mad_flow, through which Mad_flow can control the decoding process. In the case of untreated, the mad general output 32bit, in little endian format stored in the mad_fixed_t data. But most of the sound cards can support output up to 32bit precision data, it must also be quantified mad_fixed_t, smooth processing and jitter, so that the sampling signal to 16bit precision. Mad is responsible for the decoding process, which works by obtaining input from the outside, decoding it by frame, returning information in the decoding process, and then getting the decoded result. Developers to manually set the input output.
In Libmad, a decoding source program MINIMAD.C is provided to decode the MP3 file into PCM data and display its data on the terminal.
Now take the source code as an example to write our own Libmad based MP3 player.
We also turn on our audio device "/DEV/DSP" when we open our audio program.
static int sfd;
if ((SFD = open ("/DEV/DSP", O_wronly)) < 0)
{
printf ("Can NOT open device!!! /n ");
return 1;
}