mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-31 08:33:40 +00:00
Rate control for Pulse and Jack.
This commit is contained in:
parent
0b9ee6055f
commit
c833a71d2c
19
audio/jack.c
19
audio/jack.c
@ -41,6 +41,7 @@ typedef struct jack
|
||||
|
||||
pthread_cond_t cond;
|
||||
pthread_mutex_t cond_lock;
|
||||
size_t buffer_size;
|
||||
} jack_t;
|
||||
|
||||
static int process_cb(jack_nframes_t nframes, void *data)
|
||||
@ -163,6 +164,8 @@ static void *ja_init(const char *device, unsigned rate, unsigned latency)
|
||||
}
|
||||
|
||||
bufsize = find_buffersize(jd, latency);
|
||||
jd->buffer_size = bufsize;
|
||||
|
||||
SSNES_LOG("JACK: Internal buffer size: %d frames.\n", (int)(bufsize / sizeof(jack_default_audio_sample_t)));
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
@ -304,6 +307,18 @@ static bool ja_use_float(void *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t ja_write_avail(void *data)
|
||||
{
|
||||
jack_t *jd = (jack_t*)data;
|
||||
return jack_ringbuffer_write_space(jd->buffer[0]);
|
||||
}
|
||||
|
||||
static size_t ja_buffer_size(void *data)
|
||||
{
|
||||
jack_t *jd = (jack_t*)data;
|
||||
return jd->buffer_size;
|
||||
}
|
||||
|
||||
const audio_driver_t audio_jack = {
|
||||
ja_init,
|
||||
ja_write,
|
||||
@ -312,6 +327,8 @@ const audio_driver_t audio_jack = {
|
||||
ja_set_nonblock_state,
|
||||
ja_free,
|
||||
ja_use_float,
|
||||
"jack"
|
||||
"jack",
|
||||
ja_write_avail,
|
||||
ja_buffer_size,
|
||||
};
|
||||
|
||||
|
@ -30,6 +30,7 @@ typedef struct
|
||||
pa_context *context;
|
||||
pa_stream *stream;
|
||||
bool nonblock;
|
||||
size_t buffer_size;
|
||||
} pa_t;
|
||||
|
||||
static void pulse_free(void *data)
|
||||
@ -153,6 +154,8 @@ static void *pulse_init(const char *device, unsigned rate, unsigned latency)
|
||||
buffer_attr.minreq = -1;
|
||||
buffer_attr.fragsize = -1;
|
||||
|
||||
pa->buffer_size = buffer_attr.tlength;
|
||||
|
||||
if (pa_stream_connect_playback(pa->stream, NULL, &buffer_attr, PA_STREAM_ADJUST_LATENCY, NULL, NULL) < 0)
|
||||
goto error;
|
||||
|
||||
@ -177,8 +180,9 @@ static ssize_t pulse_write(void *data, const void *buf, size_t size)
|
||||
pa_t *pa = (pa_t*)data;
|
||||
|
||||
pa_threaded_mainloop_lock(pa->mainloop);
|
||||
unsigned length = pa_stream_writable_size(pa->stream);
|
||||
size_t length = pa_stream_writable_size(pa->stream);
|
||||
pa_threaded_mainloop_unlock(pa->mainloop);
|
||||
|
||||
while (length < size)
|
||||
{
|
||||
pa_threaded_mainloop_wait(pa->mainloop);
|
||||
@ -222,6 +226,21 @@ static bool pulse_use_float(void *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t pulse_write_avail(void *data)
|
||||
{
|
||||
pa_t *pa = (pa_t*)data;
|
||||
pa_threaded_mainloop_lock(pa->mainloop);
|
||||
size_t length = pa_stream_writable_size(pa->stream);
|
||||
pa_threaded_mainloop_unlock(pa->mainloop);
|
||||
return length;
|
||||
}
|
||||
|
||||
static size_t pulse_buffer_size(void *data)
|
||||
{
|
||||
pa_t *pa = (pa_t*)data;
|
||||
return pa->buffer_size;
|
||||
}
|
||||
|
||||
const audio_driver_t audio_pulse = {
|
||||
pulse_init,
|
||||
pulse_write,
|
||||
@ -230,6 +249,8 @@ const audio_driver_t audio_pulse = {
|
||||
pulse_set_nonblock_state,
|
||||
pulse_free,
|
||||
pulse_use_float,
|
||||
"pulse"
|
||||
"pulse",
|
||||
pulse_write_avail,
|
||||
pulse_buffer_size,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user