From: Steinar H. Gunderson Date: Sat, 30 Apr 2016 23:18:21 +0000 (+0200) Subject: When dropping ALSA audio, say how much (in ms) we dropped. X-Git-Tag: 1.3.0~45 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=b6dd6ef68b91fc8af13ff7173b7338f449cf923a When dropping ALSA audio, say how much (in ms) we dropped. --- diff --git a/alsa_output.cpp b/alsa_output.cpp index a3d17a2..d5ee35f 100644 --- a/alsa_output.cpp +++ b/alsa_output.cpp @@ -17,7 +17,7 @@ void die_on_error(const char *func_name, int err) } // namespace ALSAOutput::ALSAOutput(int sample_rate, int num_channels) - : num_channels(num_channels) + : sample_rate(sample_rate), num_channels(num_channels) { die_on_error("snd_pcm_open()", snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, 0)); @@ -79,7 +79,8 @@ try_again: if (ret == 0) { if (buffer.size() >= period_size * num_channels * 8) { // OK, almost 100 ms. Giving up. - fprintf(stderr, "warning: ALSA overrun, dropping some audio\n"); + fprintf(stderr, "warning: ALSA overrun, dropping some audio (%d ms)\n", + int(buffer.size() * 1000 / (num_channels * sample_rate))); buffer.clear(); } } else if (ret > 0) { diff --git a/alsa_output.h b/alsa_output.h index 12af16e..90223b7 100644 --- a/alsa_output.h +++ b/alsa_output.h @@ -21,7 +21,7 @@ private: snd_pcm_t *pcm_handle; std::vector buffer; snd_pcm_uframes_t period_size; - int num_channels; + int sample_rate, num_channels; }; #endif // !defined(_ALSA_OUTPUT_H)