annotate JackDevice/ContextJack.h @ 18:f1ff1a81be20 tip

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