diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-04-14 00:53:15 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-04-14 00:53:15 +0200 |
commit | b554628099c72c0e78e34d04e029695c407be541 (patch) | |
tree | b64e9fa7cc34df30bfed86a38765f39ca58f6703 /src/sound.cpp | |
parent | 2692a7d22c0b691f7f27f969c91e7af05c8ede7d (diff) |
Revert "Testing audio latency compensation"
This reverts commit 2692a7d22c0b691f7f27f969c91e7af05c8ede7d.
Diffstat (limited to 'src/sound.cpp')
-rw-r--r-- | src/sound.cpp | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/sound.cpp b/src/sound.cpp index 8be32b2..485548b 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -41,7 +41,6 @@ struct pa_handle { size_t output_index, output_length; int operation_success; - double latency_seconds; }; static void pa_sound_device_free(pa_handle *s) { @@ -80,9 +79,8 @@ static pa_handle* pa_sound_device_new(const char *server, p->read_data = NULL; p->read_length = 0; p->read_index = 0; - p->latency_seconds = 0.0; - const int buffer_size = attr->fragsize; + const int buffer_size = attr->maxlength; void *buffer = malloc(buffer_size); if(!buffer) { fprintf(stderr, "failed to allocate buffer for audio\n"); @@ -163,9 +161,6 @@ static int pa_sound_device_read(pa_handle *p, double timeout_seconds) { bool success = false; int r = 0; int *rerror = &r; - pa_usec_t latency = 0; - int negative = 0; - CHECK_DEAD_GOTO(p, rerror, fail); while (p->output_index < p->output_length) { @@ -198,10 +193,6 @@ static int pa_sound_device_read(pa_handle *p, double timeout_seconds) { CHECK_DEAD_GOTO(p, rerror, fail); continue; } - - if(pa_stream_get_latency(p->stream, &latency, &negative) >= 0) { - p->latency_seconds = (negative ? -(int64_t)latency : (int64_t)latency) * 0.000001; - } } const size_t space_free_in_output_buffer = p->output_length - p->output_index; @@ -264,8 +255,8 @@ int sound_device_get_by_name(SoundDevice *device, const char *device_name, const buffer_attr.tlength = -1; buffer_attr.prebuf = -1; buffer_attr.minreq = -1; - buffer_attr.maxlength = -1; - buffer_attr.fragsize = period_frame_size * audio_format_to_get_bytes_per_sample(audio_format) * num_channels; // 2/4 bytes/sample, @num_channels channels + buffer_attr.maxlength = period_frame_size * audio_format_to_get_bytes_per_sample(audio_format) * num_channels; // 2/4 bytes/sample, @num_channels channels + buffer_attr.fragsize = buffer_attr.maxlength; int error = 0; pa_handle *handle = pa_sound_device_new(nullptr, description, device_name, description, &ss, &buffer_attr, &error); @@ -285,15 +276,13 @@ void sound_device_close(SoundDevice *device) { device->handle = NULL; } -int sound_device_read_next_chunk(SoundDevice *device, void **buffer, double timeout_sec, double *latency_sec) { +int sound_device_read_next_chunk(SoundDevice *device, void **buffer, double timeout_sec) { pa_handle *pa = (pa_handle*)device->handle; if(pa_sound_device_read(pa, timeout_sec) < 0) { //fprintf(stderr, "pa_simple_read() failed: %s\n", pa_strerror(error)); - *latency_sec = 0.0; return -1; } *buffer = pa->output_data; - *latency_sec = pa->latency_seconds; return device->frames; } |