Main Page   Data Structures   File List   Data Fields   Globals  

mp3.c File Reference

#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <mad.h>
#include <stdbool.h>
#include <pthread.h>
#include <assert.h>
#include "common.h"
#include "mp3.h"
#include "daisylibao.h"
#include "audio.h"
#include "report.h"
#include "snprintf/snprintf.h"
#include "parsetime.h"

Go to the source code of this file.

Functions

enum mad_flow input (audio_data_t _data, struct mad_stream *stream)
__inline__ signed long audio_linear_dither (unsigned int bits, mad_fixed_t sample, struct audio_dither *dither)
int mp3_decode (struct_audio_data_t *data)
__inline__ unsigned long prng (unsigned long state)
enum mad_flow output (audio_data_t _data, struct mad_header const *header, struct mad_pcm *pcm)
enum mad_flow error (audio_data_t _data, struct mad_stream *stream, struct mad_frame *frame)
enum mad_flow header (audio_data_t _data, struct mad_header const *header)
audio_ditherinit_dither (void)
void reset_dither (struct audio_dither *dither)
void free_dither (struct audio_dither *dither)
void mp3_init (struct_audio_data_t *data)
bool mp3_play (struct_audio_data_t *data)
void mp3_close (struct_audio_data_t *data)


Function Documentation

__inline__ signed long audio_linear_dither unsigned int    bits,
mad_fixed_t    sample,
struct audio_dither   dither
[static]
 

Generic linear sample quantize and dither routine.

Parameters:
unsigned  int bits -
mad_fixed_t  sample - audio sample to dither
struct  audio_dither *dither - pointer to dither struct.
Returns:
signed long -

Definition at line 150 of file mp3.c.

References DITHER_MAGIC, audio_dither::error, audio_dither::magic, output(), prng(), and audio_dither::random.

Referenced by output().

enum mad_flow error audio_data_t    _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.

Parameters:
void  *_data - pointer to the data struct.
struct  mad_stream *stream - pointer to the stream where the error occured.
struct  mad_frame *frame - pointer to the frame where the error occured.
Returns:
enum mad_flow - returns an instruction for MAD to stop, ignore or continue.

Definition at line 343 of file mp3.c.

References audio_data_t, struct_audio_data_t::buffer, struct_audio_data_t::buffer::buffer_start, error(), REP_DEBUG, report(), and STRLEN.

Referenced by audio_initiate(), error(), and mp3_decode().

void free_dither struct audio_dither   dither [static]
 

Frees a dither struct

Parameters:
struct  audio_dither *dither - dither struct to free.

Definition at line 460 of file mp3.c.

References DITHER_MAGIC, and audio_dither::magic.

Referenced by mp3_decode().

enum mad_flow header audio_data_t    data,
struct mad_header const *    header
[static]
 

Analyses the frame header and do things like seeking.

Parameters:
audio_data_t  data - pointer to the data struct.
struct  mad_header const *header - pointer to the MAD header struct.
Returns:
enum mad_flow - returns an instruction for MAD to stop, ignore or continue.

Definition at line 373 of file mp3.c.

References audio_data_t, callback(), header(), struct_audio_data_t::mutex, struct_audio_data_t::progress, REP_DEBUG, report(), struct_audio_data_t::start, and struct_audio_data_t::stop.

Referenced by header(), mp3_decode(), and output().

struct audio_dither * init_dither void    [static]
 

Allocates memory for dither struct.

Returns:
struct audio_dither * - returns a pointer to a new audio_dither struct.

Definition at line 429 of file mp3.c.

References DITHER_MAGIC, audio_dither::magic, REP_CRITICAL, report(), and reset_dither().

Referenced by mp3_decode().

enum mad_flow input audio_data_t    data,
struct mad_stream *    stream
[static]
 

The input callback. The purpose of this callback is to (re)fill the stream buffer which is to be decoded. Right now, an entire file has been memory-mapped. We just call mad_stream_buffer() with the address and length of the memory-map. This callback is called by MAD when it needs more data.

Parameters:
audio_data_t  data - pointer to the data struct.
struct  mad_stream *stream - the MAD stream struct.
Returns:
enum mad_flow - returns an instruction for MAD to stop, ignore or continue.

