From 650adef8da93eb049f317821c619ed63eff5fe39 Mon Sep 17 00:00:00 2001 From: aliaspider Date: Mon, 17 Feb 2014 14:26:03 +0100 Subject: [PATCH 1/2] (PSP) added audio support --- Makefile.psp1 | 6 +- config.def.h | 3 + driver.c | 3 + driver.h | 1 + frontend/platform/platform_psp.c | 8 +- griffin/griffin.c | 2 + psp1/psp1_audio.c | 146 +++++++++++++++++++++++++++++++ settings.c | 2 + 8 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 psp1/psp1_audio.c diff --git a/Makefile.psp1 b/Makefile.psp1 index cdbdac516d..d0dfe8c1b9 100644 --- a/Makefile.psp1 +++ b/Makefile.psp1 @@ -15,7 +15,7 @@ INCDIR = CFLAGS = $(OPTIMIZE_LV) -G0 -std=gnu99 -ffast-math ASFLAGS = $(CFLAGS) -RARCH_DEFINES = -DPSP -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_ZLIB -DWANT_MINIZ -DHAVE_GRIFFIN=1 -DHAVE_NULLAUDIO -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_RGUI -DWANT_RPNG -DSINC_LOWEST_QUALITY +RARCH_DEFINES = -DPSP -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_ZLIB -DWANT_MINIZ -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_RGUI -DWANT_RPNG -DSINC_LOWEST_QUALITY ifeq ($(HAVE_FILE_LOGGER), 1) CFLAGS += -DHAVE_FILE_LOGGER @@ -25,7 +25,7 @@ CFLAGS += $(RARCH_DEFINES) LIBDIR = LDFLAGS = -LIBS = -lretro_psp1 -lstdc++ -lpspgu -lpspgum -lm +LIBS = -lretro_psp1 -lstdc++ -lpspgu -lpspgum -lm -lpspaudio -lpspfpu EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = RetroArch PSP1 @@ -34,5 +34,7 @@ PSP_OBJECTS = griffin/griffin.o OBJS = $(PSP_OBJECTS) +griffin/griffin.o: psp1/psp1_video.c psp1/psp1_audio.c frontend/platform/platform_psp.c + PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak diff --git a/config.def.h b/config.def.h index 9ee0f4ec46..8b70344254 100644 --- a/config.def.h +++ b/config.def.h @@ -68,6 +68,7 @@ enum AUDIO_XENON360, AUDIO_WII, AUDIO_RWEBAUDIO, + AUDIO_PSP1, AUDIO_NULL, INPUT_ANDROID, @@ -131,6 +132,8 @@ enum #define AUDIO_DEFAULT_DRIVER AUDIO_XENON360 #elif defined(GEKKO) #define AUDIO_DEFAULT_DRIVER AUDIO_WII +#elif defined(PSP) +#define AUDIO_DEFAULT_DRIVER AUDIO_PSP1 #elif defined(HAVE_ALSA) && defined(HAVE_VIDEOCORE) #define AUDIO_DEFAULT_DRIVER AUDIO_ALSATHREAD #elif defined(HAVE_ALSA) diff --git a/driver.c b/driver.c index 607e93cd7e..03127a6d9f 100644 --- a/driver.c +++ b/driver.c @@ -88,6 +88,9 @@ static const audio_driver_t *audio_drivers[] = { #ifdef EMSCRIPTEN &audio_rwebaudio, #endif +#ifdef PSP + &audio_psp1, +#endif #ifdef HAVE_NULLAUDIO &audio_null, #endif diff --git a/driver.h b/driver.h index d655a9595e..fe791d60fc 100644 --- a/driver.h +++ b/driver.h @@ -652,6 +652,7 @@ extern const audio_driver_t audio_coreaudio; extern const audio_driver_t audio_xenon360; extern const audio_driver_t audio_ps3; extern const audio_driver_t audio_gx; +extern const audio_driver_t audio_psp1; extern const audio_driver_t audio_rwebaudio; extern const audio_driver_t audio_null; extern const video_driver_t video_gl; diff --git a/frontend/platform/platform_psp.c b/frontend/platform/platform_psp.c index 0ae220db73..7a00cc080a 100644 --- a/frontend/platform/platform_psp.c +++ b/frontend/platform/platform_psp.c @@ -16,6 +16,7 @@ #include #include +#include #include #include "../../boolean.h" @@ -90,10 +91,12 @@ static void system_init(void *data) { (void)data; //initialize debug screen - pspDebugScreenInit(); + pspDebugScreenInit(); pspDebugScreenClear(); setup_callback(); + + pspFpuSetEnable(0);//disable FPU exceptions } static void system_deinit(void *data) @@ -113,6 +116,9 @@ static int psp_process_args(int argc, char *argv[], void *args) strlcpy(g_extern.fullpath, path, sizeof(g_extern.fullpath)); g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); +#else + strlcpy(g_extern.fullpath, argv[1], sizeof(g_extern.fullpath)); + g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); #endif } diff --git a/griffin/griffin.c b/griffin/griffin.c index 4fe3aac0a2..90f5edc83a 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -408,6 +408,8 @@ AUDIO #include "../gx/gx_audio.c" #elif defined(EMSCRIPTEN) #include "../audio/rwebaudio.c" +#elif defined(PSP) +#include "../psp1/psp1_audio.c" #endif #ifdef HAVE_XAUDIO diff --git a/psp1/psp1_audio.c b/psp1/psp1_audio.c new file mode 100644 index 0000000000..b4e96c5344 --- /dev/null +++ b/psp1/psp1_audio.c @@ -0,0 +1,146 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "../general.h" +#include "../driver.h" + + +#include + +//ToDO +typedef struct +{ + bool nonblocking; + bool started; +} psp1_audio_t; + +psp1_audio_t audioData; + +#define AUDIO_OUT_COUNT 128 + +#define AUDIO_BUFFER_SIZE (1u<<12u) +#define AUDIO_BUFFER_SIZE_MASK (AUDIO_BUFFER_SIZE-1) + +static u32 __attribute__ ( ( aligned ( 64 ) ) ) audioBuffer[AUDIO_BUFFER_SIZE]; +static u32 __attribute__ ( ( aligned ( 64 ) ) ) zeroBuffer[AUDIO_OUT_COUNT]= {0}; + +static bool audioRunning=false; +static SceUID audioThread=0; +static int audioOutputRate; + +static u16 readPos=0; +static u16 writePos=0; + +int audioMainLoop ( SceSize args, void* argp ) { + + sceAudioSRCChReserve ( AUDIO_OUT_COUNT,audioOutputRate,2 ); + while ( audioRunning ) { + if ( ( (u16)(readPos-writePos)& AUDIO_BUFFER_SIZE_MASK ) < (u16)AUDIO_OUT_COUNT*2 ) { + sceAudioSRCOutputBlocking ( PSP_AUDIO_VOLUME_MAX,zeroBuffer ); + } else { + sceAudioSRCOutputBlocking ( PSP_AUDIO_VOLUME_MAX,audioBuffer+readPos ); + readPos+=AUDIO_OUT_COUNT; + readPos&=AUDIO_BUFFER_SIZE_MASK; + } + + + } + sceAudioSRCChRelease(); + sceKernelExitThread ( 0 ); + return 0; +} +static bool psp_audio_start(void *data); +static void *psp_audio_init(const char *device, unsigned rate, unsigned latency) +{ + (void)device; + (void)latency; + audioOutputRate=rate; + audioThread= sceKernelCreateThread ( "audioMainLoop",audioMainLoop,0x12,0x10000,0,NULL ); + psp_audio_start(NULL); + return (void*)&audioData; +} + +static void psp_audio_free(void *data) +{ + (void)data; + if(audioThread) + sceKernelDeleteThread(audioThread); +} + +static ssize_t psp_audio_write(void *data, const void *buf, size_t size) +{ + size/=4; + (void)data; + (void)buf; + size_t size1,size2; + + size1=size; + if((writePos+size)>AUDIO_BUFFER_SIZE){ + memcpy(audioBuffer+writePos,buf,(AUDIO_BUFFER_SIZE-writePos)*sizeof(u32)); + memcpy(audioBuffer,buf,(writePos+size-AUDIO_BUFFER_SIZE)*sizeof(u32)); + }else{ + memcpy(audioBuffer+writePos,buf,size*sizeof(u32)); + } + + writePos+=size; + writePos&=AUDIO_BUFFER_SIZE_MASK; + return size; +} + +static bool psp_audio_stop(void *data) +{ + (void)data; + if(!audioThread) + return false; + + audioRunning=false; + return (sceKernelWaitThreadEnd(audioThread,NULL) >= 0); +} + +static bool psp_audio_start(void *data) +{ + (void)data; + if(!audioThread) + return false; + + audioRunning=true; + return (sceKernelStartThread ( audioThread,0,NULL ) >= 0); +} + +static void psp_audio_set_nonblock_state(void *data, bool state) +{ + (void)data; + (void)state; +} + +static bool psp_audio_use_float(void *data) +{ + (void)data; + return false; +} + +const audio_driver_t audio_psp1 = { + psp_audio_init, + psp_audio_write, + psp_audio_stop, + psp_audio_start, + psp_audio_set_nonblock_state, + psp_audio_free, + psp_audio_use_float, + "psp1", +}; + + + diff --git a/settings.c b/settings.c index 2368d465bb..3fc29b32f5 100644 --- a/settings.c +++ b/settings.c @@ -67,6 +67,8 @@ const char *config_get_default_audio(void) return "ps3"; case AUDIO_WII: return "gx"; + case AUDIO_PSP1: + return "psp1"; case AUDIO_RWEBAUDIO: return "rwebaudio"; case AUDIO_NULL: From 566696223f074d990e22f4a118da31f86392f78f Mon Sep 17 00:00:00 2001 From: aliaspider Date: Mon, 17 Feb 2014 14:31:33 +0100 Subject: [PATCH 2/2] (PSP) allow game loading form the commandline (for use with pspsh) --- frontend/platform/platform_psp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/platform/platform_psp.c b/frontend/platform/platform_psp.c index 7a00cc080a..7e324834e1 100644 --- a/frontend/platform/platform_psp.c +++ b/frontend/platform/platform_psp.c @@ -93,7 +93,7 @@ static void system_init(void *data) //initialize debug screen pspDebugScreenInit(); pspDebugScreenClear(); - + setup_callback(); pspFpuSetEnable(0);//disable FPU exceptions @@ -117,8 +117,10 @@ static int psp_process_args(int argc, char *argv[], void *args) strlcpy(g_extern.fullpath, path, sizeof(g_extern.fullpath)); g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); #else - strlcpy(g_extern.fullpath, argv[1], sizeof(g_extern.fullpath)); - g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); + if (argv[1]&&(argv[1][0])){ + strlcpy(g_extern.fullpath, argv[1], sizeof(g_extern.fullpath)); + g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); + } #endif }