fix DrawSpritesHiAS
[picodrive.git] / platform / common / mp3.c
index 25c5c92..c84962c 100644 (file)
@@ -104,7 +104,7 @@ out:
        return retval;
 }
 
-void mp3_start_play(void *f_, int pos)
+void mp3_start_play(void *f_, int pos1024)
 {
        unsigned char buf[2048];
        FILE *f = f_;
@@ -115,16 +115,9 @@ void mp3_start_play(void *f_, int pos)
        cdda_out_pos = 0;
        decoder_active = 0;
 
-       if (!(PicoOpt & POPT_EN_MCD_CDDA) || f == NULL) // cdda disabled or no file?
+       if (!(PicoIn.opt & POPT_EN_MCD_CDDA) || f == NULL) // cdda disabled or no file?
                return;
 
-       ret = mp3dec_start();
-       if (ret != 0)
-               return;
-
-       decoder_active = 1;
-
-       mp3_current_file = f;
        fseek(f, 0, SEEK_END);
        mp3_file_len = ftell(f);
 
@@ -145,12 +138,20 @@ void mp3_start_play(void *f_, int pos)
        }
 
        // seek..
-       if (pos) {
+       if (pos1024 != 0) {
                unsigned long long pos64 = mp3_file_len - mp3_file_pos;
-               pos64 *= pos;
+               pos64 *= pos1024;
                mp3_file_pos += pos64 >> 10;
        }
 
+       ret = mp3dec_start(f, mp3_file_pos);
+       if (ret != 0) {
+               return;
+       }
+
+       mp3_current_file = f;
+       decoder_active = 1;
+
        mp3dec_decode(mp3_current_file, &mp3_file_pos, mp3_file_len);
 }
 
@@ -166,11 +167,11 @@ void mp3_update(int *buffer, int length, int stereo)
                return;
 
        length_mp3 = length;
-       if (PsndRate <= 11025 + 100) {
+       if (PicoIn.sndRate <= 11025 + 100) {
                mix_samples = mix_16h_to_32_s2;
                length_mp3 <<= 2; shr = 2;
        }
-       else if (PsndRate <= 22050 + 100) {
+       else if (PicoIn.sndRate <= 22050 + 100) {
                mix_samples = mix_16h_to_32_s1;
                length_mp3 <<= 1; shr = 1;
        }
@@ -183,8 +184,9 @@ void mp3_update(int *buffer, int length, int stereo)
        } else {
                int ret, left = 1152 - cdda_out_pos;
 
-               mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
-                       (left >> shr) * 2);
+               if (left > 0)
+                       mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
+                               (left >> shr) * 2);
 
                ret = mp3dec_decode(mp3_current_file, &mp3_file_pos,
                        mp3_file_len);