JackTrip
|
00001 //***************************************************************** 00002 /* 00003 JackTrip: A System for High-Quality Audio Network Performance 00004 over the Internet 00005 00006 Copyright (c) 2008 Juan-Pablo Caceres, Chris Chafe. 00007 SoundWIRE group at CCRMA, Stanford University. 00008 00009 Permission is hereby granted, free of charge, to any person 00010 obtaining a copy of this software and associated documentation 00011 files (the "Software"), to deal in the Software without 00012 restriction, including without limitation the rights to use, 00013 copy, modify, merge, publish, distribute, sublicense, and/or sell 00014 copies of the Software, and to permit persons to whom the 00015 Software is furnished to do so, subject to the following 00016 conditions: 00017 00018 The above copyright notice and this permission notice shall be 00019 included in all copies or substantial portions of the Software. 00020 00021 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00023 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00024 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00025 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00026 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00027 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 OTHER DEALINGS IN THE SOFTWARE. 00029 */ 00030 //***************************************************************** 00031 00039 #ifndef __JACKAUDIOINTERFACE_H__ 00040 #define __JACKAUDIOINTERFACE_H__ 00041 00042 #include <iostream> 00043 #include <tr1/memory> //for shared_ptr 00044 #include <functional> //for mem_fun_ref 00045 #include <jack/jack.h> 00046 00047 #include <QVector> 00048 #include <QVarLengthArray> 00049 #include <QMutex> 00050 00051 00052 #include "jacktrip_types.h" 00053 #include "ProcessPlugin.h" 00054 00055 class JackTrip; //forward declaration 00056 00057 00063 class JackAudioInterface 00064 { 00065 public: 00066 00069 enum audioBitResolutionT { 00070 BIT8 = 1, 00071 BIT16 = 2, 00072 BIT24 = 3, 00073 BIT32 = 4 00074 }; 00075 00077 enum samplingRateT { 00078 SR22, 00079 SR32, 00080 SR44, 00081 SR48, 00082 SR88, 00083 SR96, 00084 SR192, 00085 UNDEF 00086 }; 00087 00095 JackAudioInterface(JackTrip* jacktrip, 00096 int NumInChans, int NumOutChans, 00097 audioBitResolutionT AudioBitResolution = BIT16, 00098 const char* ClientName = "JackTrip"); 00099 00102 virtual ~JackAudioInterface(); 00103 00106 void setup(); 00107 00110 uint32_t getSampleRate() const; 00111 00115 samplingRateT getSampleRateType() const; 00116 00122 static int getSampleRateFromType(samplingRateT rate_type); 00123 00126 uint32_t getBufferSizeInSamples() const; 00127 00130 uint32_t getBufferSizeInBytes() const 00131 { 00132 return (getBufferSizeInSamples() * getAudioBitResolution()/8); 00133 } 00134 00139 int getAudioBitResolution() const; 00140 00142 int getNumInputChannels() const; 00143 00145 int getNumOutputChannels() const; 00146 00148 size_t getSizeInBytesPerChannel() const; 00149 00154 int startProcess() const; 00155 00159 int stopProcess() const; 00160 00171 /* 00172 void setRingBuffers(const std::tr1::shared_ptr<RingBuffer> InRingBuffer, 00173 const std::tr1::shared_ptr<RingBuffer> OutRingBuffer); 00174 */ 00175 00182 //void appendProcessPlugin(const std::tr1::shared_ptr<ProcessPlugin> plugin); 00183 void appendProcessPlugin(ProcessPlugin* plugin); 00184 00192 static void fromSampleToBitConversion(const sample_t* const input, 00193 int8_t* output, 00194 const audioBitResolutionT targetBitResolution); 00195 00203 static void fromBitToSampleConversion(const int8_t* const input, 00204 sample_t* output, 00205 const audioBitResolutionT sourceBitResolution); 00206 00208 void connectDefaultPorts(); 00209 00211 void setClientName(const char* ClientName) 00212 { mClientName = ClientName; } 00213 00214 private: 00215 00224 void setupClient(); 00225 00228 void createChannels(); 00229 00233 static void jackShutdown(void*); 00234 00236 //void computeNetworkProcess(); 00237 00239 void computeNetworkProcessFromNetwork(); 00240 00242 void computeNetworkProcessToNetwork(); 00243 00247 void setProcessCallback(); 00248 00259 int processCallback(jack_nframes_t nframes); 00260 00272 // reference : http://article.gmane.org/gmane.comp.audio.jackit/12873 00273 static int wrapperProcessCallback(jack_nframes_t nframes, void *arg) ; 00274 00275 00276 int mNumInChans; 00277 int mNumOutChans; 00278 int mNumFrames; 00279 int mAudioBitResolution; 00280 audioBitResolutionT mBitResolutionMode; 00281 00282 jack_client_t* mClient; 00283 const char* mClientName; 00284 QVarLengthArray<jack_port_t*> mInPorts; 00285 QVarLengthArray<jack_port_t*> mOutPorts; 00286 //jack_port_t** mInPorts; ///< Vector of Input Ports (Channels) 00287 //jack_port_t** mOutPorts; ///< Vector of Output Ports (Channels) 00288 QVarLengthArray<sample_t*> mInBuffer; 00289 QVarLengthArray<sample_t*> mOutBuffer; 00290 00291 QVarLengthArray<sample_t*> mInProcessBuffer; 00292 QVarLengthArray<sample_t*> mOutProcessBuffer; 00293 00294 int8_t* mInputPacket; 00295 int8_t* mOutputPacket; 00296 size_t mSizeInBytesPerChannel; 00297 00298 QVector<ProcessPlugin*> mProcessPlugins; 00299 JackTrip* mJackTrip; 00300 00301 static QMutex sJackMutex; 00302 }; 00303 00304 00305 #endif