AudioDevice Class Reference

An Interface to the 'real' audio device, and the hearth of the libtraversoaudiobackend. More...

List of all members.

Signals

void stopped ()
void started ()
void driverParamsChanged ()
void bufferUnderRun ()
void clientRemoved (Client *)
void xrunStormDetected ()
void message (QString, int)

Public Member Functions

void set_parameters (int rate, nframes_t bufferSize, const QString &driverType, bool capture=true, bool playback=true, const QString &device="hw:0", const QString &ditherShape="None")
void add_client (Client *client)
void remove_client (Client *client)
void transport_start (Client *client)
void transport_stop (Client *client)
int transport_seek_to (Client *client, TimeRef location)
AudioBusget_playback_bus (QByteArray name) const
AudioBusget_capture_bus (QByteArray name) const
QStringList get_capture_buses_names () const
QStringList get_playback_buses_names () const
QString get_device_name () const
QString get_device_longname () const
QString get_driver_type () const
QStringList get_available_drivers () const
uint get_sample_rate () const
uint get_bit_depth () const
TimeRef get_buffer_latency ()
nframes_t get_buffer_size () const
void show_descriptors ()
void set_driver_properties (QHash< QString, QVariant > &properties)
int shutdown ()
uint capture_buses_count () const
uint playback_buses_count () const
trav_time_t get_cpu_time ()

Friends

class AlsaDriver
class PADriver
class Driver
class PulseAudioDriver
class AudioDeviceThread
AudioDeviceaudiodevice ()


Detailed Description

An Interface to the 'real' audio device, and the hearth of the libtraversoaudiobackend.

AudioDevice is accessed by the audiodevice() function. You need to first initialize the 'device' by calling AudioDevice::set_parameters(int rate, nframes_t bufferSize, QString driverType); This will initialize the real audiodevice in case of the Alsa driver, or connect to the jack deamon. In the latter case, the rate and bufferSize don't do anything, since they are provided by the jack itself

This class and/or related classes depend on RingBuffer, Tsar and FastDelegate which are found in libtraversocore. The signal/slot feature as supplied by Qt is also used, which makes the Qt dependency a bit deeper, though it shouldn't be to hard to get rid of it if you like to use the libtraversoaudiobackend in an application not using Qt, or if you don't want a dependency to Qt.

Using the audiobackend in an application is as simple as:

        #include <AudioDevice.h>
        
        main()
        {
                myApp = new MyApp();
                myApp->execute();
                return;
        }
                
        MyApp::MyApp() 
                : QApplication
        {       
                setup_audiobackend();
                connect_to_audiodevice();
        }
                
        
        void MyApp::setup_audiobackend()
        {
                int rate = 44100;
                int bufSize = 1024;
                QString driver = "ALSA";
                audiodevice().set_parameters(rate, bufSize, driver);
        }

The AudioDevice instance now has set up it's own audio thread, or uses the one created by jack. This thread will continuously run, and process the callback functions of the registered Client's

Connecting your application to the audiodevice is done by creating an instance of Client, and setting the right callback function. The Client is added to the audiodevice in a thread save way, without using any locking mechanisms.

        void MyApp::connect_to_audiodevice()
        {
                m_client = new Client("MyApplication");
                m_client->set_process_callback( MakeDelegate(this, &MyApp::process) );
                audiodevice().add_client(m_client);
        }

Finally, we want to do some processing in the process callback, e.g.

        int MyApp::process(nframes_t nframes)
        {
                AudioBus* captureBus = audiodevice().get_capture_bus("Capture 1");
                AudioBus* playbackBus = audiodevice().get_playback_bus("Playback 1");
                
                // Just copy the captured audio to the playback buses.
                for (int i=0; i<captureBuses->get_channel_count(); ++i) {
                        memcpy(captureBus->get_channel(i)->get_buffer(nframes), playbackBus->get_channel(i)->get_buffer(nframes), nframes); 
                }
                
                return 1;
        }

Member Function Documentation

void AudioDevice::set_parameters ( int  rate,
nframes_t  bufferSize,
const QString &  driverType,
bool  capture = true,
bool  playback = true,
const QString &  cardDevice = "hw:0",
const QString &  ditherShape = "None" 
)

This function is used to initialize the AudioDevice's audioThread with the supplied rate, bufferSize and driver type. In case the AudioDevice allready was configured, it will stop the AudioDeviceThread and emits the stopped() signal, re-inits the AlsaDriver with the new paramaters, when succesfull emits the driverParamsChanged() signal, restarts the AudioDeviceThread and emits the started() signal

Parameters:
rate The new sample rate, only used for the AlsaDriver
bufferSize The period buffer size, only used for the AlsaDriver
driverType The Driver Type, can be ALSA, Jack or the Null Driver

References driverParamsChanged(), shutdown(), and started().

void AudioDevice::add_client ( Client client  ) 

Adds the client into the audio processing chain in a Thread Save way

