optimizations, fixes, hacks, psp, ...
[picodrive.git] / platform / psp / mp3.c
index f0cfe8f..5a87877 100644 (file)
@@ -104,7 +104,7 @@ static int read_next_frame(int which_buffer)
                }
 
                if (frame_offset) {
-                       lprintf("unaligned, foffs=%i, offs=%i\n", mp3_src_pos - bytes_read, frame_offset);
+                       //lprintf("unaligned, foffs=%i, offs=%i\n", mp3_src_pos - bytes_read, frame_offset);
                        memmove(mp3_src_buffer[which_buffer], mp3_src_buffer[which_buffer] + frame_offset, frame_size);
                }
 
@@ -181,8 +181,6 @@ int mp3_init(void)
                goto fail2;
        }
 
-       lprintf("thread_busy_sem: %08x, thread_job_sem: %08x\n", thread_busy_sem, thread_job_sem);
-
        thread_exit = 0;
        thid = sceKernelCreateThread("mp3decode_thread", decode_thread, 30, 0x2000, 0, 0); /* use slightly higher prio then main */
        if (thid < 0) {
@@ -273,7 +271,7 @@ static int decode_thread(SceSize args, void *argp)
 
 int mp3_get_bitrate(FILE *f, int size)
 {
-       int ret = -1, sample_rate, bitrate;
+       int ret, retval = -1, sample_rate, bitrate;
        // filenames are stored instead handles in PSP, due to stupid max open file limit
        char *fname = (char *)f;
 
@@ -307,14 +305,14 @@ int mp3_get_bitrate(FILE *f, int size)
        }
 
        /* looking good.. */
-       ret = bitrate;
+       retval = bitrate;
 end:
        if (mp3_handle >= 0) sceIoClose(mp3_handle);
        mp3_handle = -1;
        mp3_fname = NULL;
        psp_sem_unlock(thread_busy_sem);
-       if (ret < 0) mp3_last_error = -1; // remember we had a problem..
-       return ret;
+       if (retval < 0) mp3_last_error = -1; // remember we had a problem..
+       return retval;
 }
 
 
@@ -327,7 +325,7 @@ void mp3_start_play(FILE *f, int pos)
        lprintf("mp3_start_play(%s) @ %i\n", fname, pos);
        psp_sem_lock(thread_busy_sem);
 
-       if (mp3_fname != fname)
+       if (mp3_fname != fname || mp3_handle < 0)
        {
                if (mp3_handle >= 0) sceIoClose(mp3_handle);
                mp3_handle = sceIoOpen(fname, PSP_O_RDONLY, 0777);