JackTrip
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
JackAudioInterface Class Reference

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

#include <JackAudioInterface.h>

Collaboration diagram for JackAudioInterface:
Collaboration graph
[legend]

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.

Exceptions
std::runtime_errorCan't start Jack.

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_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

automatically starts jack with buffer and sample rate settings specified by the user

Member Enumeration Documentation

Enum for Audio Resolution in bits.

Todo:
implement this into the class, now it's using jack default of 32 bits
Enumerator:
BIT8 

8 bits

BIT16 

16 bits (default)

BIT24 

24 bits

BIT32 

32 bits

Sampling Rates supported by JACK.

Enumerator:
SR22 

22050 Hz

SR32 

32000 Hz

SR44 

44100 Hz

SR48 

48000 Hz

SR88 

88200 Hz

SR96 

96000 Hz

SR192 

192000 Hz

UNDEF 

Undefined.

Constructor & Destructor Documentation

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

The class constructor.

Parameters
jacktripPointer to the JackTrip class that connects all classes (mediator)
NumInChansNumber of Input Channels
NumOutChansNumber of Output Channels
AudioBitResolutionAudio Sample Resolutions in bits
ClientNameClient name in Jack
JackAudioInterface::~JackAudioInterface ( )
virtual

The class destructor.

Member Function Documentation

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.

Todo:
If the RingBuffer is blocked, the callback should stay on the last buffer, as in JackTrip (wavetable synth)
Parameters
InRingBufferRingBuffer to read samples from
OutRingBufferRingBuffer to write samples to Append a ProcessPlugin. The order of processing is determined by the order by which appending is done.
plugina ProcesPlugin smart pointer. Create the object instance using something like:
std::tr1::shared_ptr<ProcessPluginName> loopback(new ProcessPluginName);
Todo:
check that channels in ProcessPlugins are less or same that jack channels
void JackAudioInterface::computeNetworkProcessFromNetwork ( )
private

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

Compute the process to receive packets to JACK

Todo:
cast *mInBuffer[i] to the bit resolution
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.

Parameters
rate_typeJackAudioInterface::samplingRateT enum type
Returns
Sample Rate in Hz
JackAudioInterface::samplingRateT JackAudioInterface::getSampleRateType ( ) const

Get the Jack Server Sampling Rate Enum Type samplingRateT.

Returns
JackAudioInterface::samplingRateT enum type
size_t JackAudioInterface::getSizeInBytesPerChannel ( ) const

Get size of each audio per channel, in bytes.

void JackAudioInterface::jackShutdown ( void *  )
staticprivate

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

Todo:
Implement for more than one process plugin, now it just works propertely with one. do it chaining outputs to inputs in the buffers. May need a tempo buffer
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.

Exceptions
std::runtime_errorCan'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.
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.

Returns
0 on success, otherwise a non-zero error code
int JackAudioInterface::stopProcess ( ) const

Stops the process-callback thread.

Returns
0 on success, otherwise a non-zero error code
int JackAudioInterface::wrapperProcessCallback ( jack_nframes_t  nframes,
void *  arg 
)
staticprivate

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

int JackAudioInterface::mAudioBitResolution
private

Bit resolution in audio samples.

audioBitResolutionT JackAudioInterface::mBitResolutionMode
private

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
staticprivate

Mutex to make thread safe jack functions that are not.


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