WARNING: This function assumes the Clients callback function is set to an existing objects function!

void AudioDevice::remove_client ( Client client  ) 

Removes the client into the audio processing chain in a Thread save way

The clientRemoved(Client* client); signal will be emited after succesfull removal from within the GUI Thread!

References clientRemoved().

AudioBus* AudioDevice::get_playback_bus ( QByteArray  name  )  const [inline]

Get the Playback AudioBus instance with name name.

You can use this for example in your callback function to get a Playback Bus, and mix audiodata into the Buses' buffers.

See also:
get_playback_buses_names(), AudioBus::get_buffer()
Parameters:
name The name of the Playback Bus
Returns:
An AudioBus if one exists with name name, 0 on failure

AudioBus* AudioDevice::get_capture_bus ( QByteArray  name  )  const [inline]

Get the Capture AudioBus instance with name name.

You can use this for example in your callback function to get a Capture Bus, and read the audiodata from the Buses' buffers.

See also:
AudioBus::get_buffer(), get_capture_buses_names()
Parameters:
name The name of the Capture Bus
Returns:
An AudioBus if one exists with name name, 0 on failure

QStringList AudioDevice::get_capture_buses_names (  )  const

Get the names of all the Capture Buses availble, use the names to get a Bus instance via get_capture_bus()

Returns:
A QStringList with all the Capture Buses names which are available, an empty list if no Buses are available.

References AudioBus::get_name().

QStringList AudioDevice::get_playback_buses_names (  )  const

Get the names of all the Playback Buses availble, use the names to get a Bus instance via get_playback_bus()

Returns:
A QStringList with all the PlayBack Buses names which are available, an empty list if no Buses are available.

References AudioBus::get_name().

QString AudioDevice::get_device_name (  )  const

Returns:
The short description of the 'real audio device'

QString AudioDevice::get_device_longname (  )  const

Returns:
The long description of the 'real audio device'

QString AudioDevice::get_driver_type (  )  const

Returns:
The currently used Driver type

QStringList AudioDevice::get_available_drivers (  )  const

Returns:
A list of supported Drivers

uint AudioDevice::get_sample_rate (  )  const

Returns:
The real audiodevices sample rate

Referenced by DiskIO::get_write_buffers_fill_status().

uint AudioDevice::get_bit_depth (  )  const

Returns:
The real bit depth, which is 32 bit float.... FIXME Need to get the real bitdepth as reported by the 'real audiodevice'

nframes_t AudioDevice::get_buffer_size (  )  const [inline]

Returns:
The period buffer size, as used by the Audio Driver.

void AudioDevice::show_descriptors (  ) 

Not yet implemented

int AudioDevice::shutdown (  ) 

Stops the AudioDevice's AudioThread, free's any related memory.

Use this to properly shut down the AudioDevice on application exit, or to explicitely release the real 'audiodevice'.

Use set_parameters() to reinitialize the audiodevice if you want to use it again.

Returns:
1 on succes, 0 on failure

References stopped().

Referenced by set_parameters().

uint AudioDevice::capture_buses_count (  )  const

Returns:
The amount of Capture Buses, 0 if no Capture Buses are available

uint AudioDevice::playback_buses_count (  )  const

Returns:
The amount of PlayBack Buses, 0 if no PlayBack Buses are available

trav_time_t AudioDevice::get_cpu_time (  ) 

Returns:
The cpu load, call this at least 1 time per second to keep data consistent

void AudioDevice::stopped (  )  [signal]

The stopped() signal is emited just before the AudioDeviceThread will be stopped. Connect this signal to all Objects that have a pointer to an AudioBus (For example a VU meter), since all he Buses will be deleted, and new ones created when the AudioDevice re-inits the AudioDriver.

Referenced by shutdown().

void AudioDevice::started (  )  [signal]

The started() signal is emited ones the AudioThread and AudioDriver have been succesfully setup.

Referenced by set_parameters().

void AudioDevice::driverParamsChanged (  )  [signal]

The driverParamsChanged() signal is emited just before the started() signal, you should connect all objects to this signal who need a pointer to one of the AudioBuses supplied by the AudioDevice!

Referenced by set_parameters().

void AudioDevice::bufferUnderRun (  )  [signal]

Connect this signal to any Object who need to be informed about buffer under/overruns

void AudioDevice::clientRemoved ( Client _t1  )  [signal]

This signal will be emited after succesfull Client removal from within the GUI Thread!

Parameters:
The Client client which as been removed from the AudioDevice

Referenced by remove_client().


Friends And Related Function Documentation

AudioDevice& audiodevice (  )  [friend]

A global function, used to get the AudioDevice instance. Due the nature of singletons, the AudioDevice intance will be created automatically!

Returns:
The AudioDevice instance, it will be automatically created on first call


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

Generated on Sun Mar 8 12:44:05 2009 for traverso by  doxygen 1.5.5