Class that provides an interface with the Jack Audio Server. More...
#include <JackAudioInterface.h>
Public Types | ||||
enum | audioBitResolutionT { BIT8 = 1, BIT16 = 2, BIT24 = 3, BIT32 = 4 } | |||
Enum for Audio Resolution in bits. More... | ||||
enum | samplingRateT { SR22, SR32, SR44, SR48, SR88, SR96, SR192, UNDEF } | |||
Sampling Rates supported by JACK. More... | ||||
Public Member Functions | ||||
JackAudioInterface (JackTrip *jacktrip, int NumInChans, int NumOutChans, audioBitResolutionT AudioBitResolution=BIT16, const char *ClientName="JackTrip") | ||||
The class constructor. | ||||
virtual | ~JackAudioInterface () | |||
The class destructor. | ||||
void | setup () | |||
Setup the client. | ||||
uint32_t | getSampleRate () const | |||
Get the Jack Server Sampling Rate, in samples/second. | ||||
samplingRateT | getSampleRateType () const | |||
Get the Jack Server Sampling Rate Enum Type samplingRateT. | ||||
uint32_t | getBufferSizeInSamples () const | |||
Get the Jack Server Buffer Size, in samples. | ||||
uint32_t | getBufferSizeInBytes () const | |||
Get the Jack Server Buffer Size, in bytes. | ||||
int | getAudioBitResolution () const | |||
Get the Audio Bit Resolution, in bits. | ||||
int | getNumInputChannels () const | |||
Get Number of Input Channels. | ||||
int | getNumOutputChannels () const | |||
Get Number of Output Channels. | ||||
size_t | getSizeInBytesPerChannel () const | |||
Get size of each audio per channel, in bytes. | ||||
int | startProcess () const | |||
Tell the JACK server that we are ready to roll. The process-callback will start running. This runs on its own thread. | ||||
int | stopProcess () const | |||
Stops the process-callback thread. | ||||
void | appendProcessPlugin (ProcessPlugin *plugin) | |||
Set the pointer to the Input and Output RingBuffer that'll be use to read and write audio. | ||||
void | connectDefaultPorts () | |||
Connect the default ports, capture to sends, and receives to playback. | ||||
void | setClientName (const char *ClientName) | |||
Set Client Name to something different that the default (JackTrip). | ||||
Static Public Member Functions | ||||
static int | getSampleRateFromType (samplingRateT rate_type) | |||
Helper function to get the sample rate (in Hz) for a JackAudioInterface::samplingRateT. | ||||
static void | fromSampleToBitConversion (const sample_t *const input, int8_t *output, const audioBitResolutionT targetBitResolution) | |||
Convert a 32bit number (sample_t) into one of the bit resolution supported (audioBitResolutionT). | ||||
static void | fromBitToSampleConversion (const int8_t *const input, sample_t *output, const audioBitResolutionT sourceBitResolution) | |||
Convert a audioBitResolutionT bit resolution number into a 32bit number (sample_t). | ||||
Private Member Functions | ||||
void | setupClient () | |||
Private method to setup a client of the Jack server.
| ||||
void | createChannels () | |||
Creates input and output channels in the Jack client. | ||||
void | computeNetworkProcessFromNetwork () | |||
Sets the part of the process callback that sends and receive packets. | ||||
void | computeNetworkProcessToNetwork () | |||
Compute the process from JACK to send packets. | ||||
void | setProcessCallback () | |||
Set the process callback of the member function processCallback. This process will be called by the JACK server whenever there is work to be done. | ||||
int | processCallback (jack_nframes_t nframes) | |||
JACK process callback. | ||||
Static Private Member Functions | ||||
static void | jackShutdown (void *) | |||
JACK calls this shutdown_callback if the server ever shuts down or decides to disconnect the client. | ||||
static int | wrapperProcessCallback (jack_nframes_t nframes, void *arg) | |||
Wrapper to cast the member processCallback to a static function pointer that can be used with jack_set_process_callback | ||||
Private Attributes | ||||
int | mNumInChans | |||
Number of Input Channels. | ||||
int | mNumOutChans | |||
Number of Output Channels. | ||||
int | mNumFrames | |||
Buffer block size, in samples. | ||||
int | mAudioBitResolution | |||
Bit resolution in audio samples. | ||||
audioBitResolutionT | mBitResolutionMode | |||
Bit resolution (audioBitResolutionT) mode. | ||||
jack_client_t * | mClient | |||
Jack Client. | ||||
const char * | mClientName | |||
Jack Client Name. | ||||
QVarLengthArray< jack_port_t * > | mInPorts | |||
Vector of Input Ports (Channels). | ||||
QVarLengthArray< jack_port_t * > | mOutPorts | |||
Vector of Output Ports (Channels). | ||||
QVarLengthArray< sample_t * > | mInBuffer | |||
Vector of Input buffers/channel read from JACK. | ||||
QVarLengthArray< sample_t * > | mOutBuffer | |||
Vector of Output buffer/channel to write to JACK. | ||||
QVarLengthArray< sample_t * > | mInProcessBuffer | |||
Vector of Input buffers/channel for ProcessPlugin. | ||||
QVarLengthArray< sample_t * > | mOutProcessBuffer | |||
Vector of Output buffers/channel for ProcessPlugin. | ||||
int8_t * | mInputPacket | |||
Packet containing all the channels to read from the RingBuffer. | ||||
int8_t * | mOutputPacket | |||
Packet containing all the channels to send to the RingBuffer. | ||||
size_t | mSizeInBytesPerChannel | |||
Size in bytes per audio channel. | ||||
QVector< ProcessPlugin * > | mProcessPlugins | |||
Vector of ProcesPlugins | ||||
JackTrip * | mJackTrip | |||
JackTrip mediator class. | ||||
Static Private Attributes | ||||
static QMutex | sJackMutex | |||
Mutex to make thread safe jack functions that are not. |
Class that provides an interface with the Jack Audio Server.
implement srate_callback
automatically starts jack with buffer and sample rate settings specified by the user
Enum for Audio Resolution in bits.
JackAudioInterface::JackAudioInterface | ( | JackTrip * | jacktrip, | |
int | NumInChans, | |||
int | NumOutChans, | |||
audioBitResolutionT | AudioBitResolution = BIT16 , |
|||
const char * | ClientName = "JackTrip" | |||
) |
The class constructor.
jacktrip | Pointer to the JackTrip class that connects all classes (mediator) | |
NumInChans | Number of Input Channels | |
NumOutChans | Number of Output Channels | |
AudioBitResolution | Audio Sample Resolutions in bits | |
ClientName | Client name in Jack |
JackAudioInterface::~JackAudioInterface | ( | ) | [virtual] |
The class destructor.
void JackAudioInterface::appendProcessPlugin | ( | ProcessPlugin * | plugin | ) |
Set the pointer to the Input and Output RingBuffer that'll be use to read and write audio.
These RingBuffers are used to read and write audio samples on each JACK callback.
InRingBuffer | RingBuffer to read samples from | |
OutRingBuffer | RingBuffer to write samples toAppend a ProcessPlugin. The order of processing is determined by the order by which appending is done. | |
plugin | a ProcesPlugin smart pointer. Create the object instance using something like:std::tr1::shared_ptr<ProcessPluginName> loopback(new ProcessPluginName); |
void JackAudioInterface::computeNetworkProcessFromNetwork | ( | ) | [private] |
Sets the part of the process callback that sends and receive packets.
Compute the process to receive packets to JACK
void JackAudioInterface::computeNetworkProcessToNetwork | ( | ) | [private] |
Compute the process from JACK to send packets.
void JackAudioInterface::connectDefaultPorts | ( | ) |
Connect the default ports, capture to sends, and receives to playback.
void JackAudioInterface::createChannels | ( | ) | [private] |
Creates input and output channels in the Jack client.
void JackAudioInterface::fromBitToSampleConversion | ( | const int8_t *const | input, | |
sample_t * | output, | |||
const audioBitResolutionT | sourceBitResolution | |||
) | [static] |
Convert a audioBitResolutionT bit resolution number into a 32bit number (sample_t).
The result is stored in an sample_t array of the appropriate size to hold the value. The caller is responsible to allocate enough space to store the result.
void JackAudioInterface::fromSampleToBitConversion | ( | const sample_t *const | input, | |
int8_t * | output, | |||
const audioBitResolutionT | targetBitResolution | |||
) | [static] |
Convert a 32bit number (sample_t) into one of the bit resolution supported (audioBitResolutionT).
The result is stored in an int_8 array of the appropriate size to hold the value. The caller is responsible to allocate enough space to store the result.
int JackAudioInterface::getAudioBitResolution | ( | ) | const |
Get the Audio Bit Resolution, in bits.
This is one of the audioBitResolutionT set in construction
uint32_t JackAudioInterface::getBufferSizeInBytes | ( | ) | const [inline] |
Get the Jack Server Buffer Size, in bytes.
uint32_t JackAudioInterface::getBufferSizeInSamples | ( | ) | const |
Get the Jack Server Buffer Size, in samples.
int JackAudioInterface::getNumInputChannels | ( | ) | const |
Get Number of Input Channels.
int JackAudioInterface::getNumOutputChannels | ( | ) | const |
Get Number of Output Channels.
uint32_t JackAudioInterface::getSampleRate | ( | ) | const |
Get the Jack Server Sampling Rate, in samples/second.
int JackAudioInterface::getSampleRateFromType | ( | samplingRateT | rate_type | ) | [static] |
Helper function to get the sample rate (in Hz) for a JackAudioInterface::samplingRateT.
rate_type | JackAudioInterface::samplingRateT enum type |
JackAudioInterface::samplingRateT JackAudioInterface::getSampleRateType | ( | ) | const |
Get the Jack Server Sampling Rate Enum Type samplingRateT.
size_t JackAudioInterface::getSizeInBytesPerChannel | ( | ) | const |
Get size of each audio per channel, in bytes.
void JackAudioInterface::jackShutdown | ( | void * | ) | [static, private] |
JACK calls this shutdown_callback if the server ever shuts down or decides to disconnect the client.
int JackAudioInterface::processCallback | ( | jack_nframes_t | nframes | ) | [private] |
JACK process callback.
This is the function to be called to process audio. This function is of the type JackProcessCallback, which is defined as:
typedef int(* JackProcessCallback)(jack_nframes_t nframes, void *arg)
See http://jackaudio.org/files/docs/html/types_8h.html#4923142208a8e7dacf00ca7a10681d2b for more details
void JackAudioInterface::setClientName | ( | const char * | ClientName | ) | [inline] |
Set Client Name to something different that the default (JackTrip).
void JackAudioInterface::setProcessCallback | ( | ) | [private] |
Set the process callback of the member function processCallback. This process will be called by the JACK server whenever there is work to be done.
void JackAudioInterface::setup | ( | ) |
Setup the client.
void JackAudioInterface::setupClient | ( | ) | [private] |
Private method to setup a client of the Jack server.
std::runtime_error | Can't start Jack. |
This method is called by the class constructors. It does the following:
int JackAudioInterface::startProcess | ( | ) | const |
Tell the JACK server that we are ready to roll. The process-callback will start running. This runs on its own thread.
int JackAudioInterface::stopProcess | ( | ) | const |
Stops the process-callback thread.
int JackAudioInterface::wrapperProcessCallback | ( | jack_nframes_t | nframes, | |
void * | arg | |||
) | [static, private] |
Wrapper to cast the member processCallback to a static function pointer that can be used with jack_set_process_callback
jack_set_process_callback
needs a static member function pointer. A normal member function won't work because a this pointer is passed under the scenes. That's why we need to cast the member funcion processCallback to the static function wrapperProcessCallback. The callback is then set as:
jack_set_process_callback(mClient, JackAudioInterface::wrapperProcessCallback, this)
int JackAudioInterface::mAudioBitResolution [private] |
Bit resolution in audio samples.
Bit resolution (audioBitResolutionT) mode.
jack_client_t* JackAudioInterface::mClient [private] |
Jack Client.
const char* JackAudioInterface::mClientName [private] |
Jack Client Name.
QVarLengthArray<sample_t*> JackAudioInterface::mInBuffer [private] |
Vector of Input buffers/channel read from JACK.
QVarLengthArray<jack_port_t*> JackAudioInterface::mInPorts [private] |
Vector of Input Ports (Channels).
QVarLengthArray<sample_t*> JackAudioInterface::mInProcessBuffer [private] |
Vector of Input buffers/channel for ProcessPlugin.
int8_t* JackAudioInterface::mInputPacket [private] |
Packet containing all the channels to read from the RingBuffer.
JackTrip* JackAudioInterface::mJackTrip [private] |
JackTrip mediator class.
int JackAudioInterface::mNumFrames [private] |
Buffer block size, in samples.
int JackAudioInterface::mNumInChans [private] |
Number of Input Channels.
int JackAudioInterface::mNumOutChans [private] |
Number of Output Channels.
QVarLengthArray<sample_t*> JackAudioInterface::mOutBuffer [private] |
Vector of Output buffer/channel to write to JACK.
QVarLengthArray<jack_port_t*> JackAudioInterface::mOutPorts [private] |
Vector of Output Ports (Channels).
QVarLengthArray<sample_t*> JackAudioInterface::mOutProcessBuffer [private] |
Vector of Output buffers/channel for ProcessPlugin.
int8_t* JackAudioInterface::mOutputPacket [private] |
Packet containing all the channels to send to the RingBuffer.
QVector<ProcessPlugin*> JackAudioInterface::mProcessPlugins [private] |
Vector of ProcesPlugins
size_t JackAudioInterface::mSizeInBytesPerChannel [private] |
Size in bytes per audio channel.
QMutex JackAudioInterface::sJackMutex [static, private] |
Mutex to make thread safe jack functions that are not.