MP3 decoder player based on Libmad

Source: Internet
Author: User

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;     
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.