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
56 class AudioInterface
57 {
58 public:
59
61 enum audioBitResolutionT {
62 BIT8 = 1,
63 BIT16 = 2,
64 BIT24 = 3,
65 BIT32 = 4
66 };
67
69 enum samplingRateT {
70 SR22,
71 SR32,
72 SR44,
73 SR48,
74 SR88,
75 SR96,
76 SR192,
77 UNDEF
78 };
79
86 AudioInterface(JackTrip* jacktrip,
87 int NumInChans, int NumOutChans,
88 AudioInterface::audioBitResolutionT AudioBitResolution =
89 AudioInterface::BIT16);
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; }
165 virtual uint32_t getBufferSizeInSamples() const
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__
jacktrip_types.h
AudioInterface::setBufferSizeInSamples
virtual void setBufferSizeInSamples(uint32_t buf_size)
Definition: AudioInterface.h:154
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
AudioInterface::getNumInputChannels
virtual int getNumInputChannels() const
Get Number of Input Channels.
Definition: AudioInterface.h:162
AudioInterface::stopProcess
virtual int stopProcess() const =0
Stops the process-callback thread.
AudioInterface::getBufferSizeInSamples
virtual uint32_t getBufferSizeInSamples() const
Definition: AudioInterface.h:165
AudioInterface::samplingRateT
samplingRateT
Sampling Rates supported by JACK.
Definition: AudioInterface.h:69
AudioInterface::UNDEF
Undefined.
Definition: AudioInterface.h:77
AudioInterface::SR88
88200 Hz
Definition: AudioInterface.h:74
AudioInterface::callback
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
AudioInterface::setSampleRate
virtual void setSampleRate(uint32_t sample_rate)
Definition: AudioInterface.h:152
uint32_t
quint32 uint32_t
Typedef for unsigned int. This type is guaranteed to be 32-bit.
Definition: jacktrip_types.h:73
AudioInterface::setup
virtual void setup()
Setup the client. This function should be called just before.
Definition: AudioInterface.cpp:82
AudioInterface::BIT16
16 bits (default)
Definition: AudioInterface.h:63
AudioInterface::startProcess
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.
AudioInterface::SR44
44100 Hz
Definition: AudioInterface.h:72
AudioInterface::getSampleRate
virtual uint32_t getSampleRate() const
Get the Jack Server Sampling Rate, in samples/second.
Definition: AudioInterface.h:169
AudioInterface::SR48
48000 Hz
Definition: AudioInterface.h:73
ProcessPlugin
Interface for the process plugins to add to the JACK callback process in JackAudioInterface.
Definition: ProcessPlugin.h:52
AudioInterface::getNumOutputChannels
virtual int getNumOutputChannels() const
Get Number of Output Channels.
Definition: AudioInterface.h:164
AudioInterface::getSampleRateType
virtual samplingRateT getSampleRateType() const
Get the Jack Server Sampling Rate Enum Type samplingRateT.
Definition: AudioInterface.cpp:333
AudioInterface::connectDefaultPorts
virtual void connectDefaultPorts()=0
AudioInterface::SR32
32000 Hz
Definition: AudioInterface.h:71
int8_t
qint8 int8_t
Typedef for unsigned long long int. This type is guaranteed to be 64-bit.
Definition: jacktrip_types.h:78
AudioInterface::fromSampleToBitConversion
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
AudioInterface::SR22
22050 Hz
Definition: AudioInterface.h:70
AudioInterface::BIT24
24 bits
Definition: AudioInterface.h:64
AudioInterface::fromBitToSampleConversion
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
sample_t
float sample_t
Audio sample type.
Definition: jacktrip_types.h:56
AudioInterface::appendProcessPlugin
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
AudioInterface::BIT8
8 bits
Definition: AudioInterface.h:62
AudioInterface::AudioInterface
AudioInterface(JackTrip *jacktrip, int NumInChans, int NumOutChans, AudioInterface::audioBitResolutionT AudioBitResolution=AudioInterface::BIT16)
The class constructor.
Definition: AudioInterface.cpp:46
AudioInterface::~AudioInterface
virtual ~AudioInterface()
The class destructor.
Definition: AudioInterface.cpp:67
AudioInterface::setClientName
virtual void setClientName(const char *ClientName)=0
Set Client Name to something different that the default (JackTrip)
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
AudioInterface::getSizeInBytesPerChannel
virtual size_t getSizeInBytesPerChannel() const
Definition: AudioInterface.cpp:110
AudioInterface::setNumOutputChannels
virtual void setNumOutputChannels(int nchannels)
Definition: AudioInterface.h:150
AudioInterface::getSampleRateFromType
static int getSampleRateFromType(samplingRateT rate_type)
Helper function to get the sample rate (in Hz) for a JackAudioInterface::samplingRateT.
Definition: AudioInterface.cpp:356
AudioInterface::SR192
192000 Hz
Definition: AudioInterface.h:76
ProcessPlugin.h
AudioInterface::SR96
96000 Hz
Definition: AudioInterface.h:75
AudioInterface::getAudioBitResolution
virtual int getAudioBitResolution() const
Get the Audio Bit Resolution, in bits.
Definition: AudioInterface.h:178
AudioInterface::BIT32
32 bits
Definition: AudioInterface.h:65
AudioInterface::setNumInputChannels
virtual void setNumInputChannels(int nchannels)
Definition: AudioInterface.h:148