From 21aedd46ee251ed65b6b2223476c46fd364ea6ae Mon Sep 17 00:00:00 2001 From: ggf906 Date: Fri, 15 Dec 2017 13:35:10 +0100 Subject: [PATCH] (PSP) Sync audio thread --- audio/drivers/psp_audio.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/audio/drivers/psp_audio.c b/audio/drivers/psp_audio.c index fbc6762ac3..49c3362440 100644 --- a/audio/drivers/psp_audio.c +++ b/audio/drivers/psp_audio.c @@ -50,6 +50,9 @@ typedef struct psp_audio char lock[32] __attribute__ ((aligned (8))); char cond_lock[32] __attribute__ ((aligned (8))); char cond[32] __attribute__ ((aligned (8))); +#else + SceUID lock; + SceUID cond; #endif } psp_audio_t; @@ -83,15 +86,13 @@ static int audioMainLoop(SceSize args, void* argp) #ifdef VITA sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0); +#else + sceKernelWaitSema(psp->lock, 1, 0); #endif cond = ((uint16_t)(psp->write_pos - read_pos) & AUDIO_BUFFER_SIZE_MASK) < (AUDIO_OUT_COUNT * 2); -#ifndef VITA - sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, cond ? (psp->zeroBuffer) - : (psp->buffer + read_pos)); -#endif if (!cond) { read_pos += AUDIO_OUT_COUNT; @@ -106,6 +107,13 @@ static int audioMainLoop(SceSize args, void* argp) sceAudioOutOutput(port, cond ? (psp->zeroBuffer) : (psp->buffer + read_pos_2)); +#else + sceKernelSignalSema(psp->lock, 1); + if(!cond){ + sceKernelSignalSema(psp->cond, 1); + } + sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, cond ? (psp->zeroBuffer) + : (psp->buffer + read_pos)); #endif } @@ -151,6 +159,8 @@ static void *psp_audio_init(const char *device, psp->thread = sceKernelCreateThread ("audioMainLoop", audioMainLoop, 0x10000100, 0x10000, 0, 0, NULL); #else + psp->cond=sceKernelCreateSema("audio_start_sema", 0, 0, 1, NULL); + psp->lock=sceKernelCreateSema("audio_lock_sema", 0, 1, 1, NULL); psp->thread = sceKernelCreateThread ("audioMainLoop", audioMainLoop, 0x08, 0x10000, 0, NULL); #endif @@ -177,6 +187,8 @@ static void psp_audio_free(void *data) sceKernelDeleteLwCond((struct SceKernelLwCondWork*)&psp->cond); #else sceKernelWaitThreadEnd(psp->thread, &timeout); + sceKernelDeleteSema(psp->lock); + sceKernelDeleteSema(psp->cond); #endif free(psp->buffer); sceKernelDeleteThread(psp->thread); @@ -192,11 +204,11 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size) if (psp->nonblocking) { -#ifdef VITA +//#ifdef VITA if (AUDIO_BUFFER_SIZE - ((uint16_t) (psp->write_pos - psp->read_pos) & AUDIO_BUFFER_SIZE_MASK) < size) - return 0; -#endif + return 0; +//#endif } #ifdef VITA @@ -205,6 +217,11 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size) sceKernelWaitLwCond((struct SceKernelLwCondWork*)&psp->cond, 0); sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0); +#else + while (AUDIO_BUFFER_SIZE - ((uint16_t) + (psp->write_pos - psp->read_pos) & AUDIO_BUFFER_SIZE_MASK) < size) + sceKernelWaitSema(psp->cond, 1, 0); + sceKernelWaitSema(psp->lock, 1, 0); #endif if((write_pos + sampleCount) > AUDIO_BUFFER_SIZE) @@ -227,7 +244,9 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size) return size; #else - return sampleCount; + sceKernelSignalSema(psp->lock, 1); + + return size; #endif } @@ -311,6 +330,8 @@ static size_t psp_write_avail(void *data) #ifdef VITA sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0); +#else + sceKernelWaitSema(psp->lock, 1, 0); #endif val = AUDIO_BUFFER_SIZE - ((uint16_t) @@ -318,6 +339,8 @@ static size_t psp_write_avail(void *data) #ifdef VITA sceKernelUnlockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1); +#else + sceKernelSignalSema(psp->lock, 1); #endif return val;