JackAudioInterface Class Reference

Class that provides an interface with the Jack Audio Server. More...

#include <JackAudioInterface.h>

Inheritance diagram for JackAudioInterface:

Inheritance graph
[legend]
Collaboration diagram for JackAudioInterface:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 JackAudioInterface (JackTrip *jacktrip, int NumInChans, int NumOutChans, AudioInterface::audioBitResolutionT AudioBitResolution=AudioInterface::BIT16, const char *ClientName="JackTrip")
 The class constructor.
virtual ~JackAudioInterface ()
 The class destructor.
virtual void setup ()
 Setup the client.
virtual void close ()
 Close the client and disconnects it from a JACK server.
virtual uint32_t getSampleRate () const
 Get the Jack Server Sampling Rate, in samples/second.
virtual samplingRateT getSampleRateType () const
 Get the Jack Server Sampling Rate Enum Type samplingRateT.
virtual uint32_t getBufferSizeInSamples () const
 Get the Jack Server Buffer Size, in samples.
virtual uint32_t getBufferSizeInBytes () const
 Get the Jack Server Buffer Size, in bytes.
virtual size_t getSizeInBytesPerChannel () const
 Get size of each audio per channel, in bytes.
virtual 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.
virtual int stopProcess () const
 Stops the process-callback thread.
void connectDefaultPorts ()
 Set the pointer to the Input and Output RingBuffer that'll be use to read and write audio.
virtual 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.

Private Member Functions

void setupClient ()
 Private method to setup a client of the Jack server.
Exceptions:
std::runtime_error Can't start Jack.

void createChannels ()
 Creates input and output channels in the Jack client.
void setProcessCallback ()
 Sets the part of the process callback that sends and receive packets.
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.
AudioInterface::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_tmInputPacket
 Packet containing all the channels to read from the RingBuffer.
int8_tmOutputPacket
 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.
JackTripmJackTrip
 JackTrip mediator class.

Static Private Attributes

static QMutex sJackMutex
 Mutex to make thread safe jack functions that are not.


Detailed Description

Class that provides an interface with the Jack Audio Server.

Todo:
implement srate_callback
Todo:
automatically starts jack with buffer and sample rate settings specified by the user

Constructor & Destructor Documentation

JackAudioInterface::JackAudioInterface ( JackTrip jacktrip,
int  NumInChans,
int  NumOutChans,
AudioInterface::audioBitResolutionT  AudioBitResolution = AudioInterface::BIT16,
const char *  ClientName = "JackTrip" 
)

The class constructor.

Parameters:
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.


Member Function Documentation

void JackAudioInterface::setup (  )  [virtual]

Setup the client.

Implements AudioInterface.

void JackAudioInterface::close (  )  [virtual]

Close the client and disconnects it from a JACK server.

Implements AudioInterface.

uint32_t JackAudioInterface::getSampleRate (  )  const [virtual]

Get the Jack Server Sampling Rate, in samples/second.

Reimplemented from AudioInterface.

JackAudioInterface::samplingRateT JackAudioInterface::getSampleRateType (  )  const [virtual]

Get the Jack Server Sampling Rate Enum Type samplingRateT.

Returns:
JackAudioInterface::samplingRateT enum type

Implements AudioInterface.

int JackAudioInterface::getSampleRateFromType ( samplingRateT  rate_type  )  [static]

Helper function to get the sample rate (in Hz) for a JackAudioInterface::samplingRateT.

Parameters:
rate_type JackAudioInterface::samplingRateT enum type
Returns:
Sample Rate in Hz

uint32_t JackAudioInterface::getBufferSizeInSamples (  )  const [virtual]

Get the Jack Server Buffer Size, in samples.

Reimplemented from AudioInterface.

virtual uint32_t JackAudioInterface::getBufferSizeInBytes (  )  const [inline, virtual]

Get the Jack Server Buffer Size, in bytes.

size_t JackAudioInterface::getSizeInBytesPerChannel (  )  const [virtual]

Get size of each audio per channel, in bytes.

Reimplemented from AudioInterface.

int JackAudioInterface::startProcess (  )  const [virtual]

Tell the JACK server that we are ready to roll. The process-callback will start running. This runs on its own thread.

Returns:
0 on success, otherwise a non-zero error code

Implements AudioInterface.

int JackAudioInterface::stopProcess (  )  const [virtual]

Stops the process-callback thread.

Returns:
0 on success, otherwise a non-zero error code

Implements AudioInterface.

void JackAudioInterface::connectDefaultPorts (  )  [virtual]

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.

Todo:
If the RingBuffer is blocked, the callback should stay on the last buffer, as in JackTrip (wavetable synth)
Parameters:
InRingBuffer RingBuffer to read samples from
OutRingBuffer RingBuffer to write samples to Append 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); Connect the default ports, capture to sends, and receives to playback

Implements AudioInterface.

virtual void JackAudioInterface::setClientName ( const char *  ClientName  )  [inline, virtual]

Set Client Name to something different that the default (JackTrip).

Implements AudioInterface.

void JackAudioInterface::setupClient (  )  [private]

Private method to setup a client of the Jack server.

Exceptions:
std::runtime_error Can't start Jack.

This method is called by the class constructors. It does the following:

  • Connects to the JACK server
  • Sets the shutdown process callback
  • Creates the appropriate number of input and output channels

Todo:
Write better warning messages. This following line displays very verbose message, check how to desable them.

void JackAudioInterface::createChannels (  )  [private]

Creates input and output channels in the Jack client.

void JackAudioInterface::jackShutdown ( void *   )  [static, private]

JACK calls this shutdown_callback if the server ever shuts down or decides to disconnect the client.

void JackAudioInterface::setProcessCallback (  )  [private]

Sets the part of the process callback that sends and receive packets.

Compute the process to receive packets to JACK Compute the process from JACK to send packets 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 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

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)


Member Data Documentation

Number of Input Channels.

Reimplemented from AudioInterface.

Number of Output Channels.

Reimplemented from AudioInterface.

Buffer block size, in samples.

Bit resolution (audioBitResolutionT) mode.

Reimplemented from AudioInterface.

jack_client_t* JackAudioInterface::mClient [private]

Jack Client.

const char* JackAudioInterface::mClientName [private]

Jack Client Name.

QVarLengthArray<jack_port_t*> JackAudioInterface::mInPorts [private]

Vector of Input Ports (Channels).

QVarLengthArray<jack_port_t*> JackAudioInterface::mOutPorts [private]

Vector of Output Ports (Channels).

QVarLengthArray<sample_t*> JackAudioInterface::mInBuffer [private]

Vector of Input buffers/channel read from JACK.

QVarLengthArray<sample_t*> JackAudioInterface::mOutBuffer [private]

Vector of Output buffer/channel to write to JACK.

QVarLengthArray<sample_t*> JackAudioInterface::mInProcessBuffer [private]

Vector of Input buffers/channel for ProcessPlugin.

QVarLengthArray<sample_t*> JackAudioInterface::mOutProcessBuffer [private]

Vector of Output buffers/channel for ProcessPlugin.

Packet containing all the channels to read from the RingBuffer.

Packet containing all the channels to send to the RingBuffer.

Size in bytes per audio channel.

Reimplemented from AudioInterface.

Vector of ProcesPlugins.

Reimplemented from AudioInterface.

JackTrip mediator class.

Reimplemented from AudioInterface.

QMutex JackAudioInterface::sJackMutex [static, private]

Mutex to make thread safe jack functions that are not.


The documentation for this class was generated from the following files: