#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_dither * | init_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) |
|
Generic linear sample quantize and dither routine.
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(). |
|
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 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(). |
|
Frees a dither struct
Definition at line 460 of file mp3.c. References DITHER_MAGIC, and audio_dither::magic. Referenced by mp3_decode(). |
|
Analyses the frame header and do things like seeking.
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(). |
|
Allocates memory for 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(). |
|
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.
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(). |
|
Closes the decoder. This function must be called when you are done using the mp3 decoder.
Definition at line 583 of file mp3.c. References struct_audio_data_t::device, and libao_terminate(). Referenced by audio_decoder(), and audio_terminate(). |
|
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).
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(). |
|
Initializes the decoder. This function must be called before audio_play or any atemt to use the mp3 decoder.
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(). |
|
Plays a file segment. This function will play a file from the start to the stop that is deinfed in the data struct.
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(). |
|
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).
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(). |
|
32-bit pseudo-random number generator.
Definition at line 213 of file mp3.c. Referenced by audio_linear_dither(). |
|
Resets the values in a dither struct
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(). |