To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / JackDevice / ContextJack.h @ 8:4c738d26de4f
History | View | Annotate | Download (5.23 KB)
| 1 |
/*
|
|---|---|
| 2 |
|
| 3 |
Copyright (C) 2016 Queen Mary University of London
|
| 4 |
Author: Fiore Martin
|
| 5 |
|
| 6 |
This file is part of Collidoscope.
|
| 7 |
|
| 8 |
Collidoscope is free software: you can redistribute it and/or modify
|
| 9 |
it under the terms of the GNU General Public License as published by
|
| 10 |
the Free Software Foundation, either version 3 of the License, or
|
| 11 |
(at your option) any later version.
|
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful,
|
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
GNU General Public License for more details.
|
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License
|
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 20 |
|
| 21 |
This file incorporates work covered by the following copyright and permission notice:
|
| 22 |
|
| 23 |
Copyright (c) 2014, The Cinder Project
|
| 24 |
|
| 25 |
This code is intended to be used with the Cinder C++ library, http://libcinder.org
|
| 26 |
|
| 27 |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
|
| 28 |
the following conditions are met:
|
| 29 |
|
| 30 |
* Redistributions of source code must retain the above copyright notice, this list of conditions and
|
| 31 |
the following disclaimer.
|
| 32 |
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
| 33 |
the following disclaimer in the documentation and/or other materials provided with the distribution.
|
| 34 |
|
| 35 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
| 36 |
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
| 37 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
| 38 |
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 39 |
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 40 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 41 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 42 |
POSSIBILITY OF SUCH DAMAGE.
|
| 43 |
|
| 44 |
*/
|
| 45 |
|
| 46 |
#pragma once
|
| 47 |
|
| 48 |
#include "cinder/audio/Context.h" |
| 49 |
#include <jack/jack.h> |
| 50 |
|
| 51 |
namespace cinder { namespace audio { namespace linux {
|
| 52 |
|
| 53 |
class ContextJack; |
| 54 |
class InputDeviceNodeJack; |
| 55 |
|
| 56 |
/**
|
| 57 |
* OutputNode (as in the cinder::audio::OutputNode) that sends audio to the sound card using the jack audio callback method.
|
| 58 |
*/
|
| 59 |
class OutputDeviceNodeJack : public OutputDeviceNode {
|
| 60 |
public:
|
| 61 |
OutputDeviceNodeJack( const DeviceRef &device, const Format &format, const std::shared_ptr<ContextJack> &context ); |
| 62 |
|
| 63 |
/** Gives this output node a reference to the JackInputNode.
|
| 64 |
* In initialize() the reference is used to give the input node access to jack input ports
|
| 65 |
*/
|
| 66 |
void setInput(InputDeviceNodeRef inputDeviceNode);
|
| 67 |
|
| 68 |
protected:
|
| 69 |
void initialize() override;
|
| 70 |
void uninitialize() override;
|
| 71 |
void enableProcessing() override;
|
| 72 |
void disableProcessing() override;
|
| 73 |
bool supportsProcessInPlace() const override { return false; } |
| 74 |
|
| 75 |
private:
|
| 76 |
// this is called by jack in the audio thread at every tick of the sound card
|
| 77 |
static int jackCallback(jack_nframes_t nframes, void* userData); |
| 78 |
|
| 79 |
|
| 80 |
void renderToBufferFromInputs();
|
| 81 |
|
| 82 |
/**
|
| 83 |
* RenderData is passed as user_data to jack when the jack process callback is installed
|
| 84 |
*/
|
| 85 |
struct RenderData{
|
| 86 |
RenderData() : inputNode(nullptr), outputNode(nullptr), context(nullptr){}
|
| 87 |
~RenderData() { inputNode = nullptr; outputNode = nullptr; context = nullptr; }
|
| 88 |
Node* outputNode; |
| 89 |
Node* inputNode; |
| 90 |
ContextJack* context; |
| 91 |
} mRenderData; |
| 92 |
|
| 93 |
std::weak_ptr<ContextJack> mCinderContext; |
| 94 |
|
| 95 |
jack_client_t *mClient; |
| 96 |
|
| 97 |
std::array< jack_port_t*, 2 > mOutputPorts;
|
| 98 |
|
| 99 |
std::shared_ptr<InputDeviceNodeJack> mInputDeviceNode; |
| 100 |
}; |
| 101 |
|
| 102 |
/**
|
| 103 |
* InputNode (as in the cinder::audio::OutputNode) that reads audio from the sound card using the jack audio callback method.
|
| 104 |
*/
|
| 105 |
class InputDeviceNodeJack : public InputDeviceNode {
|
| 106 |
friend OutputDeviceNodeJack; |
| 107 |
|
| 108 |
public:
|
| 109 |
InputDeviceNodeJack( const DeviceRef &device, const Format &format, const std::shared_ptr<ContextJack> &context ); |
| 110 |
|
| 111 |
protected:
|
| 112 |
void initialize() override;
|
| 113 |
void uninitialize() override;
|
| 114 |
void enableProcessing() override;
|
| 115 |
void disableProcessing() override;
|
| 116 |
void process( Buffer *buffer ) override;
|
| 117 |
|
| 118 |
private:
|
| 119 |
std::array< jack_port_t*, 2 > mInputPorts;
|
| 120 |
}; |
| 121 |
|
| 122 |
class ContextJack : public Context {
|
| 123 |
public:
|
| 124 |
ContextJack() {}
|
| 125 |
virtual ~ContextJack() {}
|
| 126 |
|
| 127 |
|
| 128 |
OutputDeviceNodeRef createOutputDeviceNode( const DeviceRef &device, const Node::Format &format = Node::Format() ) override; |
| 129 |
InputDeviceNodeRef createInputDeviceNode( const DeviceRef &device, const Node::Format &format = Node::Format() ) override; |
| 130 |
|
| 131 |
OutputDeviceNodeRef mOutputDeviceNode; |
| 132 |
InputDeviceNodeRef mInputDeviceNode; |
| 133 |
|
| 134 |
|
| 135 |
private:
|
| 136 |
}; |
| 137 |
|
| 138 |
} } } // namespace cinder::audio::linux
|
| 139 |
|