JackTrip
JackAudioInterface.h
Go to the documentation of this file.
1//*****************************************************************
2/*
3 JackTrip: A System for High-Quality Audio Network Performance
4 over the Internet
5
6 Copyright (c) 2008 Juan-Pablo Caceres, Chris Chafe.
7 SoundWIRE group at CCRMA, Stanford University.
8
9 Permission is hereby granted, free of charge, to any person
10 obtaining a copy of this software and associated documentation
11 files (the "Software"), to deal in the Software without
12 restriction, including without limitation the rights to use,
13 copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the
15 Software is furnished to do so, subject to the following
16 conditions:
17
18 The above copyright notice and this permission notice shall be
19 included in all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 OTHER DEALINGS IN THE SOFTWARE.
29*/
30//*****************************************************************
31
39#ifndef __JACKAUDIOINTERFACE_H__
40#define __JACKAUDIOINTERFACE_H__
41
42#include <iostream>
43//#include <tr1/memory> //for shared_ptr
44#include <functional> //for mem_fun_ref
45#include <jack/jack.h>
46
47#include <QVector>
48#include <QVarLengthArray>
49#include <QMutex>
50
51
52#include "jacktrip_types.h"
53#include "ProcessPlugin.h"
54#include "AudioInterface.h"
55
56//class JackTrip; //forward declaration
57
58
65{
66public:
67
76 int NumInChans, int NumOutChans,
77 #ifdef WAIR // wair
78 int NumNetRevChans,
79 #endif // endwhere
81 QString ClientName = "JackTrip");
83 virtual ~JackAudioInterface();
84
86 virtual void setup();
91 virtual int startProcess() const;
95 virtual int stopProcess() const;
98
99 //--------------SETTERS---------------------------------------------
101 virtual void setClientName(QString ClientName)
102 { mClientName = ClientName; }
103 virtual void setSampleRate(uint32_t /*sample_rate*/)
104 { std::cout << "WARNING: Setting the Sample Rate in Jack mode has no effect." << std::endl; }
105 virtual void setBufferSizeInSamples(uint32_t /*buf_size*/)
106 { std::cout << "WARNING: Setting the Sample Rate in Jack mode has no effect." << std::endl; }
107 virtual void enableBroadcastOutput() {mBroadcast = true;}
108 //------------------------------------------------------------------
109
110 //--------------GETTERS---------------------------------------------
112 virtual uint32_t getSampleRate() const;
114 virtual uint32_t getBufferSizeInSamples() const;
117 { return (getBufferSizeInSamples() * getAudioBitResolution() / 8); }
119 virtual size_t getSizeInBytesPerChannel() const;
120 //------------------------------------------------------------------
121
122private:
123
132 void setupClient();
134 void createChannels();
138 static void jackShutdown(void*);
142 void setProcessCallback();
153 int processCallback(jack_nframes_t nframes);
165 // reference : http://article.gmane.org/gmane.comp.audio.jackit/12873
166 static int wrapperProcessCallback(jack_nframes_t nframes, void *arg) ;
167
168 int mNumInChans;
169 int mNumOutChans;
170#ifdef WAIR // WAIR
171 int mNumNetRevChans;
172#endif // endwhere
173 int mNumFrames;
174 //int mAudioBitResolution; ///< Bit resolution in audio samples
175 AudioInterface::audioBitResolutionT mBitResolutionMode;
176
177 jack_client_t* mClient;
178 QString mClientName;
179 QVarLengthArray<jack_port_t*> mInPorts;
180 QVarLengthArray<jack_port_t*> mOutPorts;
181 QVarLengthArray<jack_port_t*> mBroadcastPorts;
182 QVarLengthArray<sample_t*> mInBuffer;
183 QVarLengthArray<sample_t*> mOutBuffer;
184 QVarLengthArray<sample_t*> mBroadcastBuffer;
185 bool mBroadcast;
186 size_t mSizeInBytesPerChannel;
187 QVector<ProcessPlugin*> mProcessPlugins;
188 JackTrip* mJackTrip;
189 static QMutex sJackMutex;
190};
191
192
193#endif
Base Class that provides an interface with audio.
Definition: AudioInterface.h:58
virtual int getAudioBitResolution() const
Get the Audio Bit Resolution, in bits.
Definition: AudioInterface.h:206
audioBitResolutionT
Enum for Audio Resolution in bits.
Definition: AudioInterface.h:62
@ BIT16
16 bits (default)
Definition: AudioInterface.h:64
Class that provides an interface with the Jack Audio Server.
Definition: JackAudioInterface.h:65
virtual void setBufferSizeInSamples(uint32_t)
Definition: JackAudioInterface.h:105
void connectDefaultPorts()
Connect the default ports, capture to sends, and receives to playback.
Definition: JackAudioInterface.cpp:346
virtual uint32_t getBufferSizeInBytes() const
Get the Jack Server Buffer Size, in bytes.
Definition: JackAudioInterface.h:116
virtual uint32_t getBufferSizeInSamples() const
Get the Jack Server Buffer Size, in samples.
Definition: JackAudioInterface.cpp:226
virtual size_t getSizeInBytesPerChannel() const
Get size of each audio per channel, in bytes.
Definition: JackAudioInterface.cpp:233
virtual void setup()
Setup the client.
Definition: JackAudioInterface.cpp:95
virtual ~JackAudioInterface()
The class destructor.
Definition: JackAudioInterface.cpp:90
virtual int startProcess() const
Tell the JACK server that we are ready to roll. The process-callback will start running....
Definition: JackAudioInterface.cpp:259
virtual void setSampleRate(uint32_t)
Definition: JackAudioInterface.h:103
virtual void enableBroadcastOutput()
Definition: JackAudioInterface.h:107
virtual uint32_t getSampleRate() const
Get the Jack Server Sampling Rate, in samples/second.
Definition: JackAudioInterface.cpp:219
virtual int stopProcess() const
Stops the process-callback thread.
Definition: JackAudioInterface.cpp:273
virtual void setClientName(QString ClientName)
Set Client Name to something different that the default (JackTrip)
Definition: JackAudioInterface.h:101
Main class to creates a SERVER (to listen) or a CLIENT (to connect to a listening server) to send aud...
Definition: JackTrip.h:72
quint32 uint32_t
Typedef for unsigned int. This type is guaranteed to be 32-bit.
Definition: jacktrip_types.h:73