unify helix mp3 code, some sound adjustments
[picodrive.git] / platform / gp2x / code940 / 940.c
index 90087a3..a4d3a46 100644 (file)
@@ -61,32 +61,43 @@ static void mp3_decode(void)
 \r
        if (bytesLeft <= 0) return; // EOF, nothing to do\r
 \r
-retry:\r
-       offset = find_sync_word(readPtr, bytesLeft);\r
-       if (offset < 0) {\r
-               set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);\r
-               return; // EOF\r
-       }\r
-       readPtr += offset;\r
-       bytesLeft -= offset;\r
-\r
-       err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft,\r
-                       shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0);\r
-       if (err) {\r
-               if (err == ERR_MP3_INDATA_UNDERFLOW) {\r
-                       set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);\r
-                       return;\r
-               } else if (err <= -6 && err >= -12) {\r
-                       // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*\r
-                       // just try to skip the offending frame..\r
-                       readPtr++;\r
-                       bytesLeft--;\r
-                       if (retries++ < 2) goto retry;\r
+       for (retries = 0; retries < 2; retries++)\r
+       {\r
+               offset = find_sync_word(readPtr, bytesLeft);\r
+               if (offset < 0)\r
+                       goto set_eof;\r
+\r
+               readPtr += offset;\r
+               bytesLeft -= offset;\r
+\r
+               err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft,\r
+                               shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0);\r
+               if (err) {\r
+                       if (err == ERR_MP3_MAINDATA_UNDERFLOW)\r
+                               // just need another frame\r
+                               continue;\r
+\r
+                       if (err == ERR_MP3_INDATA_UNDERFLOW)\r
+                               goto set_eof;\r
+\r
+                       if (err <= -6 && err >= -12) {\r
+                               // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*\r
+                               // just try to skip the offending frame..\r
+                               readPtr++;\r
+                               bytesLeft--;\r
+                               continue;\r
+                       }\r
+                       shared_ctl->mp3_errors++;\r
+                       shared_ctl->mp3_lasterr = err;\r
                }\r
-               shared_ctl->mp3_errors++;\r
-               shared_ctl->mp3_lasterr = err;\r
+               break;\r
        }\r
+\r
        set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, readPtr - mp3_data);\r
+       return;\r
+\r
+set_eof:\r
+       set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);\r
 }\r
 \r
 static void ym_flush_writes(void)\r