Async 1.8.0
Async::AudioLADSPAPlugin Class Reference

Use a LADSPA plugin as an audio processor. More...

#include <AsyncAudioLADSPAPlugin.h>

Inheritance diagram for Async::AudioLADSPAPlugin:
Async::AudioProcessor Async::AudioSink Async::AudioSource

Public Types

using PortNumber = decltype(LADSPA_Descriptor::PortCount)
 
using PluginIndex = unsigned long
 
using UniqueID = unsigned long
 

Public Member Functions

 AudioLADSPAPlugin (const std::string &path, PluginIndex index)
 Constructor.
 
 AudioLADSPAPlugin (UniqueID id)
 Constructor.
 
 AudioLADSPAPlugin (const std::string &label)
 Constructor.
 
 AudioLADSPAPlugin (const AudioLADSPAPlugin &)=delete
 Disallow copy construction.
 
AudioLADSPAPluginoperator= (const AudioLADSPAPlugin &)=delete
 Disallow copy assignment.
 
 ~AudioLADSPAPlugin (void)
 Destructor.
 
bool initialize (void)
 Initialize the plugin.
 
PortNumber findControlInputByName (const std::string &name)
 Find an input control port by name.
 
bool setControl (PortNumber portno, LADSPA_Data val)
 Set a control input to the given value.
 
void activate (void)
 Activate the plugin.
 
void deactivate (void)
 Deactivate the plugin.
 
std::string path (void) const
 Get the path to the plugin.
 
UniqueID uniqueId (void) const
 Get the unique ID for the plugin.
 
std::string label (void) const
 Get the unique label for the plugin.
 
std::string name (void) const
 Get the name of the plugin.
 
std::string maker (void) const
 Get information on the maker of the plugin.
 
std::string copyright (void) const
 Get the copyright information for the plugin.
 
PortNumber portCount (void) const
 Get the number of ports for the plugin.
 
bool portIsControl (PortNumber portno) const
 Check if a port is a control port.
 
bool portIsAudio (PortNumber portno) const
 Check if a port is an audio port.
 
bool portIsInput (PortNumber portno) const
 Check if a port is an input port.
 
bool portIsOutput (PortNumber portno) const
 Check if a port is an output port.
 
void print (const std::string &prefix="")
 Print some useful information for the plugin.
 
- Public Member Functions inherited from Async::AudioProcessor
 AudioProcessor (void)
 Default constuctor.
 
virtual ~AudioProcessor (void)
 Destructor.
 
int writeSamples (const float *samples, int len)
 Write audio to the filter.
 
void flushSamples (void)
 Order a flush of all samples.
 
void resumeOutput (void)
 Resume output to the sink if previously stopped.
 
void allSamplesFlushed (void)
 All samples have been flushed by the sink.
 
- Public Member Functions inherited from Async::AudioSink
 AudioSink (void)
 Default constuctor.
 
virtual ~AudioSink (void)
 Destructor.
 
bool registerSource (AudioSource *source)
 Register an audio source to provide samples to this sink.
 
void unregisterSource (void)
 Unregister the previously registered audio source.
 
bool isRegistered (void) const
 Check if an audio source has been registered.
 
AudioSourcesource (void) const
 Get the registered audio source.
 
- Public Member Functions inherited from Async::AudioSource
 AudioSource (void)
 Default constuctor.
 
virtual ~AudioSource (void)
 Destructor.
 
bool registerSink (AudioSink *sink, bool managed=false)
 Register an audio sink to provide samples to.
 
void unregisterSink (void)
 Unregister the previously registered audio sink.
 
bool isRegistered (void) const
 Check if an audio sink has been registered.
 
AudioSinksink (void) const
 Get the registered audio sink.
 
bool sinkManaged (void) const
 Check if the sink is managed or not.
 
void handleAllSamplesFlushed (void)
 The registered sink has flushed all samples.
 

Static Public Member Functions

static bool findPluginsInDir (std::string dir)
 Find any LADSPA plugins in the given subdirectory.
 
static bool findPlugins (void)
 Find LADSPA plugins in standard subdirectories.
 

Static Public Attributes

static constexpr PortNumber npos = std::numeric_limits<PortNumber>::max()
 

Protected Member Functions

virtual void processSamples (float *dest, const float *src, int count) override
 Process incoming samples and put them into the output buffer.
 
- Protected Member Functions inherited from Async::AudioProcessor
void setInputOutputSampleRate (int input_rate, int output_rate)
 Set the input and output sample rates.
 
- Protected Member Functions inherited from Async::AudioSink
void sourceResumeOutput (void)
 Tell the source that we are ready to accept more samples.
 
void sourceAllSamplesFlushed (void)
 Tell the source that all samples have been flushed.
 
bool setHandler (AudioSink *handler)
 Setup another sink to handle the incoming audio.
 
void clearHandler (void)
 Clear a handler that was previously setup with setHandler.
 
AudioSinkhandler (void) const
 
- Protected Member Functions inherited from Async::AudioSource
int sinkWriteSamples (const float *samples, int len)
 
void sinkFlushSamples (void)
 
