minimad.c File Reference

This is perhaps the simplest example use of the MAD high-level API. More...

#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "mad.h"

Include dependency graph for minimad.c:

Go to the source code of this file.

Data Structures

struct  buffer
 This is a private message structure. More...

Functions

static int decode (unsigned char const *start, unsigned long length)
 This is the function called by main() above to perform all the decoding.
int main (int argc, char *argv[])
static enum mad_flow input (void *data, struct mad_stream *stream)
 This is the input callback.
static signed int scale (mad_fixed_t sample)
 The following utility routine performs simple rounding, clipping, and scaling of MAD's high-resolution samples down to 16 bits.
static enum mad_flow output (void *data, struct mad_header const *header, struct mad_pcm *pcm)
 This is the output callback function.
static enum mad_flow error (void *data, struct mad_stream *stream, struct mad_frame *frame)
 This is the error callback function.


Detailed Description

This is perhaps the simplest example use of the MAD high-level API.

Standard input is mapped into memory via mmap(), then the high-level API is invoked with three callbacks: input, output, and error. The output callback converts MAD's high-resolution PCM samples to 16 bits, then writes them to standard output in little-endian, stereo-interleaved format.

See also:
main()

Definition in file minimad.c.


Function Documentation

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

This is the function called by main() above to perform all the decoding.

It instantiates a decoder object and configures it with the input, output, and error callback functions above. A single call to mad_decoder_run() continues until a callback function returns MAD_FLOW_STOP (to stop decoding) or MAD_FLOW_BREAK (to stop decoding and signal an error).

Definition at line 198 of file minimad.c.

References error(), input(), buffer::length, mad_decoder_finish(), mad_decoder_init(), MAD_DECODER_MODE_SYNC, mad_decoder_run(), output(), and buffer::start.

Referenced by main().

Here is the call graph for this function:

static enum mad_flow error ( void *  data,
struct mad_stream stream,
struct mad_frame frame 
) [static]

This is the error callback function.

It is called whenever a decoding error occurs. The error is indicated by stream->error; the list of possible MAD_ERROR_* errors can be found in the mad.h (or stream.h) header file.

Definition at line 173 of file minimad.c.

References mad_stream::error, MAD_FLOW_CONTINUE, mad_stream_errorstr(), buffer::start, and mad_stream::this_frame.

Referenced by decode(), III_decode(), and mad_layer_III().

Here is the call graph for this function:

static enum mad_flow input ( void *  data,
struct mad_stream stream 
) [static]

This is the input callback.

The purpose of this callback is to (re)fill the stream buffer which is to be decoded. In this example, an entire file has been mapped into memory, so we just call mad_stream_buffer() with the address and length of the mapping. When this callback is called a second time, we are finished decoding.

Definition at line 86 of file minimad.c.

References buffer::length, MAD_FLOW_CONTINUE, MAD_FLOW_STOP, mad_stream_buffer(), and buffer::start.

Referenced by decode().

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 42 of file minimad.c.

References decode().

Here is the call graph for this function:

static enum mad_flow output ( void *  data,
struct mad_header const *  header,
struct mad_pcm pcm 
) [static]

This is the output callback function.

It is called after each frame of MPEG audio data has been completely decoded. The purpose of this callback is to output (or play) the decoded PCM audio.

Definition at line 132 of file minimad.c.

References mad_pcm::channels, mad_pcm::length, MAD_FLOW_CONTINUE, mad_pcm::samples, and scale().

Referenced by decode(), and III_decode().

Here is the call graph for this function:

static signed int scale ( mad_fixed_t  sample  )  [inline, static]

The following utility routine performs simple rounding, clipping, and scaling of MAD's high-resolution samples down to 16 bits.

It does not perform any dithering or noise shaping, which would be recommended to obtain any exceptional audio quality. It is therefore not recommended to use this routine if high-quality output is desired.

Definition at line 110 of file minimad.c.

References MAD_F_FRACBITS, and MAD_F_ONE.

Referenced by dctIV(), output(), and sdctII().


Generated on Tue Jun 10 12:14:18 2008 for libmad by  doxygen 1.5.5