+/*
+ * PicoDrive
+ * (C) notaz, 2007,2008
+ *
+ * This work is licensed under the terms of MAME license.
+ * See COPYING file in the top-level directory.
+ */
+
#include <stdio.h>
#include <string.h>
#include <pspkernel.h>
#include <pspsdk.h>
#include <pspaudiocodec.h>
+#include <kubridge.h>
-#include "../../Pico/PicoInt.h"
-#include "../../Pico/sound/mix.h"
+#include "../../pico/pico_int.h"
+#include "../../pico/sound/mix.h"
#include "../common/lprintf.h"
int mp3_last_error = 0;
static SceUID load_start_module(const char *prxname)
{
- SceUID mod = pspSdkLoadStartModule(prxname, PSP_MEMORY_PARTITION_KERNEL);
- if (mod < 0)
- lprintf("failed to load %s: %08x\n", prxname, mod);
+ SceUID mod, mod1;
+ int status, ret;
+
+ mod = pspSdkLoadStartModule(prxname, PSP_MEMORY_PARTITION_KERNEL);
+ if (mod < 0) {
+ lprintf("failed to load %s (%08x), trying kuKernelLoadModule\n", prxname, mod);
+ mod1 = kuKernelLoadModule(prxname, 0, NULL);
+ if (mod1 < 0) lprintf("kuKernelLoadModule failed with %08x\n", mod1);
+ else {
+ ret = sceKernelStartModule(mod1, 0, NULL, &status, 0);
+ if (ret < 0) lprintf("sceKernelStartModule failed with %08x\n", ret);
+ else mod = mod1;
+ }
+ }
return mod;
}
mod = load_start_module("flash0:/kd/audiocodec.prx");
else mod = load_start_module("flash0:/kd/avcodec.prx");
if (mod < 0) {
- ret = mod = load_start_module("flash0:/kd/audiocodec_260.prx"); // last chance..
+ ret = mod;
+ mod = load_start_module("flash0:/kd/audiocodec_260.prx"); // last chance..
if (mod < 0) goto fail;
}
goto fail2;
}
+ /* use slightly higher prio then main */
thread_exit = 0;
- thid = sceKernelCreateThread("mp3decode_thread", decode_thread, 30, 0x2000, 0, 0); /* use slightly higher prio then main */
+ thid = sceKernelCreateThread("mp3decode_thread", decode_thread, 30, 0x2000, 0, NULL);
if (thid < 0) {
lprintf("failed to create decode thread: %08x\n", thid);
ret = thid;
// might be called before initialization
-int mp3_get_bitrate(FILE *f, int size)
+int mp3_get_bitrate(void *f, int size)
{
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;
+ char *fname = f;
/* make sure thread is not busy.. */
if (thread_busy_sem >= 0)
static int mp3_job_started = 0, mp3_samples_ready = 0, mp3_buffer_offs = 0, mp3_play_bufsel = 0;
-void mp3_start_play(FILE *f, int pos)
+void mp3_start_play(void *f, int pos)
{
- char *fname = (char *)f;
+ char *fname = f;
if (!initialized) return;
mp3_fname = fname;
}
+ // clear decoder state
+ sceAudiocodecInit(mp3_codec_struct, 0x1002);
+
// seek..
mp3_src_pos = (int) (((float)pos / 1023.0f) * (float)mp3_src_size);
sceIoLseek32(mp3_handle, mp3_src_pos, PSP_SEEK_SET);
unsigned int offs1024 = 0;
int cdda_on;
- cdda_on = (PicoMCD & 1) && (PicoOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) &&
+ cdda_on = (PicoAHW & PAHW_MCD) && (PicoOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) &&
(Pico_mcd->scd.Status_CDC & 1) && mp3_handle >= 0;
if (cdda_on) {
}
+void mp3_reopen_file(void)
+{
+ if (mp3_fname == NULL) return;
+ lprintf("mp3_reopen_file(%s)\n", mp3_fname);
+
+ // try closing, just in case
+ if (mp3_handle >= 0) sceIoClose(mp3_handle);
+
+ mp3_handle = sceIoOpen(mp3_fname, PSP_O_RDONLY, 0777);
+ if (mp3_handle >= 0)
+ sceIoLseek32(mp3_handle, mp3_src_pos, PSP_SEEK_SET);
+ lprintf("mp3_reopen_file %s\n", mp3_handle >= 0 ? "ok" : "failed");
+}
+