summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--PCM.h44
-rw-r--r--UI.cpp1
2 files changed, 23 insertions, 22 deletions
diff --git a/PCM.h b/PCM.h
index 2c338f3..bfa1e24 100644
--- a/PCM.h
+++ b/PCM.h
@@ -19,16 +19,16 @@ public:
{
// non-blocking
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0) {
- throw std::runtime_error(fmt::format("Playback open error: {}", snd_strerror(err)));
+ throw std::runtime_error(fmt::format("Playback open error: {}", snd_strerror(err)));
}
if ((err = snd_pcm_set_params(handle,
- SND_PCM_FORMAT_S16_LE,
- SND_PCM_ACCESS_RW_INTERLEAVED,
- 1,
- f_sample,
- 1,
- 100000)) < 0) { // latency in us
- throw std::runtime_error(fmt::format("Playback open error: {}", snd_strerror(err)));
+ SND_PCM_FORMAT_S16_LE,
+ SND_PCM_ACCESS_RW_INTERLEAVED,
+ 1,
+ f_sample,
+ 1,
+ 100000)) < 0) { // latency in us
+ throw std::runtime_error(fmt::format("Playback open error: {}", snd_strerror(err)));
}
m_stream.generate();
@@ -77,23 +77,23 @@ public:
// write from buffer to ALSA PCM
void write()
{
- snd_pcm_sframes_t written = snd_pcm_writei(handle, m_stream.get_buffer(), nframes);
- if (written < 0) {
- if (written == -EPIPE) {
- std::cout << "Warning: PCM underrun" << std::endl;
- }
- std::cout << "Recovering." << std::endl;
- written = snd_pcm_recover(handle, written, 0);
- }
- if (written < 0) {
- throw std::runtime_error("snd_pcm_writei failed: "s + snd_strerror(written));
+ snd_pcm_sframes_t written = snd_pcm_writei(handle, m_stream.get_buffer(), nframes);
+ if (written < 0) {
+ if (written == -EPIPE) {
+ std::cout << "Warning: PCM underrun" << std::endl;
}
+ std::cout << "Recovering." << std::endl;
+ written = snd_pcm_recover(handle, written, 0);
+ }
+ if (written < 0) {
+ throw std::runtime_error("snd_pcm_writei failed: "s + snd_strerror(written));
+ }
- if (written != nframes) {
- std::cout << "Warning: written " << std::to_string(written) << " frames instead of "<< std::to_string(nframes) << std::endl;
- }
+ if (written != nframes) {
+ std::cout << "Warning: written " << std::to_string(written) << " frames instead of "<< std::to_string(nframes) << std::endl;
+ }
- m_stream.generate();
+ m_stream.generate();
}
bool wait_for_event()
diff --git a/UI.cpp b/UI.cpp
index 57c79ec..8baf4db 100644
--- a/UI.cpp
+++ b/UI.cpp
@@ -1,6 +1,7 @@
#include "UI.h"
#include "cpuload.h"
+#include "debug.h"
#include "log.h"
#include <algorithm>