|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Introduction'madxlib' is a source code for creating a Windows DLL, that performs buffer-based MP3 decoding. It allows you to build interfaces that can process a given MP3 file in chunks at the intervals you specify, and returns the decoded 16-bit PCM samples in a buffer. Backgroundmadxlib effectively supersedes madlldlib, another MP3 decoding source I have released via The Code Project. The two sources differ in that, madlldlib took as parameters the location of the input MP3 and output WAV/PCM files and performed the conversion while passing status back to the calling code. This gave little control to the calling code to pause, restart, queue the samples, etc. madxlib rectifies this by relying on the calling code to fill the input buffer (which can come from a local file, the Internet, network share, etc). It then returns an output buffer of the converted PCM samples and waits for the next input. This source, like madlldlib, was based on the madlld source, which was designed as a tutorial of the low-level functions of the libmad library. Using the CodeIncluded in the source is the file test.cpp. This is a simple example demonstrating how to program the madxlib API. It consists of a single Within // Output file and output buffer unsigned char in_buffer[MADX_INPUT_BUFFER_SIZE + MAD_BUFFER_GUARD]; unsigned char out_buffer[MADX_OUTPUT_BUFFER_SIZE]; size_t a; size_t in_size = MADX_INPUT_BUFFER_SIZE + MAD_BUFFER_GUARD; // Structure necessary to use madxlib madx_house mxhouse; // Status and control madx_stat mxstat; // Catch signals from madx_read() madx_sig mxsig;
Next, // Initialize madxlib madx_init(out_buffer, &mxhouse);
Next test.cpp opens its input and output files with // This loop reads input until EOF, fills the // output buffer, writes the output file, and // checks for errors. The return values from // madx_read() must be inspected after each // call to determine the appropriate action. do { // Read input, pass processed data to out_buffer mxsig = madx_read( in_buffer, out_buffer, &mxhouse, &mxstat ); if (strcmp(mxstat.msg, "")) printf("%s\n", mxstat.msg); if (mxsig == ERROR_OCCURED) // Error { printf("Unrecoverable error %s\n", mxstat.msg); break; } else if (mxsig == MORE_INPUT) // Fill buffer { if (mxstat.buffstart) // Fill partial buffer { if ( (a = fread(mxstat.buffstart, 1, mxstat.readsize, in_file))== mxstat.readsize) { printf("Filling buffer.\n"); } else if (feof(in_file)) // EOF must be flagged { mxstat.is_eof = 1; mxstat.readsize = a; } else printf("Error! %d\n", ferror(in_file)); } else // Read full buffer { if ( fread(in_buffer, 1, mxstat.readsize, in_file) == mxstat.readsize) { printf("Fill buffer full.\n"); } else if (feof(in_file)) // EOF must be flagged { mxstat.is_eof = 1; mxstat.readsize = a; } else printf("Error! %d\n", ferror(in_file)); } } else if (mxsig == FLUSH_BUFFER) // Output to file { if (fwrite(out_buffer, 1, mxstat.write_size, out_file) == mxstat.write_size) printf("Writing buffer.\n"); else printf("fwrite() error\n"); } else if (mxsig == EOF_REACHED) // Input file EOF { if ( (a = fwrite(out_buffer,1,mxstat.write_size,out_file)) != mxstat.write_size) { printf("Error with final write! out_size:%d, fwrite: %d\n", mxstat.write_size, a); } else printf("Finished. out_size:%d, fwrite: %d\n", mxstat.write_size, a); break; } } while(1); The above
After If Note that after both reads EOF is checked, and if reached the variable All that remains is to pass the // Clean-up madx_deinit(&mxhouse); fclose(out_file); return; Notes
|
||||||||||||||||||||||