Fix latency on pulseaudio backend

This commit is contained in:
Paul Dino Jones 2023-11-14 15:31:44 +00:00
parent b4f459a539
commit b3067e520d
2 changed files with 5 additions and 11 deletions

View File

@ -123,7 +123,7 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
// recommended settings, i.e. server uses sensible values // recommended settings, i.e. server uses sensible values
pa_buffer_attr buffer_attr; pa_buffer_attr buffer_attr;
buffer_attr.maxlength = (uint32_t) -1; buffer_attr.maxlength = (uint32_t) 32767;
buffer_attr.tlength = (uint32_t) -1; buffer_attr.tlength = (uint32_t) -1;
buffer_attr.prebuf = (uint32_t) -1; buffer_attr.prebuf = (uint32_t) -1;
buffer_attr.minreq = (uint32_t) -1; buffer_attr.minreq = (uint32_t) -1;
@ -131,22 +131,17 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
pa_cvolume cv; pa_cvolume cv;
uint16_t pvolume = ceil(((double) volume/100.0d)*65535); uint16_t pvolume = ceil(((double) volume/100.0d)*65535);
// Settings copied as per the chromium browser source // Settings copied as per the chromium browser source
pa_stream_flags_t stream_flags;
stream_flags = PA_STREAM_INTERPOLATE_TIMING |
PA_STREAM_NOT_MONOTONIC | PA_STREAM_AUTO_TIMING_UPDATE |
PA_STREAM_ADJUST_LATENCY;
//stream_flags = PA_STREAM_START_CORKED; pa_stream_flags_t stream_flags;
stream_flags = PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_NOT_MONOTONIC | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY | PA_STREAM_START_CORKED;
// Connect stream to the default audio output sink // Connect stream to the default audio output sink
pa_cvolume_set(&cv, sample_specifications.channels, pvolume); pa_cvolume_set(&cv, sample_specifications.channels, pvolume);
//pa_cvolume_set(&cv, 1, 0);
pa_cvolume_set_balance(&cv, &channel_map, pan); pa_cvolume_set_balance(&cv, &channel_map, pan);
assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0); assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0);
// Wait for the stream to be ready // Wait for the stream to be ready
for(;;) { for(;;) {
pa_stream_state_t stream_state = pa_stream_get_state(stream); pa_stream_state_t stream_state = pa_stream_get_state(stream);

View File

@ -203,10 +203,9 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
if( poll(&mypoll, 1, 1000.0/DEFAULT_UPDATE_RATE) ) if( poll(&mypoll, 1, 1000.0/update_rate) )
{ {
scanf("%c", &ch); scanf("%c", &ch);
if(ch == 'q') if(ch == 'q')