(GX) Make gx_audio.c and platform_gx.c more generic

This commit is contained in:
twinaphex 2014-06-04 18:54:40 +02:00
parent 7a7fffc7d8
commit 353bbb5f83
2 changed files with 31 additions and 15 deletions

View File

@ -27,6 +27,8 @@
#include <cafe/ai.h>
#endif
#include "../gx/sdk_defines.h"
#define CHUNK_FRAMES 64
#define CHUNK_SIZE (CHUNK_FRAMES * sizeof(uint32_t))
#define BLOCKS 16
@ -49,7 +51,7 @@ typedef struct
volatile unsigned dma_write;
size_t write_ptr;
lwpq_t cond;
OSCond cond;
bool nonblock;
} gx_audio_t;
@ -67,7 +69,7 @@ static void dma_callback(void)
DCFlushRange(wa->data[wa->dma_next], CHUNK_SIZE);
AIInitDMA((uint32_t)wa->data[wa->dma_next], CHUNK_SIZE);
LWP_ThreadSignal(wa->cond);
OSSignalCond(wa->cond);
}
static void *gx_audio_init(const char *device, unsigned rate, unsigned latency)
@ -94,7 +96,7 @@ static void *gx_audio_init(const char *device, unsigned rate, unsigned latency)
g_settings.audio.out_rate = 48000;
}
LWP_InitQueue(&wa->cond);
OSInitThreadQueue(&wa->cond);
wa->dma_write = BLOCKS - 1;
DCFlushRange(wa->data, sizeof(wa->data));
@ -116,10 +118,10 @@ static inline void copy_swapped(uint32_t * restrict dst, const uint32_t * restri
static ssize_t gx_audio_write(void *data, const void *buf_, size_t size)
{
gx_audio_t *wa = data;
size_t frames = size >> 2;
const uint32_t *buf = buf_;
gx_audio_t *wa = data;
while (frames)
{
size_t to_write = CHUNK_FRAMES - wa->write_ptr;
@ -128,7 +130,7 @@ static ssize_t gx_audio_write(void *data, const void *buf_, size_t size)
// FIXME: Nonblocking audio should break out of loop when it has nothing to write.
while ((wa->dma_write == wa->dma_next || wa->dma_write == wa->dma_busy) && !wa->nonblock)
LWP_ThreadSleep(wa->cond);
OSSleepThread(wa->cond);
copy_swapped(wa->data[wa->dma_write] + wa->write_ptr, buf, to_write);
@ -149,6 +151,10 @@ static ssize_t gx_audio_write(void *data, const void *buf_, size_t size)
static bool gx_audio_stop(void *data)
{
gx_audio_t *wa = (gx_audio_t*)data;
if (!wa)
return false;
AIStopDMA();
memset(wa->data, 0, sizeof(wa->data));
DCFlushRange(wa->data, sizeof(wa->data));
@ -158,6 +164,10 @@ static bool gx_audio_stop(void *data)
static void gx_audio_set_nonblock_state(void *data, bool state)
{
gx_audio_t *wa = (gx_audio_t*)data;
if (!wa)
return;
wa->nonblock = state;
}
@ -171,13 +181,17 @@ static bool gx_audio_start(void *data)
static void gx_audio_free(void *data)
{
gx_audio_t *wa = (gx_audio_t*)data;
if (!wa)
return;
AIStopDMA();
AIRegisterDMACallback(NULL);
if (wa && wa->cond)
{
if (wa->cond)
LWP_CloseQueue(wa->cond);
wa->cond = 0;
}
wa->cond = 0;
free(data);
}

View File

@ -19,6 +19,7 @@
#include "../../driver.h"
#include "../../general.h"
#include "../../libretro_private.h"
#include "../../gx/sdk_defines.h"
#include "../../file.h"
@ -331,17 +332,18 @@ static void frontend_gx_init(void *data)
#endif
#if defined(HW_RVL) && !defined(IS_SALAMANDER)
lwp_t gx_device_thread;
OSThread gx_device_thread;
gx_devices[GX_DEVICE_SD].interface = &__io_wiisd;
gx_devices[GX_DEVICE_SD].name = "sd";
gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface);
gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage;
gx_devices[GX_DEVICE_USB].name = "usb";
gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface);
LWP_MutexInit(&gx_device_cond_mutex, 0);
LWP_CondInit(&gx_device_cond);
LWP_MutexInit(&gx_device_mutex, false);
LWP_CreateThread(&gx_device_thread, gx_devthread, NULL, NULL, 0, 66);
OSInitMutex(&gx_device_cond_mutex);
OSInitCond(&gx_device_cond);
OSInitMutex(&gx_device_mutex);
OSCreateThread(&gx_device_thread, gx_devthread, 0, NULL, NULL, 0, 66, 0);
#endif
}