summaryrefslogtreecommitdiffhomepage
path: root/PCM.h
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-03 17:31:21 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-03 17:31:21 +0100
commit7d98b5d410233fd9608ed5682f5a98b283f83d12 (patch)
tree8e3f24c126ffc4494a8b07ba48906e0ed97bc409 /PCM.h
parent9de0b7f8937b7f6ce990132609f0b26851b31f2b (diff)
Diagnostics
Diffstat (limited to 'PCM.h')
-rw-r--r--PCM.h11
1 files changed, 6 insertions, 5 deletions
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 <alsa/asoundlib.h>
+#include <fmt/format.h>
#include <iostream>
#include <string>
@@ -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);