AudibleT 0.0.1
A real-time A/B/X audio testing tool for subjective assessment of various audio parameters, compatible for general purpose computer as well as embedded systems.
Loading...
Searching...
No Matches
jackaudioio.hpp
1//C++ Classes that wrap JACK
2//Copyright 2007 Alex Norman
3//
4//This file is part of JACKC++.
5//
6//JACKC++ is free software: you can redistribute it and/or modify
7//it under the terms of the GNU General Public License as published by
8//the Free Software Foundation, either version 3 of the License, or
9//(at your option) any later version.
10//
11//JACKC++ is distributed in the hope that it will be useful,
12//but WITHOUT ANY WARRANTY; without even the implied warranty of
13//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14//GNU General Public License for more details.
15//
16//You should have received a copy of the GNU General Public License
17//along with JACKC++. If not, see <http://www.gnu.org/licenses/>.
18
19#ifndef JACK_AUDIO_IO_H
20#define JACK_AUDIO_IO_H
21
22extern "C" {
23#include <jack/jack.h>
24#include <jack/types.h>
25#include <jack/ringbuffer.h>
26}
27#include <string>
28#include <vector>
29#include <stdexcept>
30#include "jackringbuffer.hpp"
31
32namespace JackCpp {
33
38 class AudioIO {
39 public:
41 enum jack_state_t {notActive,active,closed};
43 typedef std::vector<jack_default_audio_sample_t *> audioBufVector;
44 private:
45 //commands
46 enum cmd_t {add_in_port, add_out_port};
47 RingBuffer<cmd_t> mCmdBuffer;
48 /* the client */
49 jack_client_t *mJackClient;
50 // an vector of i/o ports
51 std::vector<jack_port_t *> mOutputPorts;
52 std::vector<jack_port_t *> mInputPorts;
53
54 //these are only accessed by the callback [once it is activated]
55 //they will usually be equal mOutputPorts.size() etc, except when
56 //a new port is added, before the callback
57 unsigned int mNumOutputPorts;
58 unsigned int mNumInputPorts;
59
60 //these items are used for grabbing data for the jack callback
61 audioBufVector mJackInBuf;
62 audioBufVector mJackOutBuf;
63 //this stores the state of this jack process [active,notActive,closed]
64 jack_state_t mJackState;
65 //this prepares the input/output buffers to be passed
66 //to the callback function that a user writes
67 //XXX should this be virtual?
68 inline int jackToClassAudioCallback(jack_nframes_t nframes);
69 std::vector<std::string> mPortNames;
70 protected:
78 virtual int audioCallback(jack_nframes_t nframes,
79 audioBufVector inBufs,
80 audioBufVector outBufs) = 0;
81 public:
86 jack_client_t * client();
87
96 AudioIO(std::string name,
97 unsigned int inPorts = 0,
98 unsigned int outPorts = 2,
99#ifdef __APPLE__
100 bool startServer = false)
101#else
102 bool startServer = true)
103#endif
104 noexcept(false);
105
106 //create the object but don't actually create the client yet
107 AudioIO();
108
109 void createClient(std::string name,
110 unsigned int inPorts = 0,
111 unsigned int outPorts = 2,
112#ifdef __APPLE__
113 bool startServer = false)
114#else
115 bool startServer = true)
116#endif
117 noexcept(false);
118
120 virtual ~AudioIO();
121
133 static int jackProcessCallback(jack_nframes_t nframes, void *arg);
134
136 bool portExists(std::string name);
137
150 virtual void reserveOutPorts(unsigned int num)
151 noexcept(false);
164 virtual void reserveInPorts(unsigned int num)
165 noexcept(false);
166
168 void start()
169 noexcept(false);
171 void stop()
172 noexcept(false);
174 void close()
175 noexcept(false);
176
178 unsigned int inPorts();
180 unsigned int outPorts();
181
187 virtual unsigned int addInPort(std::string name)
188 noexcept(false);
194 virtual unsigned int addOutPort(std::string name)
195 noexcept(false);
196
202 void connectTo(unsigned int index, std::string sourcePortName)
203 noexcept(false);
209 void connectFrom(unsigned int index, std::string destPortName)
210 noexcept(false);
216 void connectToPhysical(unsigned int index, unsigned physical_index)
217 noexcept(false);
223 void connectFromPhysical(unsigned int index, unsigned physical_index)
224 noexcept(false);
226 void disconnectInPort(unsigned int index)
227 noexcept(false);
229 void disconnectOutPort(unsigned int index)
230 noexcept(false);
231
233 unsigned int numConnectionsInPort(unsigned int index)
234 noexcept(false);
236 unsigned int numConnectionsOutPort(unsigned int index)
237 noexcept(false);
238
243 unsigned int numPhysicalSourcePorts();
248 unsigned int numPhysicalDestinationPorts();
249
251 std::string getInputPortName(unsigned int index)
252 noexcept(false);
254 std::string getOutputPortName(unsigned int index)
255 noexcept(false);
256
261 virtual void jackShutdownCallback();
269 float getCpuLoad();
271 jack_nframes_t getSampleRate();
273 jack_nframes_t getBufferSize();
275 bool isRealTime(){return jack_is_realtime(mJackClient);}
277 bool isBufferMemoryLocked() { return mCmdBuffer.isBufferMemoryLocked(); }
286 std::string getName(){return std::string(jack_get_client_name(mJackClient));}
288 jack_state_t getState(){return mJackState;}
289
297 jack_nframes_t getFrameTime(){return jack_frame_time(mJackClient);}
298
304 jack_nframes_t getFramesSinceCycleStart(){return jack_frames_since_cycle_start(mJackClient);}
305 };
306
307}
308
309#endif
Definition: jackaudioio.hpp:38
void connectFrom(unsigned int index, std::string destPortName) noexcept(false)
Connect our input to a jack client's destination port.
Definition: jackaudioio.cpp:299
void disconnectOutPort(unsigned int index) noexcept(false)
Disconnect output port from all connections.
Definition: jackaudioio.cpp:378
unsigned int numPhysicalSourcePorts()
Get the number of physical audio input ports These are ports that can send audio to your client.
Definition: jackaudioio.cpp:420
jack_nframes_t getBufferSize()
Get the jack buffer size.
Definition: jackaudioio.cpp:489
jack_nframes_t getSampleRate()
Get the sample rate.
Definition: jackaudioio.cpp:485
static int jackProcessCallback(jack_nframes_t nframes, void *arg)
The callback that jack actually gets [static].
Definition: jackaudioio.cpp:47
virtual unsigned int addInPort(std::string name) noexcept(false)
Add a jack input port to our client.
Definition: jackaudioio.cpp:209
void connectToPhysical(unsigned int index, unsigned physical_index) noexcept(false)
Connect our output port to a physical output port.
Definition: jackaudioio.cpp:320
float getCpuLoad()
The current CPU load estimated by JACK.
Definition: jackaudioio.cpp:481
std::vector< jack_default_audio_sample_t * > audioBufVector
A typedef so so that we don't always have to write std::vector<jack_default_audio_sample_t *>
Definition: jackaudioio.hpp:43
virtual int audioCallback(jack_nframes_t nframes, audioBufVector inBufs, audioBufVector outBufs)=0
The method that the user must overload in order to actually process jack data.
virtual void reserveInPorts(unsigned int num) noexcept(false)
Reserve input ports.
Definition: jackaudioio.cpp:192
virtual unsigned int addOutPort(std::string name) noexcept(false)
Add a jack output port to our client.
Definition: jackaudioio.cpp:245
virtual void reserveOutPorts(unsigned int num) noexcept(false)
Reserve output ports.
Definition: jackaudioio.cpp:183
bool portExists(std::string name)
See if a port with the name "name" exists for our client.
Definition: jackaudioio.cpp:173
jack_state_t getState()
Get the state of our Jack client.
Definition: jackaudioio.hpp:288
void connectTo(unsigned int index, std::string sourcePortName) noexcept(false)
Connect our output to a jack client's source port.
Definition: jackaudioio.cpp:279
bool isRealTime()
Check to see if the client is running in real time mode.
Definition: jackaudioio.hpp:275
jack_state_t
An enum indicating the state of our jack client.
Definition: jackaudioio.hpp:41
unsigned int inPorts()
Get the number of jack input ports.
Definition: jackaudioio.cpp:201
jack_nframes_t getFrameTime()
Get an estimate of the current time in frames.
Definition: jackaudioio.hpp:297
std::string getInputPortName(unsigned int index) noexcept(false)
Get the name of our client's input port.
Definition: jackaudioio.cpp:434
unsigned int numPhysicalDestinationPorts()
Get the number of physical audio output ports These are ports that your client can send audio to.
Definition: jackaudioio.cpp:407
unsigned int outPorts()
Get the number of jack output ports.
Definition: jackaudioio.cpp:205
virtual void jackShutdownCallback()
This method is called when Jack shuts down. Override if you want to do something when jack shuts down...
Definition: jackaudioio.cpp:43
void stop() noexcept(false)
Stop the jack client.
Definition: jackaudioio.cpp:465
jack_nframes_t getFramesSinceCycleStart()
Get the time in frames since the JACK server began the current process cycle.
Definition: jackaudioio.hpp:304
virtual ~AudioIO()
The Destructor.
Definition: jackaudioio.cpp:157
bool isBufferMemoryLocked()
Check to see if the buffer is locked into the memory.
Definition: jackaudioio.hpp:277
jack_client_t * client()
Gives users a pointer to the client created and used by this class.
Definition: jackaudioio.cpp:81
void connectFromPhysical(unsigned int index, unsigned physical_index) noexcept(false)
Connect our input port to a physical input port.
Definition: jackaudioio.cpp:344
std::string getName()
Get the name of our client.
Definition: jackaudioio.hpp:286
unsigned int numConnectionsInPort(unsigned int index) noexcept(false)
Get the number of connections to our input port.
Definition: jackaudioio.cpp:389
void start() noexcept(false)
Start the jack client.
Definition: jackaudioio.cpp:452
unsigned int numConnectionsOutPort(unsigned int index) noexcept(false)
Get the number of connections to our output port.
Definition: jackaudioio.cpp:398
void disconnectInPort(unsigned int index) noexcept(false)
Disconnect input port from all connections.
Definition: jackaudioio.cpp:367
void close() noexcept(false)
Close the jack client.
Definition: jackaudioio.cpp:473
std::string getOutputPortName(unsigned int index) noexcept(false)
Get the name of our client's output port.
Definition: jackaudioio.cpp:443
Definition: jackringbuffer.hpp:39
bool isBufferMemoryLocked()
Get whether the ring buffer is locked into the memory.
Definition: jackringbuffer.hpp:71