diff options
Diffstat (limited to 'drumgizmo/output')
-rw-r--r-- | drumgizmo/output/alsa.cc | 54 | ||||
-rw-r--r-- | drumgizmo/output/jackaudio.cc | 21 | ||||
-rw-r--r-- | drumgizmo/output/jackaudio.h | 6 | ||||
-rw-r--r-- | drumgizmo/output/outputdummy.cc | 38 | ||||
-rw-r--r-- | drumgizmo/output/wavfile.cc | 50 |
5 files changed, 106 insertions, 63 deletions
diff --git a/drumgizmo/output/alsa.cc b/drumgizmo/output/alsa.cc index c577c72..8e6e4a9 100644 --- a/drumgizmo/output/alsa.cc +++ b/drumgizmo/output/alsa.cc @@ -35,11 +35,15 @@ struct AlsaInitError int const code; const std::string msg; - AlsaInitError(int op_code, const std::string &msg) : code{code}, msg{msg} {} + AlsaInitError(int op_code, const std::string& msg) + : code{code} + , msg{msg} + { + } - static inline void test(int code, const std::string &msg) + static inline void test(int code, const std::string& msg) { - if (code < 0) + if(code < 0) { throw AlsaInitError(code, msg); } @@ -61,7 +65,7 @@ AlsaOutputEngine::~AlsaOutputEngine() { // note: do NOT release `params`, it was allocated by `alloca()` - if (handle != nullptr) + if(handle != nullptr) { snd_pcm_close(handle); } @@ -72,10 +76,11 @@ bool AlsaOutputEngine::init(Channels channels) // try to initialize alsa try { - int value = snd_pcm_open(&handle, dev.c_str(), SND_PCM_STREAM_PLAYBACK, 0); + int value = + snd_pcm_open(&handle, dev.c_str(), SND_PCM_STREAM_PLAYBACK, 0); AlsaInitError::test(value, "snd_pcm_open"); num_channels = channels.size(); - if (handle == nullptr) + if(handle == nullptr) { std::cerr << "[AlsaOutputEngine] Failed to acquire " << "hardware handle\n"; @@ -86,21 +91,23 @@ bool AlsaOutputEngine::init(Channels channels) value = snd_pcm_hw_params_any(handle, params); AlsaInitError::test(value, "snd_pcm_hw_params_any"); - value = snd_pcm_hw_params_set_access(handle, params, - SND_PCM_ACCESS_RW_INTERLEAVED); + value = snd_pcm_hw_params_set_access( + handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); AlsaInitError::test(value, "snd_pcm_hw_params_set_access"); - value = snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_FLOAT); + value = + snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_FLOAT); AlsaInitError::test(value, "snd_pcm_hw_params_set_format"); value = snd_pcm_hw_params_set_channels(handle, params, num_channels); AlsaInitError::test(value, "snd_pcm_hw_params_set_channels"); value = snd_pcm_hw_params_set_rate_near(handle, params, &srate, 0); AlsaInitError::test(value, "snd_pcm_hw_params_set_rate_near"); - value = snd_pcm_hw_params_set_period_size_near(handle, params, &frames, 0); + value = + snd_pcm_hw_params_set_period_size_near(handle, params, &frames, 0); AlsaInitError::test(value, "snd_pcm_hw_params_set_period_size_near"); value = snd_pcm_hw_params(handle, params); AlsaInitError::test(value, "snd_pcm_hw_params"); } - catch (AlsaInitError const &error) + catch(AlsaInitError const& error) { std::cerr << "[AlsaOutputEngine] " << error.msg << " failed: " << snd_strerror(error.code) << std::endl; @@ -115,42 +122,45 @@ bool AlsaOutputEngine::init(Channels channels) void AlsaOutputEngine::setParm(std::string parm, std::string value) { - if (parm == "dev") + if(parm == "dev") { // apply hardware device name dev = value; } - else if (parm == "frames") + else if(parm == "frames") { // try to apply hardware buffer size try { frames = std::stoi(value); } - catch (...) + catch(...) { - std::cerr << "[AlsaOutputEngine] Invalid buffer size " << value << "\n"; + std::cerr << "[AlsaOutputEngine] Invalid buffer size " << value + << "\n"; } } - else if (parm == "srate") + else if(parm == "srate") { try { srate = std::stoi(value); } - catch (...) + catch(...) { - std::cerr << "[AlsaOutputEngine] Invalid samplerate " << value << "\n"; + std::cerr << "[AlsaOutputEngine] Invalid samplerate " << value + << "\n"; } } else { - std::cerr << "[AlsaOutputEngine] Unsupported parameter '" << parm << "'\n"; + std::cerr << "[AlsaOutputEngine] Unsupported parameter '" << parm + << "'\n"; } } bool AlsaOutputEngine::start() -{ +{ return true; } @@ -162,10 +172,10 @@ void AlsaOutputEngine::pre(size_t nsamples) { } -void AlsaOutputEngine::run(int ch, sample_t *samples, size_t nsamples) +void AlsaOutputEngine::run(int ch, sample_t* samples, size_t nsamples) { // Write channel data in interleaved buffer - for (auto i = 0u; i < nsamples; ++i) + for(auto i = 0u; i < nsamples; ++i) { data[i * num_channels + ch] = samples[i]; } diff --git a/drumgizmo/output/jackaudio.cc b/drumgizmo/output/jackaudio.cc index fd60a2a..53ea330 100644 --- a/drumgizmo/output/jackaudio.cc +++ b/drumgizmo/output/jackaudio.cc @@ -29,7 +29,7 @@ #include "jackaudio.h" -JackAudioOutputEngine::JackAudioOutputEngine(JackClient &client) +JackAudioOutputEngine::JackAudioOutputEngine(JackClient& client) : AudioOutputEngine{} , client(client) , channels{} @@ -50,13 +50,13 @@ bool JackAudioOutputEngine::init(Channels data) auto i = 0u; auto const buffer_size = getBufferSize(); - for (auto const &elem : data) + for(auto const& elem : data) { auto name = std::to_string(i) + "-" + elem.name; // initialize new channel channels.emplace_back(client, name, buffer_size); - if (channels.back().port.port == nullptr) + if(channels.back().port.port == nullptr) { std::cerr << "[JackAudioOutputEngine] Cannot create jack " << "port for channel #" << i << "\n"; @@ -85,9 +85,9 @@ void JackAudioOutputEngine::pre(size_t nsamples) { } -void JackAudioOutputEngine::run(int ch, sample_t *samples, size_t nsamples) +void JackAudioOutputEngine::run(int ch, sample_t* samples, size_t nsamples) { - for (auto i = 0u; i < nsamples; ++i) + for(auto i = 0u; i < nsamples; ++i) { channels[ch].samples[i] = samples[i]; } @@ -102,11 +102,10 @@ void JackAudioOutputEngine::process(jack_nframes_t num_frames) { assert(num_frames == getBufferSize()); - for (auto &channel : channels) + for(auto& channel : channels) { - auto ptr = static_cast<jack_default_audio_sample_t *>( - jack_port_get_buffer(channel.port.port, num_frames)); - for (auto i = 0u; i < num_frames; ++i) + auto ptr = static_cast<jack_default_audio_sample_t*>(jack_port_get_buffer(channel.port.port, num_frames)); + for(auto i = 0u; i < num_frames; ++i) { ptr[i] = channel.samples[i]; } @@ -124,8 +123,8 @@ size_t JackAudioOutputEngine::samplerate() return client.getSampleRate(); } -JackAudioOutputEngine::Channel::Channel(JackClient &client, - const std::string &name, +JackAudioOutputEngine::Channel::Channel(JackClient& client, + const std::string& name, std::size_t buffer_size) : port{client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput} , samples{} diff --git a/drumgizmo/output/jackaudio.h b/drumgizmo/output/jackaudio.h index e15dede..3408272 100644 --- a/drumgizmo/output/jackaudio.h +++ b/drumgizmo/output/jackaudio.h @@ -36,7 +36,7 @@ class JackAudioOutputEngine , public JackProcess { public: - JackAudioOutputEngine(JackClient &client); + JackAudioOutputEngine(JackClient& client); ~JackAudioOutputEngine(); // based on AudioOutputEngine @@ -59,8 +59,8 @@ private: JackPort port; std::vector<sample_t> samples; - Channel(JackClient& client, const std::string &name, - std::size_t buffer_size); + Channel(JackClient& client, const std::string& name, + std::size_t buffer_size); }; JackClient& client; diff --git a/drumgizmo/output/outputdummy.cc b/drumgizmo/output/outputdummy.cc index 3a3d6a0..2a01cd8 100644 --- a/drumgizmo/output/outputdummy.cc +++ b/drumgizmo/output/outputdummy.cc @@ -26,20 +26,40 @@ */ #include "outputdummy.h" -DummyOutputEngine::DummyOutputEngine() {} +DummyOutputEngine::DummyOutputEngine() +{ +} -DummyOutputEngine::~DummyOutputEngine() {} +DummyOutputEngine::~DummyOutputEngine() +{ +} -bool DummyOutputEngine::init(Channels data) { return true; } +bool DummyOutputEngine::init(Channels data) +{ + return true; +} -void DummyOutputEngine::setParm(std::string parm, std::string value) {} +void DummyOutputEngine::setParm(std::string parm, std::string value) +{ +} -bool DummyOutputEngine::start() { return true; } +bool DummyOutputEngine::start() +{ + return true; +} -void DummyOutputEngine::stop() {} +void DummyOutputEngine::stop() +{ +} -void DummyOutputEngine::pre(size_t nsamples) {} +void DummyOutputEngine::pre(size_t nsamples) +{ +} -void DummyOutputEngine::run(int ch, sample_t *samples, size_t nsamples) {} +void DummyOutputEngine::run(int ch, sample_t* samples, size_t nsamples) +{ +} -void DummyOutputEngine::post(size_t nsamples) {} +void DummyOutputEngine::post(size_t nsamples) +{ +} diff --git a/drumgizmo/output/wavfile.cc b/drumgizmo/output/wavfile.cc index faba69d..7035080 100644 --- a/drumgizmo/output/wavfile.cc +++ b/drumgizmo/output/wavfile.cc @@ -44,9 +44,9 @@ WavfileOutputEngine::WavfileOutputEngine() WavfileOutputEngine::~WavfileOutputEngine() { - for (auto &ptr : channels) + for(auto& ptr : channels) { - if (ptr != nullptr) + if(ptr != nullptr) { sf_close(ptr); } @@ -55,13 +55,14 @@ WavfileOutputEngine::~WavfileOutputEngine() bool WavfileOutputEngine::init(Channels data) { - channels.clear(), channels.resize(data.size()); // value-initialized with null - for (auto i = 0u; i < data.size(); ++i) + channels.clear(); + channels.resize(data.size()); // value-initialized with null + for(auto i = 0u; i < data.size(); ++i) { // write channel to file 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) + if(channels[i] == nullptr) { std::cerr << "[WaffileOutputEngine] Failed to initialize " << "channel #" << i << "\n"; @@ -73,21 +74,22 @@ bool WavfileOutputEngine::init(Channels data) void WavfileOutputEngine::setParm(std::string parm, std::string value) { - if (parm == "file") + if(parm == "file") { // apply output filename prefix file = value; } - else if (parm == "srate") + else if(parm == "srate") { // try to apply samplerate try { info.samplerate = std::stoi(value); } - catch (...) + catch(...) { - std::cerr << "[WavfileOutputEngine] Invalid samplerate " << value << "\n"; + std::cerr << "[WavfileOutputEngine] Invalid samplerate " << value + << "\n"; } } else @@ -97,24 +99,36 @@ void WavfileOutputEngine::setParm(std::string parm, std::string value) } } -bool WavfileOutputEngine::start() { return true; } +bool WavfileOutputEngine::start() +{ + return true; +} -void WavfileOutputEngine::stop() {} +void WavfileOutputEngine::stop() +{ +} -void WavfileOutputEngine::pre(size_t nsamples) {} +void WavfileOutputEngine::pre(size_t nsamples) +{ +} -void WavfileOutputEngine::run(int ch, sample_t *samples, size_t nsamples) +void WavfileOutputEngine::run(int ch, sample_t* samples, size_t nsamples) { - if (static_cast<unsigned int>(ch) >= channels.size()) + if(static_cast<unsigned int>(ch) >= channels.size()) { - std::cerr << "[WavfileOutputEngine] cannot access channel #" << ch << " (" - << channels.size() << " channels available)\n"; + std::cerr << "[WavfileOutputEngine] cannot access channel #" << ch + << " (" << channels.size() << " channels available)\n"; return; } sf_writef_float(channels[ch], samples, nsamples); } -void WavfileOutputEngine::post(size_t nsamples) {} +void WavfileOutputEngine::post(size_t nsamples) +{ +} -size_t WavfileOutputEngine::samplerate() { return info.samplerate; } +size_t WavfileOutputEngine::samplerate() +{ + return info.samplerate; +} |