bool setHandler (AudioSource *handler)
 Setup another source to handle the outgoing audio.
 
AudioSourcehandler (void) const
 
void clearHandler (void)
 Clear a handler that was previously setup with setHandler.
 

Detailed Description

Use a LADSPA plugin as an audio processor.

Author
Tobias Blomberg / SM0SVX
Date
2023-12-09

This class is used to load a LADSPA plugin and use it as an audio processor.

#include <iostream>
#include <AsyncAudioIO.h>
#include <AsyncFdWatch.h>
int main(void)
{
Async::AudioIO audio_io("alsa:default", 0);
audio_io.open(Async::AudioIO::MODE_RDWR);
Async::AudioSource* prev_src = &audio_io;
std::string label("tap_pitch");
if (!p1.initialize())
{
std::cout << "*** ERROR: Could not instantiate LADSPA plugin instance "
"with label " << label << std::endl;
exit(1);
}
p1.setControl(0, 4);
p1.print();
prev_src->registerSink(&p1);
prev_src = &p1;
label = "tap_vibrato";
if (!p2.initialize())
{
std::cout << "*** ERROR: Could not instantiate LADSPA plugin instance "
"with label " << label << std::endl;
exit(1);
}
p2.setControl(0, 10);
p2.setControl(1, 10);
p2.print();
prev_src->registerSink(&p2);
prev_src = &p2;
prev_src->registerSink(&audio_io);
app.exec();
return 0;
}
Contains a class for handling audio input/output to an audio device.
A class for using a LADSPA plugin as an audio processor.
The core class for writing asyncronous cpp applications.
Contains a watch for file descriptors.
A class for handling audio input/output to an audio device.
@ MODE_RDWR
Both read and write.
Use a LADSPA plugin as an audio processor.
The base class for an audio source.
bool registerSink(AudioSink *sink, bool managed=false)
Register an audio sink to provide samples to.
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
Examples
AsyncAudioLADSPAPlugin_demo.cpp.

Definition at line 125 of file AsyncAudioLADSPAPlugin.h.

Member Typedef Documentation

◆ PluginIndex

Definition at line 129 of file AsyncAudioLADSPAPlugin.h.

◆ PortNumber

using Async::AudioLADSPAPlugin::PortNumber = decltype(LADSPA_Descriptor::PortCount)

Definition at line 128 of file AsyncAudioLADSPAPlugin.h.

◆ UniqueID

using Async::AudioLADSPAPlugin::UniqueID = unsigned long

Definition at line 130 of file AsyncAudioLADSPAPlugin.h.

Constructor & Destructor Documentation

◆ AudioLADSPAPlugin() [1/4]

Async::AudioLADSPAPlugin::AudioLADSPAPlugin ( const std::string & path,
PluginIndex index )
inline

Constructor.

Parameters
pathThe full path of the plugin to load
indexThe index of the plugin to instantiate

This constructor is normally not used directly unless there is a special requirement to load a specific LADSPA plugin file with a known plugin index.

Definition at line 172 of file AsyncAudioLADSPAPlugin.h.

◆ AudioLADSPAPlugin() [2/4]

Async::AudioLADSPAPlugin::AudioLADSPAPlugin ( UniqueID id)

Constructor.

Parameters
idThe plugin unique id to look for

Use this constructor for creating a LADSPA plugin instance if you know its unique ID. The easiest way normally is to use the label to find the plugin.

◆ AudioLADSPAPlugin() [3/4]

Async::AudioLADSPAPlugin::AudioLADSPAPlugin ( const std::string & label)

Constructor.

Parameters
labelThe plugin label to look for

This is the main constructor for creating a LADSPA plugin instance.

◆ AudioLADSPAPlugin() [4/4]

Async::AudioLADSPAPlugin::AudioLADSPAPlugin ( const AudioLADSPAPlugin & )
delete

Disallow copy construction.

◆ ~AudioLADSPAPlugin()

Async::AudioLADSPAPlugin::~AudioLADSPAPlugin ( void )

Destructor.

Member Function Documentation

◆ activate()

void Async::AudioLADSPAPlugin::activate ( void )

Activate the plugin.

Use this function to activate this plugin. Activation is done in the initialize function so manual activation is normally not needed. Read more about plugin activation in the LADSPA documentation.

◆ copyright()

std::string Async::AudioLADSPAPlugin::copyright ( void ) const
inline

Get the copyright information for the plugin.

Returns
Returns a string describing the copyright

Definition at line 292 of file AsyncAudioLADSPAPlugin.h.

◆ deactivate()

void Async::AudioLADSPAPlugin::deactivate ( void )

Deactivate the plugin.

Use this function to deactivate this plugin. Read more about plugin activation in the LADSPA documentation.

◆ findControlInputByName()

PortNumber Async::AudioLADSPAPlugin::findControlInputByName ( const std::string & name)

Find an input control port by name.

Parameters
nameThe port namne to look for
Returns
Return the port number or "npos" if not found

◆ findPlugins()

static bool Async::AudioLADSPAPlugin::findPlugins ( void )
static

Find LADSPA plugins in standard subdirectories.

LADSPA plugins are typically installed in /usr/lib64/ladspa (on a 64 bit x86 system). This default value is adapted automatically to match the target system during compilation of the software.

If the LADSPA_PATH environment variable is set it will override the default path.

This function is called by the "label variant" of the constructor if the plugin index is empty.

◆ findPluginsInDir()

static bool Async::AudioLADSPAPlugin::findPluginsInDir ( std::string dir)
static

Find any LADSPA plugins in the given subdirectory.

Parameters
dirThe path to the directory to look in

This function will go through all files in the given subdirectory, reading any *.so files it can find and load them as LADSPA plugins. The plugins are not fully initialized in this process but rather just the necessary calls are made to extract enough information to determine if this is a plugin that is compatible with this class. Any plugin found to be usable is put in an index so that we later can find plugins using their label.

◆ initialize()

bool Async::AudioLADSPAPlugin::initialize ( void )

Initialize the plugin.

Returns
Return true on success or else false is returned

All loading, instantiation and initialization of the plugin is done in this function. The LADSPA activate call is called at the end of the function so it is directly ready to process audio when this function returns true. If the function returns false, it's not allowed to call any other functions so the object should be deleted as soon as possible.

Examples
AsyncAudioLADSPAPlugin_demo.cpp.

◆ label()

std::string Async::AudioLADSPAPlugin::label ( void ) const
inline

Get the unique label for the plugin.

Returns
Returns the unique label for the plugin

The label is what most often is used to find a specific plugin.

Definition at line 272 of file AsyncAudioLADSPAPlugin.h.

◆ maker()

std::string Async::AudioLADSPAPlugin::maker ( void ) const
inline

Get information on the maker of the plugin.

Returns
Returns a string describing the plugin author.

Definition at line 286 of file AsyncAudioLADSPAPlugin.h.

◆ name()

std::string Async::AudioLADSPAPlugin::name ( void ) const
inline

Get the name of the plugin.

Returns
Returns the name of the plugin

This function return the free text name/display name for the plugin.

Definition at line 280 of file AsyncAudioLADSPAPlugin.h.

◆ operator=()

AudioLADSPAPlugin & Async::AudioLADSPAPlugin::operator= ( const AudioLADSPAPlugin & )
delete

Disallow copy assignment.

◆ path()

std::string Async::AudioLADSPAPlugin::path ( void ) const
inline

Get the path to the plugin.

Returns
Returns the path to the plugin

Definition at line 256 of file AsyncAudioLADSPAPlugin.h.

◆ portCount()

PortNumber Async::AudioLADSPAPlugin::portCount ( void ) const
inline

Get the number of ports for the plugin.

Returns
Returns the total number of control/audio input/output ports

Definition at line 298 of file AsyncAudioLADSPAPlugin.h.

◆ portIsAudio()

bool Async::AudioLADSPAPlugin::portIsAudio ( PortNumber portno) const

Check if a port is an audio port.

Returns
Returns true if this is an audio port

◆ portIsControl()

bool Async::AudioLADSPAPlugin::portIsControl ( PortNumber portno) const

Check if a port is a control port.

Returns
Returns true if this is a control port

◆ portIsInput()

bool Async::AudioLADSPAPlugin::portIsInput ( PortNumber portno) const

Check if a port is an input port.

Returns
Returns true if this is an input port

◆ portIsOutput()

bool Async::AudioLADSPAPlugin::portIsOutput ( PortNumber portno) const

Check if a port is an output port.

Returns
Returns true if this is an output port

◆ print()

void Async::AudioLADSPAPlugin::print ( const std::string & prefix = "")

Print some useful information for the plugin.

Examples
AsyncAudioLADSPAPlugin_demo.cpp.

◆ processSamples()

virtual void Async::AudioLADSPAPlugin::processSamples ( float * dest,
const float * src,
int count )
overrideprotectedvirtual

Process incoming samples and put them into the output buffer.

Parameters
destDestination buffer
srcSource buffer
countNumber of samples in the source buffer

This function should be reimplemented by the inheriting class to do the actual processing of the incoming samples. All samples must be processed, otherwise they are lost and the output buffer will contain garbage.

Implements Async::AudioProcessor.

◆ setControl()

bool Async::AudioLADSPAPlugin::setControl ( PortNumber portno,
LADSPA_Data val )

Set a control input to the given value.

Parameters
portnoThe port number to set
valThe value to set
Examples
AsyncAudioLADSPAPlugin_demo.cpp.

◆ uniqueId()

UniqueID Async::AudioLADSPAPlugin::uniqueId ( void ) const
inline

Get the unique ID for the plugin.

Returns
Returns the unique ID of the plugin

All plugins have a unique ID which can be used to find it.

Definition at line 264 of file AsyncAudioLADSPAPlugin.h.

Member Data Documentation

◆ npos

PortNumber Async::AudioLADSPAPlugin::npos = std::numeric_limits<PortNumber>::max()
staticconstexpr

Definition at line 132 of file AsyncAudioLADSPAPlugin.h.


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