From 0cda8f963ce9da4338061ac87c8c029d62decf75 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Wed, 15 Aug 2018 15:57:41 +0100 Subject: [PATCH] Simplify some calculations and a bug so that the output calculation is correclty reset if there is a problem with output, e.g. an underflow. --- audio_alsa.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/audio_alsa.c b/audio_alsa.c index 0cfe4a72..ea6ab91f 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -882,6 +882,8 @@ int delay(long *the_delay) { debug(1, "Error %d in delay(): \"%s\". Delay reported is %d frames.", reply, snd_strerror(reply), *the_delay); snd_pcm_recover(alsa_handle, reply, 1); + frame_index = 0; + measurement_data_is_valid = 0; } } else { frame_index = 0; // we'll be starting over... @@ -980,20 +982,17 @@ static int play(void *buf, int samples) { long fl = 0; err2 = snd_pcm_delay(alsa_handle, &fl); if (err2 != 0) { - frame_index = 0; - measurement_data_is_valid = 0; debug(1, "Error %d in delay(): \"%s\". Delay reported is %d frames.", err2, snd_strerror(err2), fl); snd_pcm_recover(alsa_handle, err2, 1); + frame_index = 0; + measurement_data_is_valid = 0; } - uint64_t tf = get_absolute_time_in_fp(); + measurement_time = get_absolute_time_in_fp(); frames_played_at_measurement_time = frames_sent_for_playing - fl; if (frame_index == start_measurement_from_this_frame) { frames_played_at_measurement_start_time = frames_played_at_measurement_time; - measurement_start_time = tf; - } else { - frames_played_at_measurement_time = frames_played_at_measurement_time; - measurement_time = tf; + measurement_start_time = measurement_time; measurement_data_is_valid = 1; } }