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
64 class JackAudioInterface : public AudioInterface
65 {
66 public:
67
75 JackAudioInterface(JackTrip* jacktrip,
76 int NumInChans, int NumOutChans,
77 AudioInterface::audioBitResolutionT AudioBitResolution = AudioInterface::BIT16,
78 const char* ClientName = "JackTrip");
80 virtual ~JackAudioInterface();
81
83 virtual void setup();
88 virtual int startProcess() const;
92 virtual int stopProcess() const;
94 void connectDefaultPorts();
95
96 //--------------SETTERS---------------------------------------------
98 virtual void setClientName(const char* ClientName)
99 { mClientName = ClientName; }
100 virtual void setSampleRate(uint32_t /*sample_rate*/)
101 { std::cout << "WARING: Setting the Sample Rate in Jack mode has no effect." << std::endl; }
102 virtual void setBufferSizeInSamples(uint32_t /*buf_size*/)
103 { std::cout << "WARING: Setting the Sample Rate in Jack mode has no effect." << std::endl; }
104 //------------------------------------------------------------------
105
106 //--------------GETTERS---------------------------------------------
108 virtual uint32_t getSampleRate() const;
110 virtual uint32_t getBufferSizeInSamples() const;
112 virtual uint32_t getBufferSizeInBytes() const
113 { return (getBufferSizeInSamples() * getAudioBitResolution()/8); }
115 virtual size_t getSizeInBytesPerChannel() const;
116 //------------------------------------------------------------------
117
118 private:
119
128 void setupClient();
130 void createChannels();
134 static void jackShutdown(void*);
138 void setProcessCallback();
149 int processCallback(jack_nframes_t nframes);
161 // reference : http://article.gmane.org/gmane.comp.audio.jackit/12873
162 static int wrapperProcessCallback(jack_nframes_t nframes, void *arg) ;
163
164 int mNumInChans;
165 int mNumOutChans;
166 int mNumFrames;
167 //int mAudioBitResolution; ///< Bit resolution in audio samples
168 AudioInterface::audioBitResolutionT mBitResolutionMode;
169
170 jack_client_t* mClient;
171 const char* mClientName;
172 QVarLengthArray<jack_port_t*> mInPorts;
173 QVarLengthArray<jack_port_t*> mOutPorts;
174 QVarLengthArray<sample_t*> mInBuffer;
175 QVarLengthArray<sample_t*> mOutBuffer;
176 size_t mSizeInBytesPerChannel;
177 QVector<ProcessPlugin*> mProcessPlugins;
178 JackTrip* mJackTrip;
179 static QMutex sJackMutex;
180 };
181
182
183 #endif
jacktrip_types.h
JackAudioInterface::setBufferSizeInSamples
virtual void setBufferSizeInSamples(uint32_t)
Definition: JackAudioInterface.h:102
JackAudioInterface::getBufferSizeInBytes
virtual uint32_t getBufferSizeInBytes() const
Get the Jack Server Buffer Size, in bytes.
Definition: JackAudioInterface.h:112
AudioInterface::audioBitResolutionT
audioBitResolutionT
Enum for Audio Resolution in bits.
Definition: AudioInterface.h:61
AudioInterface
Base Class that provides an interface with audio.
Definition: AudioInterface.h:56
JackAudioInterface::setClientName
virtual void setClientName(const char *ClientName)
Set Client Name to something different that the default (JackTrip)
Definition: JackAudioInterface.h:98
JackAudioInterface::~JackAudioInterface
virtual ~JackAudioInterface()
The class destructor.
Definition: JackAudioInterface.cpp:81
JackAudioInterface
Class that provides an interface with the Jack Audio Server.
Definition: JackAudioInterface.h:64
JackAudioInterface::getSizeInBytesPerChannel
virtual size_t getSizeInBytesPerChannel() const
Get size of each audio per channel, in bytes.
Definition: JackAudioInterface.cpp:186
uint32_t
quint32 uint32_t
Typedef for unsigned int. This type is guaranteed to be 32-bit.
Definition: jacktrip_types.h:73
AudioInterface.h
AudioInterface::BIT16
16 bits (default)
Definition: AudioInterface.h:63
JackAudioInterface::JackAudioInterface
JackAudioInterface(JackTrip *jacktrip, int NumInChans, int NumOutChans, AudioInterface::audioBitResolutionT AudioBitResolution=AudioInterface::BIT16, const char *ClientName="JackTrip")
The class constructor.
Definition: JackAudioInterface.cpp:64
JackAudioInterface::getBufferSizeInSamples
virtual uint32_t getBufferSizeInSamples() const
Get the Jack Server Buffer Size, in samples.
Definition: JackAudioInterface.cpp:179
JackAudioInterface::startProcess
virtual int startProcess() const
Tell the JACK server that we are ready to roll. The process-callback will start running. This runs on its own thread.
Definition: JackAudioInterface.cpp:212
JackAudioInterface::setSampleRate
virtual void setSampleRate(uint32_t)
Definition: JackAudioInterface.h:100
JackAudioInterface::stopProcess
virtual int stopProcess() const
Stops the process-callback thread.
Definition: JackAudioInterface.cpp:226
JackAudioInterface::getSampleRate
virtual uint32_t getSampleRate() const
Get the Jack Server Sampling Rate, in samples/second.
Definition: JackAudioInterface.cpp:172
JackTrip
Main class to creates a SERVER (to listen) or a CLIENT (to connect to a listening server) to send aud...
Definition: JackTrip.h:67
ProcessPlugin.h
AudioInterface::getAudioBitResolution
virtual int getAudioBitResolution() const
Get the Audio Bit Resolution, in bits.
Definition: AudioInterface.h:178
JackAudioInterface::setup
virtual void setup()
Setup the client.
Definition: JackAudioInterface.cpp:86
JackAudioInterface::connectDefaultPorts
void connectDefaultPorts()
Connect the default ports, capture to sends, and receives to playback.
Definition: JackAudioInterface.cpp:284