mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +00:00
Merge pull request #5914 from frangarcj/psp_audio
(PSP) Sync audio thread
This commit is contained in:
commit
fde0cca93d
@ -50,6 +50,9 @@ typedef struct psp_audio
|
|||||||
char lock[32] __attribute__ ((aligned (8)));
|
char lock[32] __attribute__ ((aligned (8)));
|
||||||
char cond_lock[32] __attribute__ ((aligned (8)));
|
char cond_lock[32] __attribute__ ((aligned (8)));
|
||||||
char cond[32] __attribute__ ((aligned (8)));
|
char cond[32] __attribute__ ((aligned (8)));
|
||||||
|
#else
|
||||||
|
SceUID lock;
|
||||||
|
SceUID cond;
|
||||||
#endif
|
#endif
|
||||||
} psp_audio_t;
|
} psp_audio_t;
|
||||||
|
|
||||||
@ -83,15 +86,13 @@ static int audioMainLoop(SceSize args, void* argp)
|
|||||||
|
|
||||||
#ifdef VITA
|
#ifdef VITA
|
||||||
sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0);
|
sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0);
|
||||||
|
#else
|
||||||
|
sceKernelWaitSema(psp->lock, 1, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cond = ((uint16_t)(psp->write_pos - read_pos) & AUDIO_BUFFER_SIZE_MASK)
|
cond = ((uint16_t)(psp->write_pos - read_pos) & AUDIO_BUFFER_SIZE_MASK)
|
||||||
< (AUDIO_OUT_COUNT * 2);
|
< (AUDIO_OUT_COUNT * 2);
|
||||||
|
|
||||||
#ifndef VITA
|
|
||||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, cond ? (psp->zeroBuffer)
|
|
||||||
: (psp->buffer + read_pos));
|
|
||||||
#endif
|
|
||||||
if (!cond)
|
if (!cond)
|
||||||
{
|
{
|
||||||
read_pos += AUDIO_OUT_COUNT;
|
read_pos += AUDIO_OUT_COUNT;
|
||||||
@ -106,6 +107,13 @@ static int audioMainLoop(SceSize args, void* argp)
|
|||||||
sceAudioOutOutput(port,
|
sceAudioOutOutput(port,
|
||||||
cond ? (psp->zeroBuffer)
|
cond ? (psp->zeroBuffer)
|
||||||
: (psp->buffer + read_pos_2));
|
: (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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +159,8 @@ static void *psp_audio_init(const char *device,
|
|||||||
psp->thread = sceKernelCreateThread
|
psp->thread = sceKernelCreateThread
|
||||||
("audioMainLoop", audioMainLoop, 0x10000100, 0x10000, 0, 0, NULL);
|
("audioMainLoop", audioMainLoop, 0x10000100, 0x10000, 0, 0, NULL);
|
||||||
#else
|
#else
|
||||||
|
psp->cond=sceKernelCreateSema("audio_start_sema", 0, 0, 1, NULL);
|
||||||
|
psp->lock=sceKernelCreateSema("audio_lock_sema", 0, 1, 1, NULL);
|
||||||
psp->thread = sceKernelCreateThread
|
psp->thread = sceKernelCreateThread
|
||||||
("audioMainLoop", audioMainLoop, 0x08, 0x10000, 0, NULL);
|
("audioMainLoop", audioMainLoop, 0x08, 0x10000, 0, NULL);
|
||||||
#endif
|
#endif
|
||||||
@ -177,6 +187,8 @@ static void psp_audio_free(void *data)
|
|||||||
sceKernelDeleteLwCond((struct SceKernelLwCondWork*)&psp->cond);
|
sceKernelDeleteLwCond((struct SceKernelLwCondWork*)&psp->cond);
|
||||||
#else
|
#else
|
||||||
sceKernelWaitThreadEnd(psp->thread, &timeout);
|
sceKernelWaitThreadEnd(psp->thread, &timeout);
|
||||||
|
sceKernelDeleteSema(psp->lock);
|
||||||
|
sceKernelDeleteSema(psp->cond);
|
||||||
#endif
|
#endif
|
||||||
free(psp->buffer);
|
free(psp->buffer);
|
||||||
sceKernelDeleteThread(psp->thread);
|
sceKernelDeleteThread(psp->thread);
|
||||||
@ -192,11 +204,11 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
|
|||||||
|
|
||||||
if (psp->nonblocking)
|
if (psp->nonblocking)
|
||||||
{
|
{
|
||||||
#ifdef VITA
|
//#ifdef VITA
|
||||||
if (AUDIO_BUFFER_SIZE - ((uint16_t)
|
if (AUDIO_BUFFER_SIZE - ((uint16_t)
|
||||||
(psp->write_pos - psp->read_pos) & AUDIO_BUFFER_SIZE_MASK) < size)
|
(psp->write_pos - psp->read_pos) & AUDIO_BUFFER_SIZE_MASK) < size)
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VITA
|
#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);
|
sceKernelWaitLwCond((struct SceKernelLwCondWork*)&psp->cond, 0);
|
||||||
|
|
||||||
sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 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
|
#endif
|
||||||
|
|
||||||
if((write_pos + sampleCount) > AUDIO_BUFFER_SIZE)
|
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;
|
return size;
|
||||||
#else
|
#else
|
||||||
return sampleCount;
|
sceKernelSignalSema(psp->lock, 1);
|
||||||
|
|
||||||
|
return size;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,6 +330,8 @@ static size_t psp_write_avail(void *data)
|
|||||||
|
|
||||||
#ifdef VITA
|
#ifdef VITA
|
||||||
sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0);
|
sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0);
|
||||||
|
#else
|
||||||
|
sceKernelWaitSema(psp->lock, 1, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
val = AUDIO_BUFFER_SIZE - ((uint16_t)
|
val = AUDIO_BUFFER_SIZE - ((uint16_t)
|
||||||
@ -318,6 +339,8 @@ static size_t psp_write_avail(void *data)
|
|||||||
|
|
||||||
#ifdef VITA
|
#ifdef VITA
|
||||||
sceKernelUnlockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1);
|
sceKernelUnlockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1);
|
||||||
|
#else
|
||||||
|
sceKernelSignalSema(psp->lock, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user