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 
55 class JackTrip; //forward declaration
56 
57 
64 {
65 public:
66 
70  BIT8 = 1,
71  BIT16 = 2,
72  BIT24 = 3,
73  BIT32 = 4
74  };
75 
78  SR22,
79  SR32,
80  SR44,
81  SR48,
82  SR88,
83  SR96,
86  };
87 
95  JackAudioInterface(JackTrip* jacktrip,
96  int NumInChans, int NumOutChans,
97  audioBitResolutionT AudioBitResolution = BIT16,
98  const char* ClientName = "JackTrip");
99 
102  virtual ~JackAudioInterface();
103 
106  void setup();
107 
110  uint32_t getSampleRate() const;
111 
116 
122  static int getSampleRateFromType(samplingRateT rate_type);
123 
127 
131  {
133  }
134 
139  int getAudioBitResolution() const;
140 
142  int getNumInputChannels() const;
143 
145  int getNumOutputChannels() const;
146 
148  size_t getSizeInBytesPerChannel() const;
149 
154  int startProcess() const;
155 
159  int stopProcess() const;
160 
171  /*
172  void setRingBuffers(const std::tr1::shared_ptr<RingBuffer> InRingBuffer,
173  const std::tr1::shared_ptr<RingBuffer> OutRingBuffer);
174  */
175 
182  //void appendProcessPlugin(const std::tr1::shared_ptr<ProcessPlugin> plugin);
183  void appendProcessPlugin(ProcessPlugin* plugin);
184 
192  static void fromSampleToBitConversion(const sample_t* const input,
193  int8_t* output,
194  const audioBitResolutionT targetBitResolution);
195 
203  static void fromBitToSampleConversion(const int8_t* const input,
204  sample_t* output,
205  const audioBitResolutionT sourceBitResolution);
206 
208  void connectDefaultPorts();
209 
211  void setClientName(const char* ClientName)
212  { mClientName = ClientName; }
213 
214 private:
215 
224  void setupClient();
225 
228  void createChannels();
229 
233  static void jackShutdown(void*);
234 
236  //void computeNetworkProcess();
237 
240 
243 
247  void setProcessCallback();
248 
259  int processCallback(jack_nframes_t nframes);
260 
272  // reference : http://article.gmane.org/gmane.comp.audio.jackit/12873
273  static int wrapperProcessCallback(jack_nframes_t nframes, void *arg) ;
274 
275 
281 
282  jack_client_t* mClient;
283  const char* mClientName;
284  QVarLengthArray<jack_port_t*> mInPorts;
285  QVarLengthArray<jack_port_t*> mOutPorts;
286  //jack_port_t** mInPorts; ///< Vector of Input Ports (Channels)
287  //jack_port_t** mOutPorts; ///< Vector of Output Ports (Channels)
288  QVarLengthArray<sample_t*> mInBuffer;
289  QVarLengthArray<sample_t*> mOutBuffer;
290 
291  QVarLengthArray<sample_t*> mInProcessBuffer;
292  QVarLengthArray<sample_t*> mOutProcessBuffer;
293 
297 
298  QVector<ProcessPlugin*> mProcessPlugins;
300 
301  static QMutex sJackMutex;
302 };
303 
304 
305 #endif