occasional mp3 click noises fixed

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@530 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2008-07-06 20:28:11 +00:00
parent 374498bcab
commit 091facb8fe
4 changed files with 92 additions and 11 deletions

View file

@ -508,7 +508,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023
shared_ctl->mp3_len = ftell(f);
loaded_mp3 = f;
if (PicoOpt&0x200) {
if (PicoOpt & POPT_EXT_FM) {
// as we are going to change 940's cacheable area, we must invalidate it's cache..
if (CHECK_BUSY(JOB940_MP3DECODE)) wait_busy_940(JOB940_MP3DECODE);
add_job_940(JOB940_INVALIDATE_DCACHE);
@ -522,7 +522,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023
byte_offs *= pos;
byte_offs >>= 6;
}
// printf("mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len);
printf(" mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len);
shared_ctl->mp3_offs = byte_offs;
@ -531,7 +531,13 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023
mp3_job_started = 0;
shared_ctl->mp3_buffsel = 1; // will change to 0 on first decode
if (!(PicoOpt&0x200)) mp3_start_local();
if (PicoOpt & POPT_EXT_FM)
{
add_job_940(JOB940_MP3RESET);
if (CHECK_BUSY(JOB940_MP3RESET)) wait_busy_940(JOB940_MP3RESET);
}
else
mp3_start_local();
}

View file

@ -25,17 +25,44 @@ void _memcpy(void *dst, const void *src, int count);
// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer */
static int find_sync_word(unsigned char *buf, int nBytes)
{
unsigned char *p, *pe;
/* find byte-aligned syncword - need 12 (MPEG 1,2) or 11 (MPEG 2.5) matching bits */
for (p = buf, pe = buf + nBytes - 4; p < pe; p++)
{
int pn;
if (p[0] != 0xff) continue;
pn = p[1];
if ((pn & 0xf8) != 0xf8 || // currently must be MPEG1
(pn & 6) == 0) { // invalid layer
p++; continue;
}
pn = p[2];
if ((pn & 0xf0) < 0x20 || (pn & 0xf0) == 0xf0 || // bitrates
(pn & 0x0c) != 0) { // not 44kHz
continue;
}
return p - buf;
}
return -1;
}
static void mp3_decode(void)
{
int mp3_offs = shared_ctl->mp3_offs;
unsigned char *readPtr = mp3_data + mp3_offs;
int bytesLeft = shared_ctl->mp3_len - mp3_offs;
int offset; // frame offset from readPtr
int err;
int retries = 0, err;
if (bytesLeft <= 0) return; // EOF, nothing to do
offset = MP3FindSyncWord(readPtr, bytesLeft);
retry:
offset = find_sync_word(readPtr, bytesLeft);
if (offset < 0) {
set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);
return; // EOF
@ -53,6 +80,8 @@ static void mp3_decode(void)
// ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*
// just try to skip the offending frame..
readPtr++;
bytesLeft--;
if (retries++ < 2) goto retry;
}
shared_ctl->mp3_errors++;
shared_ctl->mp3_lasterr = err;
@ -189,6 +218,11 @@ void Main940(void)
case JOB940_MP3DECODE:
mp3_decode();
break;
case JOB940_MP3RESET:
if (shared_data->mp3dec) MP3FreeDecoder(shared_data->mp3dec);
shared_data->mp3dec = MP3InitDecoder();
break;
}
shared_ctl->loopc++;

View file

@ -12,6 +12,7 @@ enum _940_job_t {
JOB940_PICOSTATESAVE2,
JOB940_PICOSTATELOAD2_PREP,
JOB940_PICOSTATELOAD2,
JOB940_MP3RESET,
};
//#define MAX_940JOBS 2