X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgp2x%2Fcode940%2F940.c;fp=platform%2Fgp2x%2Fcode940%2F940.c;h=a4d3a464d8a0549e9d6ded3473f0176f764bf94b;hb=7c34867ab6109c47ad099e903a57af6d2699074f;hp=90087a3e2fae583e21f485f8ffc5b450abec3713;hpb=3328d53bb7d323f9009181e9308fad37a5b5d427;p=picodrive.git diff --git a/platform/gp2x/code940/940.c b/platform/gp2x/code940/940.c index 90087a3..a4d3a46 100644 --- a/platform/gp2x/code940/940.c +++ b/platform/gp2x/code940/940.c @@ -61,32 +61,43 @@ static void mp3_decode(void) if (bytesLeft <= 0) return; // EOF, nothing to do -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 - } - readPtr += offset; - bytesLeft -= offset; - - err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft, - shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0); - if (err) { - if (err == ERR_MP3_INDATA_UNDERFLOW) { - set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len); - return; - } else if (err <= -6 && err >= -12) { - // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_* - // just try to skip the offending frame.. - readPtr++; - bytesLeft--; - if (retries++ < 2) goto retry; + for (retries = 0; retries < 2; retries++) + { + offset = find_sync_word(readPtr, bytesLeft); + if (offset < 0) + goto set_eof; + + readPtr += offset; + bytesLeft -= offset; + + err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft, + shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0); + if (err) { + if (err == ERR_MP3_MAINDATA_UNDERFLOW) + // just need another frame + continue; + + if (err == ERR_MP3_INDATA_UNDERFLOW) + goto set_eof; + + if (err <= -6 && err >= -12) { + // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_* + // just try to skip the offending frame.. + readPtr++; + bytesLeft--; + continue; + } + shared_ctl->mp3_errors++; + shared_ctl->mp3_lasterr = err; } - shared_ctl->mp3_errors++; - shared_ctl->mp3_lasterr = err; + break; } + set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, readPtr - mp3_data); + return; + +set_eof: + set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len); } static void ym_flush_writes(void)