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 {
66 public:
67 
75  JackAudioInterface(JackTrip* jacktrip,
76  int NumInChans, int NumOutChans,
77  #ifdef WAIR // wair
78  int NumNetRevChans,
79  #endif // endwhere
81  const char* ClientName = "JackTrip");
83  virtual ~JackAudioInterface();
84 
86  virtual void setup();
91  virtual int startProcess() const;
95  virtual int stopProcess() const;
97  void connectDefaultPorts();
98 
99  //--------------SETTERS---------------------------------------------
101  virtual void setClientName(const char* 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  //------------------------------------------------------------------
108 
109  //--------------GETTERS---------------------------------------------
111  virtual uint32_t getSampleRate() const;
113  virtual uint32_t getBufferSizeInSamples() const;
116  { return (getBufferSizeInSamples() * getAudioBitResolution()/8); }
118  virtual size_t getSizeInBytesPerChannel() const;
119  //------------------------------------------------------------------
120 
121 private:
122 
131  void setupClient();
133  void createChannels();
137  static void jackShutdown(void*);
141  void setProcessCallback();
152  int processCallback(jack_nframes_t nframes);
164  // reference : http://article.gmane.org/gmane.comp.audio.jackit/12873
165  static int wrapperProcessCallback(jack_nframes_t nframes, void *arg) ;
166 
167  int mNumInChans;
168  int mNumOutChans;
169 #ifdef WAIR // WAIR
170  int mNumNetRevChans;
171 #endif // endwhere
172  int mNumFrames;
173  //int mAudioBitResolution; ///< Bit resolution in audio samples
174  AudioInterface::audioBitResolutionT mBitResolutionMode;
175 
176  jack_client_t* mClient;
177  const char* mClientName;
178  QVarLengthArray<jack_port_t*> mInPorts;
179  QVarLengthArray<jack_port_t*> mOutPorts;
180  QVarLengthArray<sample_t*> mInBuffer;
181  QVarLengthArray<sample_t*> mOutBuffer;
182  size_t mSizeInBytesPerChannel;
183  QVector<ProcessPlugin*> mProcessPlugins;
184  JackTrip* mJackTrip;
185  static QMutex sJackMutex;
186 };
187 
188 
189 #endif
JackAudioInterface::getBufferSizeInSamples
virtual uint32_t getBufferSizeInSamples() const
Get the Jack Server Buffer Size, in samples.
Definition: JackAudioInterface.cpp:193
JackAudioInterface
Class that provides an interface with the Jack Audio Server.
Definition: JackAudioInterface.h:65
JackAudioInterface::getSampleRate
virtual uint32_t getSampleRate() const
Get the Jack Server Sampling Rate, in samples/second.
Definition: JackAudioInterface.cpp:186
JackAudioInterface::startProcess
virtual int startProcess() const
Tell the JACK server that we are ready to roll. The process-callback will start running....
Definition: JackAudioInterface.cpp:226
JackTrip
Main class to creates a SERVER (to listen) or a CLIENT (to connect to a listening server) to send aud...
Definition: JackTrip.h:68
JackAudioInterface::JackAudioInterface
JackAudioInterface(JackTrip *jacktrip, int NumInChans, int NumOutChans, AudioInterface::audioBitResolutionT AudioBitResolution=AudioInterface::BIT16, const char *ClientName="JackTrip")
The class constructor.
Definition: JackAudioInterface.cpp:63
JackAudioInterface::setSampleRate
virtual void setSampleRate(uint32_t)
Definition: JackAudioInterface.h:103
JackAudioInterface::setup
virtual void setup()
Setup the client.
Definition: JackAudioInterface.cpp:94
AudioInterface.h
AudioInterface::audioBitResolutionT
audioBitResolutionT
Enum for Audio Resolution in bits.
Definition: AudioInterface.h:61
JackAudioInterface::connectDefaultPorts
void connectDefaultPorts()
Connect the default ports, capture to sends, and receives to playback.
Definition: JackAudioInterface.cpp:298
JackAudioInterface::getBufferSizeInBytes
virtual uint32_t getBufferSizeInBytes() const
Get the Jack Server Buffer Size, in bytes.
Definition: JackAudioInterface.h:115
uint32_t
quint32 uint32_t
Typedef for unsigned int. This type is guaranteed to be 32-bit.
Definition: jacktrip_types.h:73
AudioInterface::getAudioBitResolution
virtual int getAudioBitResolution() const
Get the Audio Bit Resolution, in bits.
Definition: AudioInterface.h:185
JackAudioInterface::setClientName
virtual void setClientName(const char *ClientName)
Set Client Name to something different that the default (JackTrip)
Definition: JackAudioInterface.h:101
ProcessPlugin.h
AudioInterface::BIT16
@ BIT16
16 bits (default)
Definition: AudioInterface.h:63
JackAudioInterface::~JackAudioInterface
virtual ~JackAudioInterface()
The class destructor.
Definition: JackAudioInterface.cpp:89
JackAudioInterface::getSizeInBytesPerChannel
virtual size_t getSizeInBytesPerChannel() const
Get size of each audio per channel, in bytes.
Definition: JackAudioInterface.cpp:200
JackAudioInterface::stopProcess
virtual int stopProcess() const
Stops the process-callback thread.
Definition: JackAudioInterface.cpp:240
jacktrip_types.h
AudioInterface
Base Class that provides an interface with audio.
Definition: AudioInterface.h:57
JackAudioInterface::setBufferSizeInSamples
virtual void setBufferSizeInSamples(uint32_t)
Definition: JackAudioInterface.h:105