mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 21:32:45 +00:00
(PSP) Refactor audio
This commit is contained in:
parent
cf8c4c43fa
commit
8d7ce4bf96
@ -24,7 +24,8 @@
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool nonblocking;
|
bool nonblocking;
|
||||||
bool running;
|
bool started;
|
||||||
|
bool quit_thread;
|
||||||
uint32_t* buffer;
|
uint32_t* buffer;
|
||||||
uint32_t* zeroBuffer;
|
uint32_t* zeroBuffer;
|
||||||
SceUID thread;
|
SceUID thread;
|
||||||
@ -38,8 +39,6 @@ typedef struct
|
|||||||
#define AUDIO_BUFFER_SIZE (1u<<12u)
|
#define AUDIO_BUFFER_SIZE (1u<<12u)
|
||||||
#define AUDIO_BUFFER_SIZE_MASK (AUDIO_BUFFER_SIZE-1)
|
#define AUDIO_BUFFER_SIZE_MASK (AUDIO_BUFFER_SIZE-1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int audioMainLoop(SceSize args, void* argp)
|
int audioMainLoop(SceSize args, void* argp)
|
||||||
{
|
{
|
||||||
psp1_audio_t* psp = (psp1_audio_t*)driver.audio_data;
|
psp1_audio_t* psp = (psp1_audio_t*)driver.audio_data;
|
||||||
@ -47,7 +46,7 @@ int audioMainLoop(SceSize args, void* argp)
|
|||||||
|
|
||||||
sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2);
|
sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2);
|
||||||
|
|
||||||
while (psp->running)
|
while (!psp->quit_thread)
|
||||||
{
|
{
|
||||||
if (((uint16_t)(psp->writePos - psp->readPos) & AUDIO_BUFFER_SIZE_MASK) < (uint16_t)AUDIO_OUT_COUNT * 2)
|
if (((uint16_t)(psp->writePos - psp->readPos) & AUDIO_BUFFER_SIZE_MASK) < (uint16_t)AUDIO_OUT_COUNT * 2)
|
||||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->zeroBuffer);
|
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->zeroBuffer);
|
||||||
@ -80,10 +79,9 @@ static void *psp_audio_init(const char *device, unsigned rate, unsigned latency)
|
|||||||
psp->readPos = 0;
|
psp->readPos = 0;
|
||||||
psp->writePos = 0;
|
psp->writePos = 0;
|
||||||
psp->zeroBuffer = (uint32_t*)calloc(AUDIO_OUT_COUNT, sizeof(uint32_t));
|
psp->zeroBuffer = (uint32_t*)calloc(AUDIO_OUT_COUNT, sizeof(uint32_t));
|
||||||
psp->nonblocking = true;
|
|
||||||
psp->rate = rate;
|
psp->rate = rate;
|
||||||
psp->running = false;
|
|
||||||
psp->thread = sceKernelCreateThread ("audioMainLoop", audioMainLoop, 0x12, 0x10000, 0, NULL);
|
psp->thread = sceKernelCreateThread ("audioMainLoop", audioMainLoop, 0x12, 0x10000, 0, NULL);
|
||||||
|
psp->nonblocking = true;
|
||||||
|
|
||||||
return psp;
|
return psp;
|
||||||
}
|
}
|
||||||
@ -92,6 +90,8 @@ static void psp_audio_free(void *data)
|
|||||||
{
|
{
|
||||||
psp1_audio_t* psp = (psp1_audio_t*)data;
|
psp1_audio_t* psp = (psp1_audio_t*)data;
|
||||||
|
|
||||||
|
psp->quit_thread = true;
|
||||||
|
|
||||||
sceKernelDeleteThread(psp->thread);
|
sceKernelDeleteThread(psp->thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,16 +103,24 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
|
|||||||
|
|
||||||
sampleCount= size / sizeof(uint32_t);
|
sampleCount= size / sizeof(uint32_t);
|
||||||
|
|
||||||
if((psp->writePos+sampleCount)>AUDIO_BUFFER_SIZE)
|
if (psp->nonblocking)
|
||||||
|
{
|
||||||
|
/* TODO */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if((psp->writePos + sampleCount) > AUDIO_BUFFER_SIZE)
|
||||||
{
|
{
|
||||||
memcpy(psp->buffer + psp->writePos, buf, (AUDIO_BUFFER_SIZE - psp->writePos) * sizeof(uint32_t));
|
memcpy(psp->buffer + psp->writePos, buf, (AUDIO_BUFFER_SIZE - psp->writePos) * sizeof(uint32_t));
|
||||||
memcpy(psp->buffer, buf, (psp->writePos + sampleCount - AUDIO_BUFFER_SIZE) * sizeof(uint32_t));
|
memcpy(psp->buffer, buf, (psp->writePos + sampleCount - AUDIO_BUFFER_SIZE) * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
memcpy(psp->buffer + psp->writePos, buf, size);
|
memcpy(psp->buffer + psp->writePos, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
psp->writePos += sampleCount;
|
psp->writePos += sampleCount;
|
||||||
psp->writePos &= AUDIO_BUFFER_SIZE_MASK;
|
psp->writePos &= AUDIO_BUFFER_SIZE_MASK;
|
||||||
|
|
||||||
return sampleCount;
|
return sampleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,28 +128,32 @@ static bool psp_audio_stop(void *data)
|
|||||||
{
|
{
|
||||||
psp1_audio_t* psp = (psp1_audio_t*)data;
|
psp1_audio_t* psp = (psp1_audio_t*)data;
|
||||||
|
|
||||||
if(psp->thread <= 0) // ToDO: verify that this is the correct way to check a thread ID for validity
|
if (psp->started)
|
||||||
return false;
|
{
|
||||||
|
sceKernelWaitThreadEnd(psp->thread, NULL);
|
||||||
|
psp->started = false;
|
||||||
|
}
|
||||||
|
|
||||||
psp->running = false;
|
return true;
|
||||||
return (sceKernelWaitThreadEnd(psp->thread, NULL) >= 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool psp_audio_start(void *data)
|
static bool psp_audio_start(void *data)
|
||||||
{
|
{
|
||||||
psp1_audio_t* psp = (psp1_audio_t*)data;
|
psp1_audio_t* psp = (psp1_audio_t*)data;
|
||||||
if (psp->thread <= 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
psp->running=true;
|
if (!psp->started)
|
||||||
return (sceKernelStartThread(psp->thread, sizeof(psp1_audio_t*), &data) >= 0);
|
{
|
||||||
|
sceKernelStartThread(psp->thread, sizeof(psp1_audio_t*), &data);
|
||||||
|
psp->started = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void psp_audio_set_nonblock_state(void *data, bool state)
|
static void psp_audio_set_nonblock_state(void *data, bool toggle)
|
||||||
{
|
{
|
||||||
psp1_audio_t* psp = (psp1_audio_t*)data;
|
psp1_audio_t* psp = (psp1_audio_t*)data;
|
||||||
|
psp->nonblocking = toggle;
|
||||||
psp->nonblocking = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool psp_audio_use_float(void *data)
|
static bool psp_audio_use_float(void *data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user