#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "mad.h"
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. |
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.
Definition in file minimad.c.
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().
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().
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().
int main | ( | int | argc, | |
char * | argv[] | |||
) |
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().
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.