From 06d43e27c412083cf704af48ea40e5c589504240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Fri, 22 Jan 2016 09:39:50 +0100 Subject: stdcerr output overhaul --- drumgizmo/output/alsa.cc | 31 +++++++++++++++++++++++++------ drumgizmo/output/wavfile.cc | 22 ++++++++++++++++++---- 2 files changed, 43 insertions(+), 10 deletions(-) (limited to 'drumgizmo/output') diff --git a/drumgizmo/output/alsa.cc b/drumgizmo/output/alsa.cc index f1a6806..14a9c6d 100644 --- a/drumgizmo/output/alsa.cc +++ b/drumgizmo/output/alsa.cc @@ -24,6 +24,8 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include + #include "alsa.h" int const BUFFER_SIZE = 40960; @@ -55,7 +57,7 @@ AlsaOutputEngine::AlsaOutputEngine() } AlsaOutputEngine::~AlsaOutputEngine() { - // note: cannot release `params` (seg fault but why?) + // note: do NOT release `params`, it was allocated by `alloca()` if (handle != nullptr) { snd_pcm_close(handle); @@ -69,7 +71,8 @@ bool AlsaOutputEngine::init(Channels channels) { AlsaInitError::test(value, "snd_pcm_open"); num_channels = channels.size(); if (handle == nullptr) { - printf("No handle!\n"); + std::cerr << "[AlsaOutputEngine] Failed to acquire " + << "hardware handle\n"; return false; } // Allocate and init a hardware parameters object @@ -91,8 +94,8 @@ bool AlsaOutputEngine::init(Channels channels) { AlsaInitError::test(value, "snd_pcm_hw_params"); } catch (AlsaInitError const & error) { - printf("%s failed: %s\n", error.msg.c_str(), snd_strerror(error.code)); - fflush(stdout); + std::cerr << "[AlsaOutputEngine] " << error.msg << " failed: " + << snd_strerror(error.code) << std::endl; return false; } @@ -104,11 +107,27 @@ bool AlsaOutputEngine::init(Channels channels) { void AlsaOutputEngine::setParm(std::string parm, std::string value) { if (parm == "dev") { + // apply hardware device name dev = value; + } else if (parm == "frames") { - frames = std::stoi(value); + // try to apply hardware buffer size + try { + frames = std::stoi(value); + } catch (...) { + std::cerr << "[AlsaOutputEngine] Invalid buffer size " + << value << "\n"; + } } else if (parm == "srate") { - srate = std::stoi(value); + try { + srate = std::stoi(value); + } catch (...) { + std::cerr << "[AlsaOutputEngine] Invalid samplerate " + << value << "\n"; + } + } else { + std::cerr << "[AlsaOutputEngine] Unsupported parameter '" + << parm << "'\n"; } } diff --git a/drumgizmo/output/wavfile.cc b/drumgizmo/output/wavfile.cc index ae8b3f1..d8b8d99 100644 --- a/drumgizmo/output/wavfile.cc +++ b/drumgizmo/output/wavfile.cc @@ -24,6 +24,8 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include + #include "wavfile.h" WavfileOutputEngine::WavfileOutputEngine() @@ -54,7 +56,8 @@ bool WavfileOutputEngine::init(Channels data) { auto fname = file + data[i].name + "-" + std::to_string(i) + ".wav"; channels[i] = sf_open(fname.c_str(), SFM_WRITE, &info); if (channels[i] == nullptr) { - printf("Write error...\n"); + std::cerr << "[WaffileOutputEngine] Failed to initialize " + << "channel #" << i << "\n"; return false; } } @@ -63,11 +66,21 @@ bool WavfileOutputEngine::init(Channels data) { void WavfileOutputEngine::setParm(std::string parm, std::string value) { if (parm == "file") { + // apply output filename prefix file = value; + } else if (parm == "srate") { - info.samplerate = std::stoi(value); + // try to apply samplerate + try { + info.samplerate = std::stoi(value); + } catch (...) { + std::cerr << "[WavfileOutputEngine] Invalid samplerate " + << value << "\n"; + } + } else { - printf("Unsupported wavfile parameter '%s'\n", parm.c_str()); + std::cerr << "[WavfileOutputEngine] Unsupported parameter '" + << parm << "'\n"; } } @@ -83,7 +96,8 @@ void WavfileOutputEngine::pre(size_t nsamples) { void WavfileOutputEngine::run(int ch, sample_t* samples, size_t nsamples) { if (static_cast(ch) >= channels.size()) { - printf("Invalid channel %d (%d channels available)", ch, static_cast(channels.size())); + std::cerr << "[WavfileOutputEngine] cannot access channel #" + << ch << " (" << channels.size() << " channels available)\n"; return; } -- cgit v1.2.3