Data flow of key structures

Source: Internet
Author: User

Depending on how you use the platform, you can open a MP3 file in a variety of ways, minimad.c a way to open the sample file under Unix, and it's not hard to rewrite it as Windows:

CFile file;

if(!file.Open("E:\\A.mp3",CFile::modeRead|CFile::shareDenyRead,NULL))

{

cout<<"can not open file!"<<endl;

return -1;

}

DWORD file_size=file.GetLength();

DWORD file_readerd=0;

if(file_size==0)

{

cout<<"File Error!"<<endl;

return -1;

}

unsigned char * file_buffer=(unsigned char *)malloc(file_size);

do

{

file_readerd=file.Read(file_buffer,file_size);

} while (file_readerd);

free(file_buffer);

file.Close();

The entire MP3 file is mapped to the File_buffer. This file_buffer can be passed on to the decoder decoder. However, the parameters of Mad_decoder_init () and Mad_decoder_run () do not have a place in which to pass this pointer. Minimad,c uses one of the simplest "custom message structures" (private messages structure) to pass the start and length of the buffer to the Mad_decoder structure by Mad_decoder_init (). Then decode the Mad_decoder with Mad_decoder_run ():

static

int decode(unsigned char const *start, unsigned long length)

{

struct buffer buffer;

struct mad_decoder decoder;

int result;

/* initialize our private message structure */

buffer.start = start;

buffer.length = length;

/* configure input, output, and error functions */

mad_decoder_init(&decoder, &buffer,

input, 0 /* header */, 0 /* filter */, output,

error, 0 /* message */);

/* start decoding */

result = mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);

/* release the decoder */

mad_decoder_finish(&decoder);

return result;

}

Combining the previous analysis, we get the general trend of data: first, we call the Mad_stream_buffer () function by the input callback function to bind the MP3 file to a mad_stream structure, and then the decoder separates the frame from the stream. Finally decode a single frame to get PCM.

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.