From 6507b869730be99db941bcf70394633b27edd5a4 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 20 Feb 2019 23:45:30 +0100 Subject: [PATCH 1/3] Fix freeze audio after restart core --- audio/drivers/ps2_audio.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/audio/drivers/ps2_audio.c b/audio/drivers/ps2_audio.c index 1fca4b2916..8c1f49dd8c 100644 --- a/audio/drivers/ps2_audio.c +++ b/audio/drivers/ps2_audio.c @@ -27,7 +27,8 @@ typedef struct ps2_audio { fifo_buffer_t* buffer; bool nonblocking; - volatile bool running; + bool running; + bool audio_stopped; int worker_thread; int lock; int cond_lock; @@ -49,20 +50,24 @@ static void audioMainLoop(void *data) ps2_audio_t* ps2 = backup_ps2; while (ps2->running) - { - size_t size; + { + if (ps2->audio_stopped) { + audsrv_stop_audio(); + } else { + 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); - 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_wait_audio(size); + audsrv_play_audio(out_tmp, size); + } } audsrv_stop_audio(); + ps2->worker_thread = 0; ExitDeleteThread(); } @@ -175,7 +180,10 @@ static void ps2_audio_free(void *data) } } + + audsrv_stop_audio(); fifo_free(ps2->buffer); + backup_ps2 = NULL; free(ps2); } @@ -220,7 +228,7 @@ static bool ps2_audio_stop(void *data) if (ps2) { - audioStopNDeleteThread(ps2); + ps2->audio_stopped = true; audsrv_stop_audio(); } @@ -236,6 +244,8 @@ static bool ps2_audio_start(void *data, bool is_shutdown) { if (!ps2->running && !ps2->worker_thread) audioCreateThread(ps2); + + ps2->audio_stopped = false; } return start; From cf68058e674aee848dfc72da44283c4a4f4fde90 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 21 Feb 2019 00:38:56 +0100 Subject: [PATCH 2/3] Fix issues with the GSFont --- gfx/drivers/ps2_gfx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 0fbb1db5db..99c1f58305 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -182,7 +182,6 @@ static void clearVRAMIfNeeded(ps2_video_t *ps2, void *frame, int width, int heig } if (ps2->clearVRAM) { - gsKit_clear(ps2->gsGlobal, GS_BLACK); gsKit_vram_clear(ps2->gsGlobal); } } @@ -266,6 +265,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, #endif clearVRAMIfNeeded(ps2, frame, width, height); + gsKit_clear(ps2->gsGlobal, GS_BLACK); if (frame) { bool sendPalette = false; @@ -277,7 +277,6 @@ static bool ps2_gfx_frame(void *data, const void *frame, ps2->iface.updatedPalette = false; padding = ps2->iface.padding; if (ps2->iface.clearTexture) { - gsKit_clear(ps2->gsGlobal, GS_BLACK); ps2->iface.clearTexture = false; } } @@ -434,6 +433,8 @@ static void ps2_set_texture_enable(void *data, bool enable, bool fullscreen) if (ps2->menuVisible != enable) { /* If Menu change status, CLEAR VRAM */ ps2->clearVRAM = true; + ps2->iface.clearTexture = true; + ps2->iface.updatedPalette = true; } ps2->menuVisible = enable; ps2->fullscreen = fullscreen; From 7ec160f860fd412b640d39c889daaa10ea5cbbc5 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Fri, 22 Feb 2019 00:01:36 +0100 Subject: [PATCH 3/3] Remove the specific audio thread --- audio/drivers/ps2_audio.c | 138 +++----------------------------------- gfx/drivers/ps2_gfx.c | 1 + 2 files changed, 11 insertions(+), 128 deletions(-) diff --git a/audio/drivers/ps2_audio.c b/audio/drivers/ps2_audio.c index 8c1f49dd8c..8345a8a0d4 100644 --- a/audio/drivers/ps2_audio.c +++ b/audio/drivers/ps2_audio.c @@ -23,89 +23,18 @@ #include "../audio_driver.h" +#define AUDIO_BUFFER 64 * 1024 +#define AUDIO_CHANNELS 2 +#define AUDIO_BITS 16 + typedef struct ps2_audio { fifo_buffer_t* buffer; bool nonblocking; bool running; - bool audio_stopped; - int worker_thread; - int lock; - int cond_lock; } 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) - { - if (ps2->audio_stopped) { - audsrv_stop_audio(); - } else { - 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(); - ps2->worker_thread = 0; - 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) { int err; @@ -125,23 +54,6 @@ static void audioConfigure(ps2_audio_t *ps2, unsigned rate) 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, unsigned rate, unsigned latency, unsigned block_frames, @@ -152,10 +64,7 @@ static void *ps2_audio_init(const char *device, if (!ps2) return NULL; - ps2->buffer = fifo_new(AUDIO_BUFFER); audioConfigure(ps2, rate); - audioCreateSemas(ps2); - audioCreateThread(ps2); return ps2; } @@ -166,24 +75,8 @@ static void ps2_audio_free(void *data) if(!ps2) return; - if(ps2->running){ - audioStopNDeleteThread(ps2); - - if (ps2->lock){ - iDeleteSema(ps2->lock); - ps2->lock = 0; - } - - if (ps2->cond_lock){ - iDeleteSema(ps2->cond_lock); - ps2->cond_lock = 0; - } - - } - + ps2->running = false; audsrv_stop_audio(); - fifo_free(ps2->buffer); - backup_ps2 = NULL; free(ps2); } @@ -200,12 +93,8 @@ static ssize_t ps2_audio_write(void *data, const void *buf, size_t size) return 0; } - while (fifo_write_avail(ps2->buffer) < size) - WaitSema(ps2->cond_lock); - - WaitSema(ps2->lock); - fifo_write(ps2->buffer, buf, size); - iSignalSema(ps2->lock); + audsrv_wait_audio(size); + audsrv_play_audio(buf, size); return size; } @@ -228,8 +117,8 @@ static bool ps2_audio_stop(void *data) if (ps2) { - ps2->audio_stopped = true; audsrv_stop_audio(); + ps2->running = false; } return stop; @@ -242,10 +131,7 @@ static bool ps2_audio_start(void *data, bool is_shutdown) if (ps2) { - if (!ps2->running && !ps2->worker_thread) - audioCreateThread(ps2); - - ps2->audio_stopped = false; + ps2->running = true; } return start; @@ -270,11 +156,7 @@ static size_t ps2_audio_write_avail(void *data) if (ps2 && ps2->running) { - size_t size; - WaitSema(ps2->lock); - size = AUDIO_BUFFER - fifo_read_avail(ps2->buffer); - iSignalSema(ps2->lock); - return size; + return AUDIO_BUFFER; } return 0; diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 99c1f58305..6eae3f35e2 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -183,6 +183,7 @@ static void clearVRAMIfNeeded(ps2_video_t *ps2, void *frame, int width, int heig if (ps2->clearVRAM) { gsKit_vram_clear(ps2->gsGlobal); + ps2->iface.updatedPalette = true; } }