Microchip® Advanced Software Framework

mp3_libmad_player.c File Reference
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "compiler.h"
#include "file.h"
#include "conf_audio_player.h"
#include "audio_mixer.h"
#include "mad.h"
#include "reader_id3.h"
#include "com_task.h"
#include "navigation.h"
#include "audio_interface.h"

Data Structures

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

Macros

#define FILEPOSDELAY   4000
 
#define MP3_MAX_DATA_REQUESTED   (2881 + MAD_BUFFER_GUARD)
 Maximal number of input bytes requested by the decoder at once. More...
 
#define NBSAVFILEPOS   200
 
#define OFFSETFILEPOS   50
 
#define PCM_BUF_BYTE_SIZE   (PCM_BUF_SAMP_SIZE * 2 * sizeof(int16_t))
 Size of each PCM buffer in bytes. More...
 
#define PCM_BUF_SAMP_SIZE   1152
 Size of each PCM buffer in samples per channel. More...
 

Functions

static enum mad_flow error (void *data, struct mad_stream *stream, struct mad_frame *frame)
 This is the error callback function. More...
 
static enum mad_flow header (void *data, struct mad_header const *header)
 
static enum mad_flow input (void *data, struct mad_stream *stream)
 This is the input callback. More...
 
static enum mad_flow output (void *data, const struct mad_header *header, struct mad_pcm *pcm)
 This is the output callback function. More...
 
bool play_mp3 (const char *filename, bool verbose)
 This is the function called by ushell_task() to perform all the MP3 decoding. More...
 

Variables

uint16_t cptms
 
uint16_t FilePosPtr
 
uint32_t g_player_currentTime_ms
 
uint32_t g_player_duration
 
Ai_player_flag_t g_player_flag
 
uint32_t g_player_target_file_pos
 
uint8_t g_smooth_com_cnt
 
uint32_t time_goal
 This is the header callback function. More...
 
uint32_t TimeStampOffset
 
uint32_t * tSavFilePos
 

#define FILEPOSDELAY   4000

Referenced by header().

#define MP3_MAX_DATA_REQUESTED   (2881 + MAD_BUFFER_GUARD)

Maximal number of input bytes requested by the decoder at once.

Referenced by input(), and play_mp3().

#define NBSAVFILEPOS   200

Referenced by header(), and play_mp3().

#define OFFSETFILEPOS   50

Referenced by header().

#define PCM_BUF_BYTE_SIZE   (PCM_BUF_SAMP_SIZE * 2 * sizeof(int16_t))

Size of each PCM buffer in bytes.

Referenced by play_mp3().

#define PCM_BUF_SAMP_SIZE   1152

Size of each PCM buffer in samples per channel.

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.

References data, mad_stream::error, mp3_play_data::frame_buf_guard, MAD_ERROR_LOSTSYNC, MAD_FLOW_CONTINUE, mad_stream::this_frame, and mp3_play_data::verbose.

Referenced by et024006_DrawFilledCircle(), and play_mp3().

bool play_mp3 ( const char *  filename,
bool  verbose 
)

This is the function called by ushell_task() to perform all the MP3 decoding.

Returns
false in case of error, otherwise return true.

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).

References St_id3size::appended_tag, audio_mixer_close, audio_mixer_create_buffers, audio_mixer_dacs_flush, cptms, error(), file_close(), file_open(), file_seek(), filename, FilePosPtr, FOPEN_MODE_R, mp3_play_data::frame_buf, mp3_play_data::frame_buf_end, mp3_play_data::frame_buf_guard, FS_NAV_ID_AUDIO, FS_SEEK_SET, header(), input, mad_decoder_finish(), mad_decoder_init(), MAD_DECODER_MODE_SYNC, mad_decoder_run(), mad_timer_zero, mp3_play_data::mp3_end_file_pos, MP3_MAX_DATA_REQUESTED, mp3_play_data::mp3_start_file_pos, nav_file_lgt(), nav_select(), NBSAVFILEPOS, output, PCM_BUF_BYTE_SIZE, St_id3size::prepended_tag, reader_id3_size(), time_goal, TimeStampOffset, tSavFilePos, and mp3_play_data::unrecoverable_error.

Referenced by codec_mp3_task().

uint16_t cptms

Referenced by header(), and play_mp3().

uint16_t FilePosPtr

Referenced by header(), and play_mp3().

uint32_t g_player_currentTime_ms

Referenced by header().

uint32_t g_player_duration

Referenced by header().

Ai_player_flag_t g_player_flag
uint32_t g_player_target_file_pos

Referenced by header().

uint8_t g_smooth_com_cnt

Referenced by output().

uint32_t time_goal

This is the header callback function.

It is called whenever a asf header is found

Referenced by header(), and play_mp3().

uint32_t TimeStampOffset

Referenced by header(), and play_mp3().

uint32_t* tSavFilePos

Referenced by header(), and play_mp3().