(Vita) Attempt to reuse PSP1 audio driver for Vita

This commit is contained in:
twinaphex 2015-08-12 12:18:45 +02:00
parent b892f8252b
commit 273788cdf9
6 changed files with 43 additions and 25 deletions

View File

@ -117,8 +117,8 @@ static const audio_driver_t *audio_drivers[] = {
#ifdef EMSCRIPTEN
&audio_rwebaudio,
#endif
#ifdef PSP
&audio_psp1,
#if defined(PSP) || defined(VITA)
&audio_psp,
#endif
#ifdef _3DS
&audio_ctr,

View File

@ -88,7 +88,7 @@ extern audio_driver_t audio_coreaudio;
extern audio_driver_t audio_xenon360;
extern audio_driver_t audio_ps3;
extern audio_driver_t audio_gx;
extern audio_driver_t audio_psp1;
extern audio_driver_t audio_psp;
extern audio_driver_t audio_ctr;
extern audio_driver_t audio_rwebaudio;
extern audio_driver_t audio_null;

View File

@ -18,11 +18,18 @@
#include "../../general.h"
#include "../../driver.h"
#ifdef VITA
#include <psp2/kernel/processmgr.h>
#include <psp2/kernel/threadmgr.h>
#include <psp2/kernel/sysmem.h>
#include <psp2/audioout.h>
#else
#include <pspkernel.h>
#include <pspaudio.h>
#endif
#include <stdint.h>
typedef struct psp1_audio
typedef struct psp_audio
{
bool nonblocking;
uint32_t* buffer;
@ -33,7 +40,7 @@ typedef struct psp1_audio
volatile bool running;
volatile uint16_t readPos;
volatile uint16_t writePos;
} psp1_audio_t;
} psp_audio_t;
#define AUDIO_OUT_COUNT 512u
#define AUDIO_BUFFER_SIZE (1u<<13u)
@ -41,9 +48,13 @@ typedef struct psp1_audio
static int audioMainLoop(SceSize args, void* argp)
{
psp1_audio_t* psp = *((psp1_audio_t**)argp);
psp_audio_t* psp = *((psp_audio_t**)argp);
#ifdef VITA
sceAudioOutOpenPort(0, AUDIO_OUT_COUNT, psp->rate, 2);
#else
sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2);
#endif
while (psp->running)
{
@ -52,8 +63,13 @@ static int audioMainLoop(SceSize args, void* argp)
bool cond = ((uint16_t)(psp->writePos - readPos) & AUDIO_BUFFER_SIZE_MASK)
< (AUDIO_OUT_COUNT * 2);
#ifdef VITA
sceAudioOutOutput(0,
cond ? psp->zeroBuffer : (psp->buffer + readPos));
#else
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, cond ? (psp->zeroBuffer)
: (psp->buffer + readPos));
#endif
if (!cond)
{
@ -63,7 +79,9 @@ static int audioMainLoop(SceSize args, void* argp)
}
}
#ifndef VITA
sceAudioSRCChRelease();
#endif
sceKernelExitThread(0);
return 0;
}
@ -71,7 +89,7 @@ static int audioMainLoop(SceSize args, void* argp)
static void *psp_audio_init(const char *device,
unsigned rate, unsigned latency)
{
psp1_audio_t *psp = (psp1_audio_t*)calloc(1, sizeof(psp1_audio_t));
psp_audio_t *psp = (psp_audio_t*)calloc(1, sizeof(psp_audio_t));
if (!psp)
return NULL;
@ -96,7 +114,7 @@ static void *psp_audio_init(const char *device,
psp->nonblocking = false;
psp->running = true;
sceKernelStartThread(psp->thread, sizeof(psp1_audio_t*), &psp);
sceKernelStartThread(psp->thread, sizeof(psp_audio_t*), &psp);
return psp;
}
@ -104,7 +122,7 @@ static void *psp_audio_init(const char *device,
static void psp_audio_free(void *data)
{
SceUInt timeout = 100000;
psp1_audio_t* psp = (psp1_audio_t*)data;
psp_audio_t* psp = (psp_audio_t*)data;
if(!psp)
return;
@ -121,7 +139,7 @@ static void psp_audio_free(void *data)
static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
{
uint16_t sampleCount;
psp1_audio_t* psp = (psp1_audio_t*)data;
psp_audio_t* psp = (psp_audio_t*)data;
uint16_t writePos = psp->writePos;
sampleCount= size / sizeof(uint32_t);
@ -153,7 +171,7 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
static bool psp_audio_alive(void *data)
{
psp1_audio_t* psp = (psp1_audio_t*)data;
psp_audio_t* psp = (psp_audio_t*)data;
if (!psp)
return false;
return psp->running;
@ -163,7 +181,7 @@ static bool psp_audio_stop(void *data)
{
SceKernelThreadRunStatus runStatus;
SceUInt timeout = 100000;
psp1_audio_t* psp = (psp1_audio_t*)data;
psp_audio_t* psp = (psp_audio_t*)data;
runStatus.size = sizeof(SceKernelThreadRunStatus);
@ -182,7 +200,7 @@ static bool psp_audio_stop(void *data)
static bool psp_audio_start(void *data)
{
SceKernelThreadRunStatus runStatus;
psp1_audio_t* psp = (psp1_audio_t*)data;
psp_audio_t* psp = (psp_audio_t*)data;
runStatus.size = sizeof(SceKernelThreadRunStatus);
@ -194,14 +212,14 @@ static bool psp_audio_start(void *data)
psp->running = true;
sceKernelStartThread(psp->thread, sizeof(psp1_audio_t*), &psp);
sceKernelStartThread(psp->thread, sizeof(psp_audio_t*), &psp);
return true;
}
static void psp_audio_set_nonblock_state(void *data, bool toggle)
{
psp1_audio_t* psp = (psp1_audio_t*)data;
psp_audio_t* psp = (psp_audio_t*)data;
if (psp)
psp->nonblocking = toggle;
}
@ -215,7 +233,7 @@ static bool psp_audio_use_float(void *data)
static size_t psp_write_avail(void *data)
{
/* TODO */
psp1_audio_t* psp = (psp1_audio_t*)data;
psp_audio_t* psp = (psp_audio_t*)data;
return AUDIO_BUFFER_SIZE - ((uint16_t)
(psp->writePos - psp->readPos) & AUDIO_BUFFER_SIZE_MASK);
}
@ -227,7 +245,7 @@ static size_t psp_buffer_size(void *data)
}
audio_driver_t audio_psp1 = {
audio_driver_t audio_psp = {
psp_audio_init,
psp_audio_write,
psp_audio_stop,
@ -236,7 +254,7 @@ audio_driver_t audio_psp1 = {
psp_audio_set_nonblock_state,
psp_audio_free,
psp_audio_use_float,
"psp1",
"psp",
psp_write_avail,
psp_buffer_size,
};

View File

@ -66,7 +66,7 @@ enum
AUDIO_XENON360,
AUDIO_WII,
AUDIO_RWEBAUDIO,
AUDIO_PSP1,
AUDIO_PSP,
AUDIO_CTR,
AUDIO_NULL,
@ -167,8 +167,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(PSP) || defined(VITA)
#define AUDIO_DEFAULT_DRIVER AUDIO_PSP
#elif defined(_3DS)
#define AUDIO_DEFAULT_DRIVER AUDIO_CTR
#elif defined(HAVE_ALSA) && defined(HAVE_VIDEOCORE)

View File

@ -114,8 +114,8 @@ const char *config_get_default_audio(void)
return "ps3";
case AUDIO_WII:
return "gx";
case AUDIO_PSP1:
return "psp1";
case AUDIO_PSP:
return "psp";
case AUDIO_CTR:
return "ctr";
case AUDIO_RWEBAUDIO:

View File

@ -472,8 +472,8 @@ AUDIO
#include "../audio/drivers/gx_audio.c"
#elif defined(EMSCRIPTEN)
#include "../audio/drivers/rwebaudio.c"
#elif defined(PSP)
#include "../audio/drivers/psp1_audio.c"
#elif defined(PSP) || defined(VITA)
#include "../audio/drivers/psp_audio.c"
#elif defined(_3DS)
#include "../audio/drivers/ctr_audio.c"
#endif