Definition at line 113 of file mp3.c.

References audio_data_t, struct_audio_data_t::buffer, struct_audio_data_t::buffer::buffer_length, struct_audio_data_t::buffer::buffer_start, and struct_audio_data_t::mutex.

Referenced by mp3_decode().

void mp3_close struct_audio_data_t   data
 

Closes the decoder. This function must be called when you are done using the mp3 decoder.

Parameters:
struct_audio_data_t  *data - pointer to the data struct.

Definition at line 583 of file mp3.c.

References struct_audio_data_t::device, and libao_terminate().

Referenced by audio_decoder(), and audio_terminate().

int mp3_decode struct_audio_data_t   data [static]
 

This is the function called to perform all the decoding. It instantiates a decoder struct and configures it with the input, output, header, 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).

Parameters:
struct_audio_data_t  *data - pointer to the data struct.
Returns:
int - returns the return-value from mad_decoder_run.

Definition at line 481 of file mp3.c.

References struct_audio_data_t::buffer, struct_audio_data_t::buffer::buffer_length, struct_audio_data_t::buffer::buffer_start, error(), struct_audio_data_t::fdm, free_dither(), header(), init_dither(), input(), struct_audio_data_t::mp3_dither, struct_audio_data_t::mutex, output(), and struct_audio_data_t::stat.

Referenced by mp3_play().

void mp3_init struct_audio_data_t   data
 

Initializes the decoder. This function must be called before audio_play or any atemt to use the mp3 decoder.

Parameters:
struct_audio_data_t  *data - pointer to the data struct TODO: Return something useful on error instead of reporting a critical error (and possibly die).

Definition at line 530 of file mp3.c.

References struct_audio_data_t::cb_error, struct_audio_data_t::daisy, DAISY_ERROR_AUDIO_DATA_IS_NULL, struct_audio_data_t::device, struct_audio_data_t::mutex, struct_audio_data_t::progress, REP_CRITICAL, REP_DEBUG, and report().

Referenced by audio_decoder().

bool mp3_play struct_audio_data_t   data
 

Plays a file segment. This function will play a file from the start to the stop that is deinfed in the data struct.

Parameters:
struct_audio_data_t  *data - pointer to the data struct.
Returns:
bool - returns false.

Definition at line 558 of file mp3.c.

References struct_audio_data_t::fdm, struct_audio_data_t::file_name, mp3_decode(), struct_audio_data_t::mutex, struct_audio_data_t::progress, REP_DEBUG, report(), and STRLEN.

Referenced by audio_decoder().

enum mad_flow output audio_data_t    _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 prepare the decoded PCM audio and tell libao to audio_play it. (Some of the folowing code are borowed from mpg321).

Parameters:
void  *audio_data - pointer to the data struct.
struct  mad_header const *header - pointer to the MAD header struct.
struct  mad_pcm *pcm - pointer to the MAD PCM struct.
Returns:
enum mad_flow - returns an instruction for MAD to stop, ignore or continue.

Definition at line 230 of file mp3.c.

References audio_data_t, audio_linear_dither(), struct_audio_data_t::device, header(), libao_initiate(), libao_play(), libao_terminate(), struct_audio_data_t::mp3_dither, struct_audio_data_t::mutex, REP_DEBUG, report(), and reset_dither().

Referenced by audio_linear_dither(), and mp3_decode().

__inline__ unsigned long prng unsigned long    state [static]
 

32-bit pseudo-random number generator.

Parameters:
unsigned  long state - used as a basis to generate pseudo-random number.
Returns:
unsigned long - pseudo-random number. NOTE: This is only used by the dither routine.

Definition at line 213 of file mp3.c.

Referenced by audio_linear_dither().

void reset_dither struct audio_dither   dither [static]
 

Resets the values in a dither struct

Parameters:
struct  audio_dither *dither - dither struct to reset.

Definition at line 446 of file mp3.c.

References DITHER_MAGIC, audio_dither::error, audio_dither::magic, and audio_dither::random.

Referenced by init_dither(), and output().


Generated on Tue Sep 5 12:14:08 2006 for libdaisy by doxygen1.2.15