diff options
author | Christian Glöckner <cgloeckner@freenet.de> | 2016-01-25 12:32:09 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-02-09 09:03:16 +0100 |
commit | 41b6ef4642b25c22e47e5f89f113b502d3a4321c (patch) | |
tree | 2aac4d7d2fe822506d7ce902f81d3c7dc52e0171 /drumgizmo/output | |
parent | 7236fee052f52667f116ed83cacb21ed587d0d65 (diff) |
added JackMidiInputEngine + additional minor changes
Diffstat (limited to 'drumgizmo/output')
-rw-r--r-- | drumgizmo/output/jackaudio.cc | 35 | ||||
-rw-r--r-- | drumgizmo/output/jackaudio.h | 15 |
2 files changed, 32 insertions, 18 deletions
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<sample_t> samples; + + Channel(JackClient& client, std::string const & name, std::size_t buffer_size); + }; + JackClient& client; - std::vector<JackChannel> channels; + std::vector<Channel> channels; Semaphore sema; }; |