JackTrip
AudioInterface.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 
38 #ifndef __AUDIOINTERFACE_H__
39 #define __AUDIOINTERFACE_H__
40 
41 #include "ProcessPlugin.h"
42 #include "jacktrip_types.h"
43 
44 #include <QVarLengthArray>
45 #include <QVector>
46 //#include "jacktrip_globals.h"
47 
48 // Forward declarations
49 class JackTrip;
50 
51 //using namespace JackTripNamespace;
52 
53 
57 {
58 public:
59 
62  BIT8 = 1,
63  BIT16 = 2,
64  BIT24 = 3,
65  BIT32 = 4
66  };
67 
70  SR22,
71  SR32,
72  SR44,
73  SR48,
74  SR88,
75  SR96,
78  };
79 
86  AudioInterface(JackTrip* jacktrip,
87  int NumInChans, int NumOutChans,
88  AudioInterface::audioBitResolutionT AudioBitResolution =
91  virtual ~AudioInterface();
92 
100  virtual void setup();
104  virtual int startProcess() const = 0;
107  virtual int stopProcess() const = 0;
115  virtual void callback(QVarLengthArray<sample_t*>& in_buffer,
116  QVarLengthArray<sample_t*>& out_buffer,
117  unsigned int n_frames);
124  virtual void appendProcessPlugin(ProcessPlugin* plugin);
125  virtual void connectDefaultPorts() = 0;
133  static void fromSampleToBitConversion(const sample_t* const input,
134  int8_t* output,
135  const AudioInterface::audioBitResolutionT targetBitResolution);
143  static void fromBitToSampleConversion(const int8_t* const input,
144  sample_t* output,
145  const AudioInterface::audioBitResolutionT sourceBitResolution);
146 
147  //--------------SETTERS---------------------------------------------
148  virtual void setNumInputChannels(int nchannels)
149  { mNumInChans = nchannels; }
150  virtual void setNumOutputChannels(int nchannels)
151  { mNumOutChans = nchannels; }
152  virtual void setSampleRate(uint32_t sample_rate)
153  { mSampleRate = sample_rate; }
154  virtual void setBufferSizeInSamples(uint32_t buf_size)
155  { mBufferSizeInSamples = buf_size; }
157  virtual void setClientName(const char* ClientName) = 0;
158  //------------------------------------------------------------------
159 
160  //--------------GETTERS---------------------------------------------
162  virtual int getNumInputChannels() const { return mNumInChans; }
164  virtual int getNumOutputChannels() const { return mNumOutChans; }
166  { return mBufferSizeInSamples; }
167  virtual size_t getSizeInBytesPerChannel() const;
169  virtual uint32_t getSampleRate() const
170  { return mSampleRate; }
173  virtual samplingRateT getSampleRateType() const;
178  virtual int getAudioBitResolution() const { return mAudioBitResolution; }
184  static int getSampleRateFromType(samplingRateT rate_type);
185  //------------------------------------------------------------------
186 
187 
188 private:
189 
191  void computeProcessFromNetwork(QVarLengthArray<sample_t*>& out_buffer,
192  unsigned int n_frames);
194  void computeProcessToNetwork(QVarLengthArray<sample_t*>& in_buffer,
195  unsigned int n_frames);
196 
197  JackTrip* mJackTrip;
198  int mNumInChans;
199  int mNumOutChans;
200  int mAudioBitResolution;
201  AudioInterface::audioBitResolutionT mBitResolutionMode;
202  uint32_t mSampleRate;
203  uint32_t mBufferSizeInSamples;
204  size_t mSizeInBytesPerChannel;
205  QVector<ProcessPlugin*> mProcessPlugins;
206  QVarLengthArray<sample_t*> mInProcessBuffer;
207  QVarLengthArray<sample_t*> mOutProcessBuffer;
208  int8_t* mInputPacket;
209  int8_t* mOutputPacket;
210 };
211 
212 #endif // __AUDIOINTERFACE_H__
virtual void setBufferSizeInSamples(uint32_t buf_size)
Definition: AudioInterface.h:154
virtual int getNumOutputChannels() const
Get Number of Output Channels.
Definition: AudioInterface.h:164
audioBitResolutionT
Enum for Audio Resolution in bits.
Definition: AudioInterface.h:61
Base Class that provides an interface with audio.
Definition: AudioInterface.h:56
virtual int stopProcess() const =0
Stops the process-callback thread.
samplingRateT
Sampling Rates supported by JACK.
Definition: AudioInterface.h:69
Undefined.
Definition: AudioInterface.h:77
88200 Hz
Definition: AudioInterface.h:74
virtual void setSampleRate(uint32_t sample_rate)
Definition: AudioInterface.h:152
quint32 uint32_t
Typedef for unsigned int. This type is guaranteed to be 32-bit.
Definition: jacktrip_types.h:73
virtual int getNumInputChannels() const
Get Number of Input Channels.
Definition: AudioInterface.h:162
virtual void setup()
Setup the client. This function should be called just before.
Definition: AudioInterface.cpp:82
16 bits (default)
Definition: AudioInterface.h:63
virtual size_t getSizeInBytesPerChannel() const
Definition: AudioInterface.cpp:110
virtual int startProcess() const =0
Tell the audio server that we are ready to roll. The process-callback will start running. This runs on its own thread.
44100 Hz
Definition: AudioInterface.h:72
48000 Hz
Definition: AudioInterface.h:73
Interface for the process plugins to add to the JACK callback process in JackAudioInterface.
Definition: ProcessPlugin.h:52
virtual int getAudioBitResolution() const
Get the Audio Bit Resolution, in bits.
Definition: AudioInterface.h:178
virtual void connectDefaultPorts()=0
32000 Hz
Definition: AudioInterface.h:71
qint8 int8_t
Typedef for unsigned long long int. This type is guaranteed to be 64-bit.
Definition: jacktrip_types.h:78
static void fromSampleToBitConversion(const sample_t *const input, int8_t *output, const AudioInterface::audioBitResolutionT targetBitResolution)
Convert a 32bit number (sample_t) into one of the bit resolution supported (audioBitResolutionT).
Definition: AudioInterface.cpp:233
22050 Hz
Definition: AudioInterface.h:70
24 bits
Definition: AudioInterface.h:64
static void fromBitToSampleConversion(const int8_t *const input, sample_t *output, const AudioInterface::audioBitResolutionT sourceBitResolution)
Convert a audioBitResolutionT bit resolution number into a 32bit number (sample_t) ...
Definition: AudioInterface.cpp:283
float sample_t
Audio sample type.
Definition: jacktrip_types.h:56
virtual void appendProcessPlugin(ProcessPlugin *plugin)
Append a ProcessPlugin. The order of processing is determined by the order by which appending is done...
Definition: AudioInterface.cpp:324
8 bits
Definition: AudioInterface.h:62
virtual uint32_t getSampleRate() const
Get the Jack Server Sampling Rate, in samples/second.
Definition: AudioInterface.h:169
AudioInterface(JackTrip *jacktrip, int NumInChans, int NumOutChans, AudioInterface::audioBitResolutionT AudioBitResolution=AudioInterface::BIT16)
The class constructor.
Definition: AudioInterface.cpp:46
virtual ~AudioInterface()
The class destructor.
Definition: AudioInterface.cpp:67
virtual void setClientName(const char *ClientName)=0
Set Client Name to something different that the default (JackTrip)
virtual void callback(QVarLengthArray< sample_t * > &in_buffer, QVarLengthArray< sample_t * > &out_buffer, unsigned int n_frames)
Process callback. Subclass should call this callback after obtaining the in_buffer and out_buffer poi...
Definition: AudioInterface.cpp:117
Main class to creates a SERVER (to listen) or a CLIENT (to connect to a listening server) to send aud...
Definition: JackTrip.h:67
virtual void setNumOutputChannels(int nchannels)
Definition: AudioInterface.h:150
static int getSampleRateFromType(samplingRateT rate_type)
Helper function to get the sample rate (in Hz) for a JackAudioInterface::samplingRateT.
Definition: AudioInterface.cpp:356
192000 Hz
Definition: AudioInterface.h:76
96000 Hz
Definition: AudioInterface.h:75
virtual uint32_t getBufferSizeInSamples() const
Definition: AudioInterface.h:165
virtual samplingRateT getSampleRateType() const
Get the Jack Server Sampling Rate Enum Type samplingRateT.
Definition: AudioInterface.cpp:333
32 bits
Definition: AudioInterface.h:65
virtual void setNumInputChannels(int nchannels)
Definition: AudioInterface.h:148