diff options
author | Roland Reichwein <mail@reichwein.it> | 2025-01-03 18:48:57 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2025-01-03 18:48:57 +0100 |
commit | 81ef3f08215a62d469c49762ccd492cb806150c4 (patch) | |
tree | 8327302643b820939b2427a4cb0774f01d0a8259 /PCM.h | |
parent | 1f1e71e0d9e1a60eac38040ea5e6a49c14d81b71 (diff) |
Cleanup
Diffstat (limited to 'PCM.h')
-rw-r--r-- | PCM.h | 44 |
1 files changed, 22 insertions, 22 deletions
@@ -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() |