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
static enum mad_flow input ( void *  data,
struct mad_stream *  stream 
)
static
static enum mad_flow output ( void *  data,
const struct mad_header *  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.

References audio_mixer_dacs_flush, audio_mixer_dacs_output, audio_mixer_dacs_setup, audio_mixer_get_buffer, audio_mixer_mute_audio, com_task(), data, mp3_play_data::duration_played, fat_check_mount_select_open(), FS_NAV_ID_AUDIO, g_smooth_com_cnt, i, nav_select(), NULL, PLAYER_FLAG_NORMAL, PLAYER_FLAG_PAUSE, PLAYER_FLAG_PLAY, PLAYER_FLAG_STOP, state, STATE_OUTPUT, Ai_player_flag_t::status, and Ai_player_flag_t::status_fast.

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, mp3_play_data::mp3_end_file_pos, MP3_MAX_DATA_REQUESTED, mp3_play_data::mp3_start_file_pos, nav_file_lgt(), nav_select(), NBSAVFILEPOS, NULL, 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
uint32_t g_player_duration
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().