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 @ 4:ab6db404403a
History | View | Annotate | Download (4.23 KB)
| 1 | 1:b5bcad8e7803 | f | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2015, The Cinder Project
|
||
| 3 | |||
| 4 | This code is intended to be used with the Cinder C++ library, http://libcinder.org
|
||
| 5 | |||
| 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that
|
||
| 7 | the following conditions are met:
|
||
| 8 | |||
| 9 | * Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||
| 10 | the following disclaimer.
|
||
| 11 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||
| 12 | the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||
| 13 | |||
| 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||
| 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||
| 16 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||
| 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||
| 18 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
| 19 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||
| 20 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||
| 21 | POSSIBILITY OF SUCH DAMAGE.
|
||
| 22 | */
|
||
| 23 | |||
| 24 | #pragma once
|
||
| 25 | |||
| 26 | #include "cinder/audio/Context.h" |
||
| 27 | #include <jack/jack.h> |
||
| 28 | |||
| 29 | namespace cinder { namespace audio { namespace linux {
|
||
| 30 | |||
| 31 | class ContextJack; |
||
| 32 | class InputDeviceNodeJack; |
||
| 33 | |||
| 34 | 4:ab6db404403a | f | /**
|
| 35 | * OutputNode (as in the cinder::audio::OutputNode) that sends audio to the sound card using the jack audio callback method.
|
||
| 36 | */
|
||
| 37 | 1:b5bcad8e7803 | f | class OutputDeviceNodeJack : public OutputDeviceNode {
|
| 38 | public:
|
||
| 39 | OutputDeviceNodeJack( const DeviceRef &device, const Format &format, const std::shared_ptr<ContextJack> &context ); |
||
| 40 | |||
| 41 | 4:ab6db404403a | f | /** Gives this output node a reference to the JackInputNode.
|
| 42 | * In initialize() the reference is used to give the input node access to jack input ports
|
||
| 43 | */
|
||
| 44 | 1:b5bcad8e7803 | f | void setInput(InputDeviceNodeRef inputDeviceNode);
|
| 45 | |||
| 46 | protected:
|
||
| 47 | void initialize() override;
|
||
| 48 | void uninitialize() override;
|
||
| 49 | void enableProcessing() override;
|
||
| 50 | void disableProcessing() override;
|
||
| 51 | bool supportsProcessInPlace() const override { return false; } |
||
| 52 | |||
| 53 | private:
|
||
| 54 | 4:ab6db404403a | f | // this is called by jack in the audio thread at every tick of the sound card
|
| 55 | 1:b5bcad8e7803 | f | static int jackCallback(jack_nframes_t nframes, void* userData); |
| 56 | |||
| 57 | |||
| 58 | void renderToBufferFromInputs();
|
||
| 59 | |||
| 60 | 4:ab6db404403a | f | /**
|
| 61 | * RenderData is passed as user_data to jack when the jack process callback is installed
|
||
| 62 | */
|
||
| 63 | 1:b5bcad8e7803 | f | struct RenderData{
|
| 64 | RenderData() : inputNode(nullptr), outputNode(nullptr), context(nullptr){}
|
||
| 65 | ~RenderData() { inputNode = nullptr; outputNode = nullptr; context = nullptr; }
|
||
| 66 | Node* outputNode; |
||
| 67 | Node* inputNode; |
||
| 68 | ContextJack* context; |
||
| 69 | } mRenderData; |
||
| 70 | |||
| 71 | std::weak_ptr<ContextJack> mCinderContext; |
||
| 72 | |||
| 73 | jack_client_t *mClient; |
||
| 74 | |||
| 75 | std::array< jack_port_t*, 2 > mOutputPorts;
|
||
| 76 | |||
| 77 | std::shared_ptr<InputDeviceNodeJack> mInputDeviceNode; |
||
| 78 | }; |
||
| 79 | |||
| 80 | 4:ab6db404403a | f | /**
|
| 81 | * InputNode (as in the cinder::audio::OutputNode) that reads audio from the sound card using the jack audio callback method.
|
||
| 82 | */
|
||
| 83 | 1:b5bcad8e7803 | f | class InputDeviceNodeJack : public InputDeviceNode {
|
| 84 | friend OutputDeviceNodeJack; |
||
| 85 | |||
| 86 | public:
|
||
| 87 | InputDeviceNodeJack( const DeviceRef &device, const Format &format, const std::shared_ptr<ContextJack> &context ); |
||
| 88 | |||
| 89 | protected:
|
||
| 90 | void initialize() override;
|
||
| 91 | void uninitialize() override;
|
||
| 92 | void enableProcessing() override;
|
||
| 93 | void disableProcessing() override;
|
||
| 94 | void process( Buffer *buffer ) override;
|
||
| 95 | |||
| 96 | private:
|
||
| 97 | std::array< jack_port_t*, 2 > mInputPorts;
|
||
| 98 | }; |
||
| 99 | |||
| 100 | class ContextJack : public Context {
|
||
| 101 | public:
|
||
| 102 | 4:ab6db404403a | f | ContextJack() {}
|
| 103 | virtual ~ContextJack() {}
|
||
| 104 | 1:b5bcad8e7803 | f | |
| 105 | |||
| 106 | OutputDeviceNodeRef createOutputDeviceNode( const DeviceRef &device, const Node::Format &format = Node::Format() ) override; |
||
| 107 | InputDeviceNodeRef createInputDeviceNode( const DeviceRef &device, const Node::Format &format = Node::Format() ) override; |
||
| 108 | |||
| 109 | OutputDeviceNodeRef mOutputDeviceNode; |
||
| 110 | InputDeviceNodeRef mInputDeviceNode; |
||
| 111 | |||
| 112 | |||
| 113 | private:
|
||
| 114 | }; |
||
| 115 | |||
| 116 | } } } // namespace cinder::audio::linux
|