From 41b6ef4642b25c22e47e5f89f113b502d3a4321c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Mon, 25 Jan 2016 12:32:09 +0100 Subject: added JackMidiInputEngine + additional minor changes --- drumgizmo/output/jackaudio.cc | 35 +++++++++++++++++++++-------------- drumgizmo/output/jackaudio.h | 15 +++++++++++---- 2 files changed, 32 insertions(+), 18 deletions(-) (limited to 'drumgizmo/output') diff --git a/drumgizmo/output/jackaudio.cc b/drumgizmo/output/jackaudio.cc index 07ae4b5..634b7d1 100644 --- a/drumgizmo/output/jackaudio.cc +++ b/drumgizmo/output/jackaudio.cc @@ -29,17 +29,18 @@ #include "jackaudio.h" -JackaudioOutputEngine::JackaudioOutputEngine(JackClient& client) +JackAudioOutputEngine::JackAudioOutputEngine(JackClient& client) : client(client) // wanna use initializer braces here but jenkins fails , channels{} , sema{"jackaudio"} { client.add(*this); } -JackaudioOutputEngine::~JackaudioOutputEngine() { +JackAudioOutputEngine::~JackAudioOutputEngine() { + client.remove(*this); } -bool JackaudioOutputEngine::init(Channels data) { +bool JackAudioOutputEngine::init(Channels data) { channels.clear(); channels.reserve(data.size()); auto i = 0u; @@ -48,10 +49,10 @@ bool JackaudioOutputEngine::init(Channels data) { for (auto const & elem: data) { auto name = std::to_string(i) + "-" + elem.name; // initialize new channel - channels.emplace_back(client, buffer_size, name); + channels.emplace_back(client, name, buffer_size); if (channels.back().port == nullptr) { - std::cerr << "[JackaudioOutputEngine] Cannot create jack " + std::cerr << "[JackAudioOutputEngine] Cannot create jack " << "port for channel #" << i << "\n"; return false; } @@ -60,31 +61,31 @@ bool JackaudioOutputEngine::init(Channels data) { return true; } -void JackaudioOutputEngine::setParm(std::string parm, std::string value) { +void JackAudioOutputEngine::setParm(std::string parm, std::string value) { } -bool JackaudioOutputEngine::start() { +bool JackAudioOutputEngine::start() { client.activate(); return true; } -void JackaudioOutputEngine::stop() { +void JackAudioOutputEngine::stop() { } -void JackaudioOutputEngine::pre(size_t nsamples) { +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) { channels[ch].samples[i] = samples[i]; } } -void JackaudioOutputEngine::post(size_t nsamples) { +void JackAudioOutputEngine::post(size_t nsamples) { sema.wait(); } -void JackaudioOutputEngine::process(jack_nframes_t num_frames) { +void JackAudioOutputEngine::process(jack_nframes_t num_frames) { assert(num_frames == getBufferSize()); for (auto& channel: channels) { @@ -97,10 +98,16 @@ void JackaudioOutputEngine::process(jack_nframes_t num_frames) { sema.post(); } -size_t JackaudioOutputEngine::getBufferSize() { +size_t JackAudioOutputEngine::getBufferSize() { return client.getBufferSize(); } -size_t JackaudioOutputEngine::samplerate() { +size_t JackAudioOutputEngine::samplerate() { return client.getSampleRate(); } + +JackAudioOutputEngine::Channel::Channel(JackClient& client, std::string const & name, std::size_t buffer_size) + : port{client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0} + , samples{} { + samples.resize(buffer_size); +} diff --git a/drumgizmo/output/jackaudio.h b/drumgizmo/output/jackaudio.h index 13ed75f..12539c5 100644 --- a/drumgizmo/output/jackaudio.h +++ b/drumgizmo/output/jackaudio.h @@ -31,12 +31,12 @@ #include "audiooutputengine.h" #include "../jackclient.h" -class JackaudioOutputEngine +class JackAudioOutputEngine : public AudioOutputEngine , public JackProcess { public: - JackaudioOutputEngine(JackClient& client); - ~JackaudioOutputEngine(); + JackAudioOutputEngine(JackClient& client); + ~JackAudioOutputEngine(); // based on AudioOutputEngine bool init(Channels chan) override; @@ -53,7 +53,14 @@ class JackaudioOutputEngine void process(jack_nframes_t num_frames) override; private: + struct Channel { + JackPort port; + std::vector samples; + + Channel(JackClient& client, std::string const & name, std::size_t buffer_size); + }; + JackClient& client; - std::vector channels; + std::vector channels; Semaphore sema; }; -- cgit v1.2.3