Skip to content

Commit

Permalink
(WASAPI) Buffer cleanups (#16057)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonninnos authored Dec 29, 2023
1 parent 285f800 commit aa1d47a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
34 changes: 24 additions & 10 deletions audio/drivers/wasapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static void *wasapi_init(const char *dev_id, unsigned rate, unsigned latency,
return NULL;
}

static bool wasapi_flush(wasapi_t * w, const void * data, size_t size)
static bool wasapi_flush(wasapi_t *w, const void *data, size_t size)
{
BYTE *dest = NULL;
UINT32 frame_count = size / w->frame_size;
Expand All @@ -173,7 +173,7 @@ static bool wasapi_flush(wasapi_t * w, const void * data, size_t size)
return true;
}

static bool wasapi_flush_buffer(wasapi_t * w, size_t size)
static bool wasapi_flush_buffer(wasapi_t *w, size_t size)
{
BYTE *dest = NULL;
UINT32 frame_count = size / w->frame_size;
Expand All @@ -191,7 +191,7 @@ static bool wasapi_flush_buffer(wasapi_t * w, size_t size)
return true;
}

static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void * data, size_t size)
static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void *data, size_t size)
{
ssize_t written = -1;
size_t write_avail = FIFO_WRITE_AVAIL(w->buffer);
Expand Down Expand Up @@ -222,7 +222,7 @@ static ssize_t wasapi_write_sh_buffer(wasapi_t *w, const void * data, size_t siz
return written;
}

static ssize_t wasapi_write_sh(wasapi_t *w, const void * data, size_t size)
static ssize_t wasapi_write_sh(wasapi_t *w, const void *data, size_t size)
{
ssize_t written = -1;
size_t write_avail = 0;
Expand All @@ -246,7 +246,7 @@ static ssize_t wasapi_write_sh(wasapi_t *w, const void * data, size_t size)
return written;
}

static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void * data, size_t size)
static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void *data, size_t size)
{
ssize_t written = -1;
size_t write_avail = 0;
Expand Down Expand Up @@ -291,7 +291,7 @@ static ssize_t wasapi_write_sh_nonblock(wasapi_t *w, const void * data, size_t s
return written;
}

static ssize_t wasapi_write_ex(wasapi_t *w, const void * data, size_t size, DWORD ms)
static ssize_t wasapi_write_ex(wasapi_t *w, const void *data, size_t size, DWORD ms)
{
ssize_t written = 0;
size_t write_avail = FIFO_WRITE_AVAIL(w->buffer);
Expand Down Expand Up @@ -395,10 +395,23 @@ static bool wasapi_alive(void *wh)
return w->running;
}

static void wasapi_insert_silence(wasapi_t *w)
{
int i;

for (i = 0; i < 12; i++)
audio_driver_menu_sample();
}

static void wasapi_set_nonblock_state(void *wh, bool nonblock)
{
wasapi_t *w = (wasapi_t*)wh;

/* Since exclusive mode keeps repeating last sample while
* in paused menu, generate some silence first. */
if (!nonblock && w->exclusive)
wasapi_insert_silence(w);

w->nonblock = nonblock;
}

Expand Down Expand Up @@ -447,20 +460,21 @@ static size_t wasapi_write_avail(void *wh)
wasapi_t *w = (wasapi_t*)wh;
UINT32 padding = 0;

if (w->buffer)
return FIFO_WRITE_AVAIL(w->buffer);

if (FAILED(_IAudioClient_GetCurrentPadding(w->client, &padding)))
return 0;

if (w->buffer)
/* Exaggarate available size for best results.. */
return FIFO_WRITE_AVAIL(w->buffer) + padding * 2;

return w->engine_buffer_size - padding * w->frame_size;
}

static size_t wasapi_buffer_size(void *wh)
{
wasapi_t *w = (wasapi_t*)wh;

if (!w->exclusive && w->buffer)
if (w->buffer)
return w->buffer->size;

return w->engine_buffer_size;
Expand Down
2 changes: 1 addition & 1 deletion runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -6015,7 +6015,7 @@ static enum runloop_state_enum runloop_check_state(
menu->state = 0;
}

if (!libretro_running)
if (settings->bools.audio_enable_menu && !libretro_running)
audio_driver_menu_sample();
}

Expand Down

0 comments on commit aa1d47a

Please sign in to comment.