(PSP) added audio support

This commit is contained in:
aliaspider 2014-02-17 14:26:03 +01:00
parent 9a2863e95f
commit 650adef8da
8 changed files with 168 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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;

View File

@ -16,6 +16,7 @@
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspfpu.h>
#include <stdint.h>
#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
}

View File

@ -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

146
psp1/psp1_audio.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "../general.h"
#include "../driver.h"
#include <pspaudio.h>
//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",
};

View File

@ -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: