Remove the specific audio thread
This commit is contained in:
parent
cf68058e67
commit
7ec160f860
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue