NAME

Audio::LADPSA::Plugin - Use ladpsa plugins from perl

SYNOPSIS

use Audio::LADSPA;

my (@plugin_classes) = Audio::LADPSA->plugins();

# or ...
my $plugin_class = Audio::LADSPA->plugin( label => "delay_5s", id => 1043);

my $plugin = $plugin_class->new($sample_rate);

DESCRIPTION

Audio::LADSPA::Plugin is a base class for LADSPA plugins. Default behaviour of the Audio::LADPSA module is to generate a subclass for each plugin found in LADSPA_PATH, using the Audio::LADSPA::LibraryLoader module.

You can use the Audio::LADSPA::Plugin classes to query the capabilities of the loaded plugin, and you can instantiate new objects from them to do some actual audio processing.

A list of all available classnames on your system can be retrieved from Audio::LADSPA->plugins(), or you can get one by label and / or id via Audio::LADSPA->plugin( %ARGS ).

Class Methods

These methods can all be used as class methods as well as object methods, So you can query plugins without creating a new instance, or query an object you've already created.

id

my $id = $plugin_class->id();

Returns the unique id of the plugin class, as reported by the plugin itself.

label

my $label = $plugin_class->label();

The short name of the plugin.

name

my $name = $plugin_class->name();

A more descriptive name of the plugin.

maker

my $maker = $plugin_class->maker();

The author of the plugin.

my $copy = $plugin_class->copyright();

The copyright message for the plugin.

port_count

my $num_ports = $plugin_class->port_count();

The number of input / output / audio / control ports for the plugin, added together.

is_realtime

if ($plugin_class->is_realtime()) {
    warn "This plugin uses realtime input";
}

From the LADSPA SDK: "Indicates that the plugin has a real-time dependency (e.g. listens to a MIDI device) and so its output must not be cached or subject to significant latency."

The Audio::LADSPA environment might not be fast enough for these kinds of plugins though. Report back to me if you can get it to do something interesting in real time.

is_inplace_broken

if ($plugin->is_inplace_broken()) {
   # connect plugin to seperate output buffer
}
else {
   # connect plugin to shared output buffer
}

Returns true if the plugin doesn't use the run_adding() method, so you should not connect it need to a shared buffer. See run_adding for more info.

is_hard_rt_capable

if ($plugin->is_hard_rt_capable) {
   # do something in realtime
}

Returns true if the plugin can be run in a realtime environment. Whether the Audio::LADSPA host is a realtime environment, probably depends on you hardware and the complexity of your plugin network. Let me know.

has_run

Returns true if the plugin has a run() method.

has_run_adding

Returns true if the plugin has a run_adding() method.

has_activate

Returns true if the plugin has an activate() method.

has_deactivate

Returns true if the plugin has an deactivate() method.

ports

my @ports = $plugin->ports();

Returns the names of all input/output ports for this plugin, ordered by port index.

port

my $port = $plugin->port($index);

Returns the name of an input/output port for the plugin given its index.

Constructor

new

my $plugin_object = $plugin_class->new($sample_rate);

# now do something interesting involving audio

Create a new plugin object of $plugin_class and set its sample rate to $sample_rate. Usually you will want to set all connected plugins to the same sample rate. Audio::LADSPA::Network objects will do this automatically for you.

Object Methods

The following methods involve connections to buffers, handling audio data etc.

connect

$plugin->connect( $port => $buffer);

Connects the $port to the Audio::LADSPA::Buffer $buffer. Returns true on success, false otherwise.

If the $plugin is part of an Audio::LADSPA::Network, use $network->connect() instead.

See also "connect" in Audio::LADPSA::Network and cb_connect.

disconnect

$plugin->disconnect( $port );

Disconnect a $port. See also "cb_disconnect".

get_buffer

my $buffer = $plugin->get_buffer( $port );

Returns the buffer connected to the specified port. Returns undef if not connected.

set

$plugin->set( $port => @values );

# eg..

$drum->set( Velocity => 10 );
$echo->set( Input    => 1, 1, 0, 0, -1, -1, 0, 0 );

Set the Audio::LADSPA::Buffer connected to the $port. See "set" in Audio::LADSPA::Buffer.

get

my @values = $plugin->get( $port );
my $value  = $plugin->get( $port );

# eg

@output = $sine_fcac->get('Output');

Get the data from the Audio::LADSPA::Buffer connected to the $port. See "get" in Audio::LADSPA::Buffer.

activate

$plugin->activate();

Signal that the plugin should get ready to run. Is called automatically when run or run_adding is called and the plugin is not active. Is ignored after the first call, except when deactivate() is called.

deactivate

$plugin->deactivate();

Signal that the plugin can stop. Calling deactivate() and then activate() should reset the plugin.

run

$plugin->run($num_samples);

Run the plugin for $num_samples samples. All ports should be connected to a buffer, and activate is called automatically if the plugin isn't active already.

Usually $plugin will read from all buffers connected to its input ports and write to all buffers connected to its output ports.

run_adding

$plugin->run_adding($num_samples);

Same as run() except that the plugin will add its output to the buffers connected to its output ports, instead of overwriting them. Use $plugin->has_run_adding() to check whether the plugin supports this mode.

run_adding_gain

$plugin->run_adding_gain($gain);

Set the output gain for the run_adding() method. Will throw an exception if the plugin has no run_adding() method. Check $plugin->has_run_adding().

SETTING CALLBACKS

To ease the creation of 'container' objects for Audio::LADSPA::Plugins, you can register a 'monitor' object that will recieve callbacks whenever certain methods are called on the plugin.

Please note that the monitor object should be kept in scope by the container; the reference counting for the $monitor object is NOT increased by calling $plugin->set_monitor($monitor). This is intentional; it allows the container to be the monitor, while still being DESTROYED when going out of scope (this means you don't have to worry about this when the container is the monitor; the Perl garbage collector will work as you would expect it to). See Audio::LASDPA::Network for an implementation.

set_monitor

$plugin->set_monitor($monitor);

Sets the $monitor object for $plugin. Use $plugin->set_monitor(undef) to remove a monitor object.

monitor

my $monitor = $plugin->monitor();

Returns the $monitor object for $plugin, or undef if there is no monitor set.

CALLBACK METHODS

In general, the callback methods will be called when the corresponing event is called, before any processing of the event is done. Some callback methods can return true or false indicating that the event should be processed or not. When a plugin has no monitor, or the callback is not implemented, the event is processed (the plugin acts as if the callback returned true).

The monitor object may implement the following methods:

cb_connect

$monitor->cb_connect( $plugin, $port, $buffer );

Will be called when $plugin->connect($port, $buffer) is called. If cb_connect returns false, the connection will not be made.

cb_disconnect

$monitor->cb_disconnect( $plugin, $port );

Will be called when $plugin->disconnect($port) is called.

SEE ALSO

Audio::LADSPA, Audio::LASDPA::Plugin::XS, Audio::LADSPA::Plugin::Perl.

COPYRIGHT AND LICENSE

Copyright (C) 2003 Joost Diepenmaat <joost AT hortus-mechanicus.net>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.