From 7d98b5d410233fd9608ed5682f5a98b283f83d12 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 3 Jan 2025 17:31:21 +0100 Subject: Diagnostics --- PCM.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'PCM.h') diff --git a/PCM.h b/PCM.h index c9d7f7f..2c338f3 100644 --- a/PCM.h +++ b/PCM.h @@ -5,6 +5,7 @@ #include "config.h" #include +#include #include #include @@ -18,8 +19,7 @@ public: { // non-blocking if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0) { - printf("Playback open error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); + throw std::runtime_error(fmt::format("Playback open error: {}", snd_strerror(err))); } if ((err = snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE, @@ -28,8 +28,7 @@ public: f_sample, 1, 100000)) < 0) { // latency in us - printf("Playback open error: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); + throw std::runtime_error(fmt::format("Playback open error: {}", snd_strerror(err))); } m_stream.generate(); @@ -54,6 +53,8 @@ public: if (npfd != 1) { std::cout << "Warning: " << std::to_string(npfd) << " poll fds for pcm" << std::endl; + } else if (fd() <= 2) { + std::cout << "Warning: Bad PCM fd: " << std::to_string(fd()) << std::endl; } } @@ -62,7 +63,7 @@ public: // pass the remaining samples, otherwise they're dropped in close err = snd_pcm_drain(handle); if (err < 0) - printf("snd_pcm_drain failed: %s\n", snd_strerror(err)); + std::cerr << fmt::format("snd_pcm_drain failed: {}", snd_strerror(err)) << std::endl; snd_pcm_close(handle); free(pfd); -- cgit v1.2.3