mirror of
https://github.com/libretro/RetroArch
synced 2025-04-16 08:43:10 +00:00
Merge pull request #8341 from fjtrujy/feature/PS2AudioImprovement
[PS2] Audio improvement
This commit is contained in:
commit
0778847062
@ -23,84 +23,18 @@
|
|||||||
|
|
||||||
#include "../audio_driver.h"
|
#include "../audio_driver.h"
|
||||||
|
|
||||||
|
#define AUDIO_BUFFER 64 * 1024
|
||||||
|
#define AUDIO_CHANNELS 2
|
||||||
|
#define AUDIO_BITS 16
|
||||||
|
|
||||||
typedef struct ps2_audio
|
typedef struct ps2_audio
|
||||||
{
|
{
|
||||||
fifo_buffer_t* buffer;
|
fifo_buffer_t* buffer;
|
||||||
bool nonblocking;
|
bool nonblocking;
|
||||||
volatile bool running;
|
bool running;
|
||||||
int worker_thread;
|
|
||||||
int lock;
|
|
||||||
int cond_lock;
|
|
||||||
|
|
||||||
} ps2_audio_t;
|
} ps2_audio_t;
|
||||||
|
|
||||||
static ps2_audio_t *backup_ps2;
|
|
||||||
static u8 audioThreadStack[4 * 1024] __attribute__ ((aligned(16)));
|
|
||||||
|
|
||||||
#define AUDIO_OUT_BUFFER 2 * 1024
|
|
||||||
#define AUDIO_BUFFER 64 * 1024
|
|
||||||
#define AUDIO_CHANNELS 2
|
|
||||||
#define AUDIO_BITS 16
|
|
||||||
#define AUDIO_PRIORITY 0x7F /* LOWER VALUE GRATHER PRIORITY*/
|
|
||||||
|
|
||||||
static void audioMainLoop(void *data)
|
|
||||||
{
|
|
||||||
char out_tmp[AUDIO_OUT_BUFFER];
|
|
||||||
ps2_audio_t* ps2 = backup_ps2;
|
|
||||||
|
|
||||||
while (ps2->running)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
WaitSema(ps2->lock);
|
|
||||||
size = MIN(fifo_read_avail(ps2->buffer), sizeof(out_tmp));
|
|
||||||
fifo_read(ps2->buffer, out_tmp, size);
|
|
||||||
iSignalSema(ps2->lock);
|
|
||||||
iSignalSema(ps2->cond_lock);
|
|
||||||
|
|
||||||
audsrv_wait_audio(size);
|
|
||||||
audsrv_play_audio(out_tmp, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
audsrv_stop_audio();
|
|
||||||
ExitDeleteThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void audioCreateThread(ps2_audio_t *ps2)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
ee_thread_t thread;
|
|
||||||
|
|
||||||
thread.func=&audioMainLoop;
|
|
||||||
thread.stack=audioThreadStack;
|
|
||||||
thread.stack_size=sizeof(audioThreadStack);
|
|
||||||
thread.gp_reg=&_gp;
|
|
||||||
thread.initial_priority=AUDIO_PRIORITY;
|
|
||||||
thread.attr=thread.option=0;
|
|
||||||
|
|
||||||
/*Backup the PS2 content to be used in the thread */
|
|
||||||
backup_ps2 = ps2;
|
|
||||||
|
|
||||||
ps2->running = true;
|
|
||||||
ps2->worker_thread = CreateThread(&thread);
|
|
||||||
|
|
||||||
if (ps2->worker_thread >= 0)
|
|
||||||
{
|
|
||||||
ret = StartThread(ps2->worker_thread, NULL);
|
|
||||||
if (ret < 0)
|
|
||||||
printf("sound_init: StartThread returned %d\n", ret);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printf("CreateThread failed: %d\n", ps2->worker_thread);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void audioStopNDeleteThread(ps2_audio_t *ps2)
|
|
||||||
{
|
|
||||||
ps2->running = false;
|
|
||||||
if (ps2->worker_thread)
|
|
||||||
ps2->worker_thread = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void audioConfigure(ps2_audio_t *ps2, unsigned rate)
|
static void audioConfigure(ps2_audio_t *ps2, unsigned rate)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -120,23 +54,6 @@ static void audioConfigure(ps2_audio_t *ps2, unsigned rate)
|
|||||||
audsrv_set_volume(MAX_VOLUME);
|
audsrv_set_volume(MAX_VOLUME);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void audioCreateSemas(ps2_audio_t *ps2)
|
|
||||||
{
|
|
||||||
ee_sema_t lock_info;
|
|
||||||
ee_sema_t cond_lock_info;
|
|
||||||
|
|
||||||
lock_info.max_count = 1;
|
|
||||||
lock_info.init_count = 1;
|
|
||||||
lock_info.option = 0;
|
|
||||||
ps2->lock = CreateSema(&lock_info);
|
|
||||||
|
|
||||||
cond_lock_info.init_count = 1;
|
|
||||||
cond_lock_info.max_count = 1;
|
|
||||||
cond_lock_info.option = 0;
|
|
||||||
|
|
||||||
ps2->cond_lock = CreateSema(&cond_lock_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *ps2_audio_init(const char *device,
|
static void *ps2_audio_init(const char *device,
|
||||||
unsigned rate, unsigned latency,
|
unsigned rate, unsigned latency,
|
||||||
unsigned block_frames,
|
unsigned block_frames,
|
||||||
@ -147,10 +64,7 @@ static void *ps2_audio_init(const char *device,
|
|||||||
if (!ps2)
|
if (!ps2)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ps2->buffer = fifo_new(AUDIO_BUFFER);
|
|
||||||
audioConfigure(ps2, rate);
|
audioConfigure(ps2, rate);
|
||||||
audioCreateSemas(ps2);
|
|
||||||
audioCreateThread(ps2);
|
|
||||||
|
|
||||||
return ps2;
|
return ps2;
|
||||||
}
|
}
|
||||||
@ -161,21 +75,8 @@ static void ps2_audio_free(void *data)
|
|||||||
if(!ps2)
|
if(!ps2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(ps2->running){
|
ps2->running = false;
|
||||||
audioStopNDeleteThread(ps2);
|
audsrv_stop_audio();
|
||||||
|
|
||||||
if (ps2->lock){
|
|
||||||
iDeleteSema(ps2->lock);
|
|
||||||
ps2->lock = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ps2->cond_lock){
|
|
||||||
iDeleteSema(ps2->cond_lock);
|
|
||||||
ps2->cond_lock = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
fifo_free(ps2->buffer);
|
|
||||||
free(ps2);
|
free(ps2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,12 +93,8 @@ static ssize_t ps2_audio_write(void *data, const void *buf, size_t size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fifo_write_avail(ps2->buffer) < size)
|
audsrv_wait_audio(size);
|
||||||
WaitSema(ps2->cond_lock);
|
audsrv_play_audio(buf, size);
|
||||||
|
|
||||||
WaitSema(ps2->lock);
|
|
||||||
fifo_write(ps2->buffer, buf, size);
|
|
||||||
iSignalSema(ps2->lock);
|
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@ -220,8 +117,8 @@ static bool ps2_audio_stop(void *data)
|
|||||||
|
|
||||||
if (ps2)
|
if (ps2)
|
||||||
{
|
{
|
||||||
audioStopNDeleteThread(ps2);
|
|
||||||
audsrv_stop_audio();
|
audsrv_stop_audio();
|
||||||
|
ps2->running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return stop;
|
return stop;
|
||||||
@ -234,8 +131,7 @@ static bool ps2_audio_start(void *data, bool is_shutdown)
|
|||||||
|
|
||||||
if (ps2)
|
if (ps2)
|
||||||
{
|
{
|
||||||
if (!ps2->running && !ps2->worker_thread)
|
ps2->running = true;
|
||||||
audioCreateThread(ps2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return start;
|
return start;
|
||||||
@ -260,11 +156,7 @@ static size_t ps2_audio_write_avail(void *data)
|
|||||||
|
|
||||||
if (ps2 && ps2->running)
|
if (ps2 && ps2->running)
|
||||||
{
|
{
|
||||||
size_t size;
|
return AUDIO_BUFFER;
|
||||||
WaitSema(ps2->lock);
|
|
||||||
size = AUDIO_BUFFER - fifo_read_avail(ps2->buffer);
|
|
||||||
iSignalSema(ps2->lock);
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -182,8 +182,8 @@ static void clearVRAMIfNeeded(ps2_video_t *ps2, void *frame, int width, int heig
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ps2->clearVRAM) {
|
if (ps2->clearVRAM) {
|
||||||
gsKit_clear(ps2->gsGlobal, GS_BLACK);
|
|
||||||
gsKit_vram_clear(ps2->gsGlobal);
|
gsKit_vram_clear(ps2->gsGlobal);
|
||||||
|
ps2->iface.updatedPalette = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +266,7 @@ static bool ps2_gfx_frame(void *data, const void *frame,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
clearVRAMIfNeeded(ps2, frame, width, height);
|
clearVRAMIfNeeded(ps2, frame, width, height);
|
||||||
|
gsKit_clear(ps2->gsGlobal, GS_BLACK);
|
||||||
|
|
||||||
if (frame) {
|
if (frame) {
|
||||||
bool sendPalette = false;
|
bool sendPalette = false;
|
||||||
@ -277,7 +278,6 @@ static bool ps2_gfx_frame(void *data, const void *frame,
|
|||||||
ps2->iface.updatedPalette = false;
|
ps2->iface.updatedPalette = false;
|
||||||
padding = ps2->iface.padding;
|
padding = ps2->iface.padding;
|
||||||
if (ps2->iface.clearTexture) {
|
if (ps2->iface.clearTexture) {
|
||||||
gsKit_clear(ps2->gsGlobal, GS_BLACK);
|
|
||||||
ps2->iface.clearTexture = false;
|
ps2->iface.clearTexture = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,6 +434,8 @@ static void ps2_set_texture_enable(void *data, bool enable, bool fullscreen)
|
|||||||
if (ps2->menuVisible != enable) {
|
if (ps2->menuVisible != enable) {
|
||||||
/* If Menu change status, CLEAR VRAM */
|
/* If Menu change status, CLEAR VRAM */
|
||||||
ps2->clearVRAM = true;
|
ps2->clearVRAM = true;
|
||||||
|
ps2->iface.clearTexture = true;
|
||||||
|
ps2->iface.updatedPalette = true;
|
||||||
}
|
}
|
||||||
ps2->menuVisible = enable;
|
ps2->menuVisible = enable;
|
||||||
ps2->fullscreen = fullscreen;
|
ps2->fullscreen = fullscreen;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user