Hi,
I am trying to modify the well known MP3 Player Example from Elektor,(written from TI), to play WAVE files. WAVE files are uncompressed and have simple formatting. However, I have spent almost four weeks without success due to the implementation of DSP/BIOS in the example. Below I have attached the modified tskDecode(). Would you please give me some pointers or help to make EZDSP play WAVE files?
Thanks,
#include <std.h>
#include <stdio.h>
#include <stdlib.h>
#include <tistdtypes.h>
#include <sio.h>
#include "common.h"
#include "ff.h"
#include <decode.h>
#include <mp3_tni.h>
#define INPBUF_SZ (1024) // minimum cluster size is INP_BUFSZ [bytes]
int DECODE_decode(DECODE_Handle handle, Int * in, Int *out, int inwords,
IDECODE_OutArgs* outargs);
void DECODE_getStatus(DECODE_Handle handle, DECODE_Status *status);
void DECODE_reset(DECODE_Handle handle);
extern void handleKeys(void);
extern int DisplayString(char *str);
extern PCM_SAMPLE_TYPE audBufs[NUM_OUT_BUFS][WORDS_PER_OUT_BUF];
Int inBuffer[1152/*INPBUF_SZ*/];
Int* inBuffStart;
FIL mp3File;
FILINFO fno;
extern DIR dirObj;
extern SIO_Handle hStreamOut;
Ptr outBuffer;
int numFrames = 0;
void tskDecode()
{
IDECODE_Handle handle;
IDECODE_Params decParams = MP3_PARAMS;
IDECODE_OutArgs outArgs;
PCM_SAMPLE_TYPE* pAudBufs;
int numValidWords;
int idx;
FRESULT res;
decParams.size = sizeof(IDECODE_Params);
outArgs.size = sizeof(IDECODE_OutArgs);
decParams.pcmFormat = IAUDIO_BLOCK;
while(1) {
unsigned int sample_idx=0;
unsigned int buffer_idx=0;
Uint16 *pbuffer;
UINT br;
long framesDecoded;
res = f_readdir(&dirObj, &fno);
if (res != FR_OK) {
break;
}
res = f_open(&mp3File, fno.fname, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
break;
}
f_lseek(&mp3File, 44/2);
// clear buffers
pAudBufs = &audBufs[0][0];
for (idx=0; idx<NUM_OUT_BUFS*WORDS_PER_OUT_BUF; idx++) {
*pAudBufs++ = 0;
}
// issue buffers
for (idx=0; idx<NUM_OUT_BUFS; idx++) { // issue all buffer at once
SIO_issue(hStreamOut, &audBufs[idx][0], WORDS_PER_OUT_BUF, NULL); // buffers have to be issued before they can be reclaimed
}
framesDecoded = 1;
while(1) {
SIO_reclaim(hStreamOut, &outBuffer, NULL); // get an empty audio buffer, blocking until buffer a/v
pbuffer = outBuffer;
BLUE_ON
//DECODE_decode(handle, (Int*)&inBuffer[addr_is_odd], (Int*)outBuffer, numValidWords, &outArgs);
res = f_read(&mp3File, (BYTE*)(&inBuffer[0]), 1152, &br);
for(sample_idx=0; sample_idx<1152; sample_idx++){
*(pbuffer+sample_idx) = inBuffer[sample_idx*2];
*(pbuffer+sample_idx+576) = inBuffer[sample_idx*2+1];
//audBufs[buffer_idx][sample_idx] = inBuffer[sample_idx*2];
//audBufs[buffer_idx][sample_idx+576] = inBuffer[sample_idx*2+1];
}
buffer_idx++;
if(buffer_idx == 3) buffer_idx = 0;
BLUE_OFF
if (framesDecoded == 1) {
outArgs.sampleRate = 48000;
outArgs.numSamples = 576;
outArgs.numChannels = 2;
outArgs.outputPCMWidth = 16;
outArgs.pcmFormat = 0;
SIO_ctrl(hStreamOut, AIC3204_CMD_SET_SRATE, &outArgs.sampleRate); // adjust sampling rate
DisplayString(fno.fname);
framesDecoded++; // update Display
}
SIO_issue(hStreamOut, outBuffer, outArgs.numSamples*outArgs.numChannels, NULL);
handleKeys(); // check the keys
}
for (idx=0; idx<NUM_OUT_BUFS; idx++) {
SIO_reclaim(hStreamOut, &outBuffer, NULL); // get all buffers back
}
}
DECODE_delete(handle);
YELLOW_ON
}
void tskDecode()
{
IDECODE_Handle handle;
IDECODE_Params decParams = MP3_PARAMS;
IDECODE_OutArgs outArgs;
PCM_SAMPLE_TYPE* pAudBufs;
int numValidWords;
int idx;
FRESULT res;
decParams.size = sizeof(IDECODE_Params);
outArgs.size = sizeof(IDECODE_OutArgs);
decParams.pcmFormat = IAUDIO_BLOCK;
while(1) {
unsigned int sample_idx=0;
unsigned int buffer_idx=0;
Uint16 *pbuffer;
UINT br;
long framesDecoded;
res = f_readdir(&dirObj, &fno);
if (res != FR_OK) {
break;
}
res = f_open(&mp3File, fno.fname, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
break;
}
f_lseek(&mp3File, 44/2);
// clear buffers
pAudBufs = &audBufs[0][0];
for (idx=0; idx<NUM_OUT_BUFS*WORDS_PER_OUT_BUF; idx++) {
*pAudBufs++ = 0;
}
// issue buffers
for (idx=0; idx<NUM_OUT_BUFS; idx++) { // issue all buffer at once
SIO_issue(hStreamOut, &audBufs[idx][0], WORDS_PER_OUT_BUF, NULL); // buffers have to be issued before they can be reclaimed
}
framesDecoded = 1;
while(1) {
SIO_reclaim(hStreamOut, &outBuffer, NULL); // get an empty audio buffer, blocking until buffer a/v
pbuffer = outBuffer;
BLUE_ON
//DECODE_decode(handle, (Int*)&inBuffer[addr_is_odd], (Int*)outBuffer, numValidWords, &outArgs);
res = f_read(&mp3File, (BYTE*)(&inBuffer[0]), 1152, &br);
for(sample_idx=0; sample_idx<1152; sample_idx++){
*(pbuffer+sample_idx) = inBuffer[sample_idx*2];
*(pbuffer+sample_idx+576) = inBuffer[sample_idx*2+1];
//audBufs[buffer_idx][sample_idx] = inBuffer[sample_idx*2];
//audBufs[buffer_idx][sample_idx+576] = inBuffer[sample_idx*2+1];
}
buffer_idx++;
if(buffer_idx == 3) buffer_idx = 0;
BLUE_OFF
if (framesDecoded == 1) {
outArgs.sampleRate = 48000;
outArgs.numSamples = 576;
outArgs.numChannels = 2;
outArgs.outputPCMWidth = 16;
outArgs.pcmFormat = 0;
SIO_ctrl(hStreamOut, AIC3204_CMD_SET_SRATE, &outArgs.sampleRate); // adjust sampling rate
DisplayString(fno.fname);
framesDecoded++; // update Display
}
SIO_issue(hStreamOut, outBuffer, outArgs.numSamples*outArgs.numChannels, NULL);
handleKeys(); // check the keys
}
for (idx=0; idx<NUM_OUT_BUFS; idx++) {
SIO_reclaim(hStreamOut, &outBuffer, NULL); // get all buffers back
}
}
DECODE_delete(handle);
YELLOW_ON
}