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) |
| AudioBus * | get_playback_bus (QByteArray name) const |
| AudioBus * | get_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 |
| AudioDevice & | audiodevice () |
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; }
| 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
| 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] |
| AudioBus* AudioDevice::get_capture_bus | ( | QByteArray | name | ) | const [inline] |
| 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()
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()
References AudioBus::get_name().
| QString AudioDevice::get_device_name | ( | ) | const |
| QString AudioDevice::get_device_longname | ( | ) | const |
| QString AudioDevice::get_driver_type | ( | ) | const |
| QStringList AudioDevice::get_available_drivers | ( | ) | const |
| uint AudioDevice::get_sample_rate | ( | ) | const |
| uint AudioDevice::get_bit_depth | ( | ) | const |
| nframes_t AudioDevice::get_buffer_size | ( | ) | const [inline] |
| 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.
References stopped().
Referenced by set_parameters().
| uint AudioDevice::capture_buses_count | ( | ) | const |
| uint AudioDevice::playback_buses_count | ( | ) | const |
| trav_time_t AudioDevice::get_cpu_time | ( | ) |
| 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!
| The | Client client which as been removed from the AudioDevice |
Referenced by remove_client().
| AudioDevice& audiodevice | ( | ) | [friend] |
A global function, used to get the AudioDevice instance. Due the nature of singletons, the AudioDevice intance will be created automatically!
1.5.5