2001-12-23 15:26:43 +00:00
|
|
|
/* GStreamer
|
2007-01-28 17:35:13 +00:00
|
|
|
* Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2001 Steve Baker <stevebaker_org@yahoo.co.uk>
|
2003-12-04 10:37:38 +00:00
|
|
|
* 2003 Andy Wingo <wingo at pobox.com>
|
2001-12-23 15:26:43 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-11-06 23:36:33 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-23 15:26:43 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
2003-07-19 23:25:25 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2007-01-28 17:35:13 +00:00
|
|
|
#include <gst/controller/gstcontroller.h>
|
2001-12-23 15:26:43 +00:00
|
|
|
|
|
|
|
#include "gstladspa.h"
|
2004-03-15 19:32:27 +00:00
|
|
|
#include <ladspa.h> /* main ladspa sdk include file */
|
|
|
|
#include "utils.h" /* ladspa sdk utility functions */
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2003-12-04 10:37:38 +00:00
|
|
|
/* 1.0 and the 1.1 preliminary headers don't define a version, but 1.1 final
|
|
|
|
does */
|
|
|
|
#ifndef LADSPA_VERSION
|
|
|
|
#define LADSPA_VERSION "1.0"
|
|
|
|
#endif
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2008-02-04 19:15:39 +00:00
|
|
|
#define GST_LADSPA_DESCRIPTOR_QDATA g_quark_from_static_string("ladspa-descriptor")
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_ladspa_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_ladspa_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-25 09:30:24 +00:00
|
|
|
static gboolean gst_ladspa_setup (GstSignalProcessor * sigproc,
|
2005-08-26 11:05:13 +00:00
|
|
|
guint sample_rate);
|
|
|
|
static gboolean gst_ladspa_start (GstSignalProcessor * sigproc);
|
|
|
|
static void gst_ladspa_stop (GstSignalProcessor * sigproc);
|
|
|
|
static void gst_ladspa_cleanup (GstSignalProcessor * sigproc);
|
|
|
|
static void gst_ladspa_process (GstSignalProcessor * sigproc, guint nframes);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2008-02-04 19:15:39 +00:00
|
|
|
static GstSignalProcessorClass *parent_class;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
|
|
|
static GstPlugin *ladspa_plugin;
|
2003-07-19 23:25:25 +00:00
|
|
|
|
2003-07-16 16:08:13 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (ladspa_debug);
|
2004-04-05 17:32:43 +00:00
|
|
|
#define GST_CAT_DEFAULT ladspa_debug
|
2002-01-22 04:42:11 +00:00
|
|
|
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2003-11-02 13:55:40 +00:00
|
|
|
static void
|
2005-08-26 11:05:13 +00:00
|
|
|
gst_ladspa_base_init (gpointer g_class)
|
2003-11-02 13:55:40 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
GstLADSPAClass *klass = (GstLADSPAClass *) g_class;
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
GstSignalProcessorClass *gsp_class = GST_SIGNAL_PROCESSOR_CLASS (g_class);
|
2003-11-02 13:55:40 +00:00
|
|
|
GstElementDetails *details;
|
|
|
|
LADSPA_Descriptor *desc;
|
2007-01-31 08:16:59 +00:00
|
|
|
guint j, audio_in_count, audio_out_count, control_in_count, control_out_count;
|
2003-11-02 13:55:40 +00:00
|
|
|
|
2005-08-28 17:59:20 +00:00
|
|
|
GST_DEBUG ("base_init %p", g_class);
|
|
|
|
|
2008-02-04 19:15:39 +00:00
|
|
|
desc = (LADSPA_Descriptor *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
GST_LADSPA_DESCRIPTOR_QDATA);
|
2003-11-02 23:58:20 +00:00
|
|
|
g_assert (desc);
|
2005-08-26 11:05:13 +00:00
|
|
|
klass->descriptor = desc;
|
2003-11-02 13:55:40 +00:00
|
|
|
|
|
|
|
/* pad templates */
|
2005-08-25 09:30:24 +00:00
|
|
|
gsp_class->num_audio_in = 0;
|
|
|
|
gsp_class->num_audio_out = 0;
|
2007-01-31 08:16:59 +00:00
|
|
|
/* properties */
|
|
|
|
gsp_class->num_control_in = 0;
|
|
|
|
gsp_class->num_control_out = 0;
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (j = 0; j < desc->PortCount; j++) {
|
2005-08-25 09:30:24 +00:00
|
|
|
LADSPA_PortDescriptor p = desc->PortDescriptors[j];
|
|
|
|
|
|
|
|
if (LADSPA_IS_PORT_AUDIO (p)) {
|
2004-03-14 22:34:33 +00:00
|
|
|
gchar *name = g_strdup ((gchar *) desc->PortNames[j]);
|
|
|
|
|
2008-03-20 15:54:23 +00:00
|
|
|
/* FIXME: group stereo pairs into a stereo pad
|
|
|
|
* ladspa-fx have "XXX (Left)" and "XXX (Right)"
|
|
|
|
* where XXX={In,Input,Out,Output}
|
|
|
|
*/
|
|
|
|
|
2006-08-16 15:33:12 +00:00
|
|
|
GST_DEBUG ("LADSPA port name: \"%s\"", name);
|
2008-03-20 15:54:23 +00:00
|
|
|
/* replaces all spaces with underscores, and then remaining special chars
|
|
|
|
* with '-'
|
|
|
|
* FIXME: why, pads can have any name
|
|
|
|
*/
|
2006-08-16 15:33:12 +00:00
|
|
|
g_strdelimit (name, " ", '_');
|
|
|
|
g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "_-><=", '-');
|
|
|
|
GST_DEBUG ("GStreamer pad name: \"%s\"", name);
|
2003-11-02 13:55:40 +00:00
|
|
|
|
2005-08-25 09:30:24 +00:00
|
|
|
if (LADSPA_IS_PORT_INPUT (p))
|
2005-08-26 11:05:13 +00:00
|
|
|
gst_signal_processor_class_add_pad_template (gsp_class, name,
|
|
|
|
GST_PAD_SINK, gsp_class->num_audio_in++);
|
2005-08-25 09:30:24 +00:00
|
|
|
else
|
2005-08-26 11:05:13 +00:00
|
|
|
gst_signal_processor_class_add_pad_template (gsp_class, name,
|
|
|
|
GST_PAD_SRC, gsp_class->num_audio_out++);
|
2007-08-16 07:07:41 +00:00
|
|
|
|
|
|
|
g_free (name);
|
2007-01-31 08:16:59 +00:00
|
|
|
} else if (LADSPA_IS_PORT_CONTROL (p)) {
|
|
|
|
if (LADSPA_IS_PORT_INPUT (p))
|
|
|
|
gsp_class->num_control_in++;
|
|
|
|
else
|
|
|
|
gsp_class->num_control_out++;
|
2003-11-02 13:55:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-12 18:18:51 +00:00
|
|
|
/* construct the element details struct */
|
2004-03-14 22:34:33 +00:00
|
|
|
details = g_new0 (GstElementDetails, 1);
|
2004-07-19 21:44:49 +00:00
|
|
|
details->longname = g_locale_to_utf8 (desc->Name, -1, NULL, NULL, NULL);
|
|
|
|
if (!details->longname)
|
|
|
|
details->longname = g_strdup ("no description available");
|
2004-02-12 18:18:51 +00:00
|
|
|
details->description = details->longname;
|
2004-07-19 21:44:49 +00:00
|
|
|
details->author = g_locale_to_utf8 (desc->Maker, -1, NULL, NULL, NULL);
|
|
|
|
if (!details->author)
|
|
|
|
details->author = g_strdup ("no author available");
|
2007-01-31 08:16:59 +00:00
|
|
|
|
2005-08-25 09:30:24 +00:00
|
|
|
if (gsp_class->num_audio_in == 0)
|
2004-03-14 22:34:33 +00:00
|
|
|
details->klass = "Source/Audio/LADSPA";
|
2007-01-31 08:16:59 +00:00
|
|
|
else if (gsp_class->num_audio_out == 0) {
|
|
|
|
if (gsp_class->num_control_out == 0)
|
|
|
|
details->klass = "Sink/Audio/LADSPA";
|
|
|
|
else
|
|
|
|
details->klass = "Sink/Analyzer/Audio/LADSPA";
|
|
|
|
} else
|
2005-08-25 09:30:24 +00:00
|
|
|
details->klass = "Filter/Effect/Audio/LADSPA";
|
2004-02-12 18:18:51 +00:00
|
|
|
gst_element_class_set_details (element_class, details);
|
2007-08-16 07:07:41 +00:00
|
|
|
g_free (details->longname);
|
|
|
|
g_free (details->author);
|
|
|
|
g_free (details);
|
|
|
|
|
2004-02-12 18:18:51 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
klass->audio_in_portnums = g_new0 (gint, gsp_class->num_audio_in);
|
2005-08-25 09:30:24 +00:00
|
|
|
klass->audio_out_portnums = g_new0 (gint, gsp_class->num_audio_out);
|
2007-01-31 08:16:59 +00:00
|
|
|
klass->control_in_portnums = g_new0 (gint, gsp_class->num_control_in);
|
|
|
|
klass->control_out_portnums = g_new0 (gint, gsp_class->num_control_out);
|
|
|
|
|
|
|
|
audio_in_count = audio_out_count = control_in_count = control_out_count = 0;
|
2003-11-02 13:55:40 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (j = 0; j < desc->PortCount; j++) {
|
2007-01-31 08:16:59 +00:00
|
|
|
LADSPA_PortDescriptor p = desc->PortDescriptors[j];
|
|
|
|
|
|
|
|
if (LADSPA_IS_PORT_AUDIO (p)) {
|
|
|
|
if (LADSPA_IS_PORT_INPUT (p))
|
|
|
|
klass->audio_in_portnums[audio_in_count++] = j;
|
2003-11-02 13:55:40 +00:00
|
|
|
else
|
2007-01-31 08:16:59 +00:00
|
|
|
klass->audio_out_portnums[audio_out_count++] = j;
|
|
|
|
} else if (LADSPA_IS_PORT_CONTROL (p)) {
|
|
|
|
if (LADSPA_IS_PORT_INPUT (p))
|
|
|
|
klass->control_in_portnums[control_in_count++] = j;
|
|
|
|
else
|
|
|
|
klass->control_out_portnums[control_out_count++] = j;
|
2003-11-02 13:55:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-31 08:16:59 +00:00
|
|
|
g_assert (audio_in_count == gsp_class->num_audio_in);
|
|
|
|
g_assert (audio_out_count == gsp_class->num_audio_out);
|
|
|
|
g_assert (control_in_count == gsp_class->num_control_in);
|
|
|
|
g_assert (control_out_count == gsp_class->num_control_out);
|
|
|
|
|
2006-08-04 11:38:54 +00:00
|
|
|
if (!LADSPA_IS_INPLACE_BROKEN (desc->Properties))
|
|
|
|
GST_SIGNAL_PROCESSOR_CLASS_SET_CAN_PROCESS_IN_PLACE (klass);
|
|
|
|
|
2003-11-02 13:55:40 +00:00
|
|
|
klass->descriptor = desc;
|
|
|
|
}
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
static gchar *
|
|
|
|
gst_ladspa_class_get_param_name (GstLADSPAClass * klass, gint portnum)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
|
|
|
LADSPA_Descriptor *desc;
|
2005-08-26 11:05:13 +00:00
|
|
|
gchar *ret, *paren;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
desc = klass->descriptor;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
ret = g_strdup (desc->PortNames[portnum]);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
paren = g_strrstr (ret, " (");
|
|
|
|
if (paren != NULL)
|
|
|
|
*paren = '\0';
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
/* this is the same thing that param_spec_* will do */
|
|
|
|
g_strcanon (ret, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
|
|
|
|
/* satisfy glib2 (argname[0] must be [A-Za-z]) */
|
|
|
|
if (!((ret[0] >= 'a' && ret[0] <= 'z') || (ret[0] >= 'A' && ret[0] <= 'Z'))) {
|
|
|
|
gchar *tempstr = ret;
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
ret = g_strconcat ("param-", ret, NULL);
|
|
|
|
g_free (tempstr);
|
|
|
|
}
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
/* check for duplicate property names */
|
|
|
|
if (g_object_class_find_property (G_OBJECT_CLASS (klass), ret)) {
|
|
|
|
gint n = 1;
|
|
|
|
gchar *nret = g_strdup_printf ("%s-%d", ret, n++);
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2007-08-16 07:07:41 +00:00
|
|
|
g_free (ret);
|
2005-08-26 11:05:13 +00:00
|
|
|
while (g_object_class_find_property (G_OBJECT_CLASS (klass), nret)) {
|
|
|
|
g_free (nret);
|
|
|
|
nret = g_strdup_printf ("%s-%d", ret, n++);
|
2005-08-25 09:30:24 +00:00
|
|
|
}
|
2005-08-26 11:05:13 +00:00
|
|
|
ret = nret;
|
2005-08-25 09:30:24 +00:00
|
|
|
}
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
static GParamSpec *
|
|
|
|
gst_ladspa_class_get_param_spec (GstLADSPAClass * klass, gint portnum)
|
|
|
|
{
|
|
|
|
LADSPA_Descriptor *desc;
|
|
|
|
GParamSpec *ret;
|
|
|
|
gchar *name;
|
|
|
|
gint hintdesc, perms;
|
|
|
|
gfloat lower, upper, def;
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
desc = klass->descriptor;
|
2005-08-25 09:30:24 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
name = gst_ladspa_class_get_param_name (klass, portnum);
|
|
|
|
perms = G_PARAM_READABLE;
|
|
|
|
if (LADSPA_IS_PORT_INPUT (desc->PortDescriptors[portnum]))
|
2005-08-28 17:59:20 +00:00
|
|
|
perms |= G_PARAM_WRITABLE | G_PARAM_CONSTRUCT;
|
2007-01-28 17:35:13 +00:00
|
|
|
if (LADSPA_IS_PORT_CONTROL (desc->PortDescriptors[portnum]))
|
|
|
|
perms |= GST_PARAM_CONTROLLABLE;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
/* short name for hint descriptor */
|
|
|
|
hintdesc = desc->PortRangeHints[portnum].HintDescriptor;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (LADSPA_IS_HINT_TOGGLED (hintdesc)) {
|
|
|
|
ret = g_param_spec_boolean (name, name, name, FALSE, perms);
|
|
|
|
g_free (name);
|
|
|
|
return ret;
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (LADSPA_IS_HINT_BOUNDED_BELOW (hintdesc))
|
|
|
|
lower = desc->PortRangeHints[portnum].LowerBound;
|
|
|
|
else
|
|
|
|
lower = -G_MAXFLOAT;
|
2003-07-16 16:08:13 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (LADSPA_IS_HINT_BOUNDED_ABOVE (hintdesc))
|
|
|
|
upper = desc->PortRangeHints[portnum].UpperBound;
|
|
|
|
else
|
|
|
|
upper = G_MAXFLOAT;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (LADSPA_IS_HINT_SAMPLE_RATE (hintdesc)) {
|
|
|
|
/* FIXME! */
|
|
|
|
lower *= 44100;
|
|
|
|
upper *= 44100;
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (LADSPA_IS_HINT_INTEGER (hintdesc)) {
|
|
|
|
lower = CLAMP (lower, G_MININT, G_MAXINT);
|
|
|
|
upper = CLAMP (upper, G_MININT, G_MAXINT);
|
|
|
|
}
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
/* default to lower bound */
|
|
|
|
def = lower;
|
2002-07-24 18:32:00 +00:00
|
|
|
|
|
|
|
#ifdef LADSPA_IS_HINT_HAS_DEFAULT
|
2005-08-26 11:05:13 +00:00
|
|
|
if (LADSPA_IS_HINT_HAS_DEFAULT (hintdesc)) {
|
|
|
|
if (LADSPA_IS_HINT_DEFAULT_0 (hintdesc))
|
|
|
|
def = 0.0;
|
|
|
|
else if (LADSPA_IS_HINT_DEFAULT_1 (hintdesc))
|
|
|
|
def = 1.0;
|
|
|
|
else if (LADSPA_IS_HINT_DEFAULT_100 (hintdesc))
|
|
|
|
def = 100.0;
|
|
|
|
else if (LADSPA_IS_HINT_DEFAULT_440 (hintdesc))
|
|
|
|
def = 440.0;
|
|
|
|
if (LADSPA_IS_HINT_DEFAULT_MINIMUM (hintdesc))
|
|
|
|
def = lower;
|
|
|
|
else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM (hintdesc))
|
|
|
|
def = upper;
|
|
|
|
else if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) {
|
|
|
|
if (LADSPA_IS_HINT_DEFAULT_LOW (hintdesc))
|
|
|
|
def = exp (0.75 * log (lower) + 0.25 * log (upper));
|
2002-07-24 18:32:00 +00:00
|
|
|
else if (LADSPA_IS_HINT_DEFAULT_MIDDLE (hintdesc))
|
2005-08-26 11:05:13 +00:00
|
|
|
def = exp (0.5 * log (lower) + 0.5 * log (upper));
|
2002-07-24 18:32:00 +00:00
|
|
|
else if (LADSPA_IS_HINT_DEFAULT_HIGH (hintdesc))
|
2005-08-26 11:05:13 +00:00
|
|
|
def = exp (0.25 * log (lower) + 0.75 * log (upper));
|
|
|
|
} else {
|
|
|
|
if (LADSPA_IS_HINT_DEFAULT_LOW (hintdesc))
|
|
|
|
def = 0.75 * lower + 0.25 * upper;
|
|
|
|
else if (LADSPA_IS_HINT_DEFAULT_MIDDLE (hintdesc))
|
|
|
|
def = 0.5 * lower + 0.5 * upper;
|
|
|
|
else if (LADSPA_IS_HINT_DEFAULT_HIGH (hintdesc))
|
|
|
|
def = 0.25 * lower + 0.75 * upper;
|
2002-07-24 18:32:00 +00:00
|
|
|
}
|
2005-08-26 11:05:13 +00:00
|
|
|
}
|
2002-07-24 18:32:00 +00:00
|
|
|
#endif /* LADSPA_IS_HINT_HAS_DEFAULT */
|
2002-09-20 21:51:50 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (lower > upper) {
|
|
|
|
gfloat tmp;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
/* silently swap */
|
|
|
|
tmp = lower;
|
|
|
|
lower = upper;
|
|
|
|
upper = tmp;
|
|
|
|
}
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
def = CLAMP (def, lower, upper);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (LADSPA_IS_HINT_INTEGER (hintdesc)) {
|
|
|
|
ret = g_param_spec_int (name, name, name, lower, upper, def, perms);
|
|
|
|
} else {
|
|
|
|
ret = g_param_spec_float (name, name, name, lower, upper, def, perms);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
g_free (name);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
return ret;
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-02-04 19:15:39 +00:00
|
|
|
gst_ladspa_class_init (GstLADSPAClass * klass, LADSPA_Descriptor * desc)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstSignalProcessorClass *gsp_class;
|
2007-01-31 08:16:59 +00:00
|
|
|
gint i;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-28 17:59:20 +00:00
|
|
|
GST_DEBUG ("class_init %p", klass);
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gobject_class->set_property = gst_ladspa_set_property;
|
|
|
|
gobject_class->get_property = gst_ladspa_get_property;
|
2002-09-16 05:38:53 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
gsp_class = GST_SIGNAL_PROCESSOR_CLASS (klass);
|
|
|
|
gsp_class->setup = gst_ladspa_setup;
|
|
|
|
gsp_class->start = gst_ladspa_start;
|
|
|
|
gsp_class->stop = gst_ladspa_stop;
|
|
|
|
gsp_class->cleanup = gst_ladspa_cleanup;
|
|
|
|
gsp_class->process = gst_ladspa_process;
|
2002-01-22 04:42:11 +00:00
|
|
|
|
2007-01-31 08:16:59 +00:00
|
|
|
/* register properties */
|
2002-04-20 13:57:00 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
for (i = 0; i < gsp_class->num_control_in; i++) {
|
|
|
|
GParamSpec *p;
|
|
|
|
|
|
|
|
p = gst_ladspa_class_get_param_spec (klass, klass->control_in_portnums[i]);
|
|
|
|
|
|
|
|
/* properties have an offset of 1 */
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), i + 1, p);
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
for (i = 0; i < gsp_class->num_control_out; i++) {
|
|
|
|
GParamSpec *p;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
p = gst_ladspa_class_get_param_spec (klass, klass->control_out_portnums[i]);
|
|
|
|
|
|
|
|
/* properties have an offset of 1, and we already added num_control_in */
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
|
|
|
gsp_class->num_control_in + i + 1, p);
|
|
|
|
}
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
2003-07-16 16:08:13 +00:00
|
|
|
static void
|
2005-08-28 17:59:20 +00:00
|
|
|
gst_ladspa_init (GstLADSPA * ladspa, GstLADSPAClass * klass)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
/* whoopee, nothing to do */
|
2002-01-22 04:42:11 +00:00
|
|
|
|
2005-08-28 17:59:20 +00:00
|
|
|
ladspa->descriptor = klass->descriptor;
|
2005-08-26 11:05:13 +00:00
|
|
|
ladspa->activated = FALSE;
|
|
|
|
ladspa->inplace_broken =
|
|
|
|
LADSPA_IS_INPLACE_BROKEN (ladspa->descriptor->Properties);
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ladspa_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
GstSignalProcessor *gsp;
|
|
|
|
GstSignalProcessorClass *gsp_class;
|
2003-07-19 23:25:25 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
gsp = GST_SIGNAL_PROCESSOR (object);
|
|
|
|
gsp_class = GST_SIGNAL_PROCESSOR_GET_CLASS (object);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2003-07-16 16:08:13 +00:00
|
|
|
/* remember, properties have an offset of 1 */
|
|
|
|
prop_id--;
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
/* only input ports */
|
|
|
|
g_return_if_fail (prop_id < gsp_class->num_control_in);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2002-01-22 04:42:11 +00:00
|
|
|
/* now see what type it is */
|
2005-08-26 11:05:13 +00:00
|
|
|
switch (pspec->value_type) {
|
|
|
|
case G_TYPE_BOOLEAN:
|
|
|
|
gsp->control_in[prop_id] = g_value_get_boolean (value) ? 1.f : 0.f;
|
|
|
|
break;
|
|
|
|
case G_TYPE_INT:
|
|
|
|
gsp->control_in[prop_id] = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case G_TYPE_FLOAT:
|
|
|
|
gsp->control_in[prop_id] = g_value_get_float (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ladspa_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
GstSignalProcessor *gsp;
|
|
|
|
GstSignalProcessorClass *gsp_class;
|
|
|
|
gfloat *controls;
|
|
|
|
|
|
|
|
gsp = GST_SIGNAL_PROCESSOR (object);
|
|
|
|
gsp_class = GST_SIGNAL_PROCESSOR_GET_CLASS (object);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2003-07-16 16:08:13 +00:00
|
|
|
/* remember, properties have an offset of 1 */
|
|
|
|
prop_id--;
|
2002-01-22 04:42:11 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (prop_id < gsp_class->num_control_in) {
|
|
|
|
controls = gsp->control_in;
|
|
|
|
} else if (prop_id < gsp_class->num_control_in + gsp_class->num_control_out) {
|
|
|
|
controls = gsp->control_out;
|
|
|
|
prop_id -= gsp_class->num_control_in;
|
|
|
|
} else {
|
2007-12-29 17:31:49 +00:00
|
|
|
g_return_if_reached ();
|
2005-08-26 11:05:13 +00:00
|
|
|
}
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2002-01-22 04:42:11 +00:00
|
|
|
/* now see what type it is */
|
2005-08-26 11:05:13 +00:00
|
|
|
switch (pspec->value_type) {
|
|
|
|
case G_TYPE_BOOLEAN:
|
|
|
|
g_value_set_boolean (value, controls[prop_id] > 0.5);
|
|
|
|
break;
|
|
|
|
case G_TYPE_INT:
|
|
|
|
g_value_set_int (value, CLAMP (controls[prop_id], G_MININT, G_MAXINT));
|
|
|
|
break;
|
|
|
|
case G_TYPE_FLOAT:
|
|
|
|
g_value_set_float (value, controls[prop_id]);
|
|
|
|
break;
|
|
|
|
default:
|
2007-12-29 17:31:49 +00:00
|
|
|
g_return_if_reached ();
|
2005-08-26 11:05:13 +00:00
|
|
|
}
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2005-08-26 11:05:13 +00:00
|
|
|
gst_ladspa_setup (GstSignalProcessor * gsp, guint sample_rate)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
GstLADSPA *ladspa;
|
|
|
|
GstLADSPAClass *oclass;
|
|
|
|
GstSignalProcessorClass *gsp_class;
|
2001-12-23 15:26:43 +00:00
|
|
|
LADSPA_Descriptor *desc;
|
|
|
|
int i;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
gsp_class = GST_SIGNAL_PROCESSOR_GET_CLASS (gsp);
|
|
|
|
ladspa = (GstLADSPA *) gsp;
|
|
|
|
oclass = (GstLADSPAClass *) gsp_class;
|
2001-12-23 15:26:43 +00:00
|
|
|
desc = ladspa->descriptor;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
g_return_val_if_fail (ladspa->handle == NULL, FALSE);
|
|
|
|
g_return_val_if_fail (ladspa->activated == FALSE, FALSE);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
GST_DEBUG_OBJECT (ladspa, "instantiating the plugin at %d Hz", sample_rate);
|
|
|
|
|
|
|
|
ladspa->handle = desc->instantiate (desc, sample_rate);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-23 15:26:43 +00:00
|
|
|
g_return_val_if_fail (ladspa->handle != NULL, FALSE);
|
|
|
|
|
2003-07-16 16:08:13 +00:00
|
|
|
/* connect the control ports */
|
2005-08-26 11:05:13 +00:00
|
|
|
for (i = 0; i < gsp_class->num_control_in; i++)
|
2004-03-14 22:34:33 +00:00
|
|
|
desc->connect_port (ladspa->handle,
|
2005-08-26 11:05:13 +00:00
|
|
|
oclass->control_in_portnums[i], &(gsp->control_in[i]));
|
|
|
|
for (i = 0; i < gsp_class->num_control_out; i++)
|
|
|
|
desc->connect_port (ladspa->handle,
|
|
|
|
oclass->control_out_portnums[i], &(gsp->control_out[i]));
|
2003-07-16 16:08:13 +00:00
|
|
|
|
2001-12-23 15:26:43 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ladspa_start (GstSignalProcessor * gsp)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
GstLADSPA *ladspa;
|
2001-12-23 15:26:43 +00:00
|
|
|
LADSPA_Descriptor *desc;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
ladspa = (GstLADSPA *) gsp;
|
2001-12-23 15:26:43 +00:00
|
|
|
desc = ladspa->descriptor;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
g_return_val_if_fail (ladspa->activated == FALSE, FALSE);
|
|
|
|
g_return_val_if_fail (ladspa->handle != NULL, FALSE);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-04-05 17:32:43 +00:00
|
|
|
GST_DEBUG_OBJECT (ladspa, "activating");
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (desc->activate)
|
2004-03-14 22:34:33 +00:00
|
|
|
desc->activate (ladspa->handle);
|
2002-01-22 04:42:11 +00:00
|
|
|
|
2001-12-23 15:26:43 +00:00
|
|
|
ladspa->activated = TRUE;
|
2005-08-26 11:05:13 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-08-26 11:05:13 +00:00
|
|
|
gst_ladspa_stop (GstSignalProcessor * gsp)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
GstLADSPA *ladspa;
|
2001-12-23 15:26:43 +00:00
|
|
|
LADSPA_Descriptor *desc;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
ladspa = (GstLADSPA *) gsp;
|
2001-12-23 15:26:43 +00:00
|
|
|
desc = ladspa->descriptor;
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
g_return_if_fail (ladspa->activated == TRUE);
|
|
|
|
g_return_if_fail (ladspa->handle != NULL);
|
|
|
|
|
2004-04-05 17:32:43 +00:00
|
|
|
GST_DEBUG_OBJECT (ladspa, "deactivating");
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (desc->activate)
|
|
|
|
desc->activate (ladspa->handle);
|
2002-01-22 04:42:11 +00:00
|
|
|
|
2001-12-23 15:26:43 +00:00
|
|
|
ladspa->activated = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-08-26 11:05:13 +00:00
|
|
|
gst_ladspa_cleanup (GstSignalProcessor * gsp)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
|
|
|
GstLADSPA *ladspa;
|
2005-08-26 11:05:13 +00:00
|
|
|
LADSPA_Descriptor *desc;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
ladspa = (GstLADSPA *) gsp;
|
2003-07-16 16:08:13 +00:00
|
|
|
desc = ladspa->descriptor;
|
2002-04-20 13:57:00 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
g_return_if_fail (ladspa->activated == FALSE);
|
|
|
|
g_return_if_fail (ladspa->handle != NULL);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
GST_DEBUG_OBJECT (ladspa, "cleaning up");
|
2002-04-20 13:57:00 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
if (desc->cleanup)
|
|
|
|
desc->cleanup (ladspa->handle);
|
2003-07-16 16:08:13 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
ladspa->handle = NULL;
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
static void
|
|
|
|
gst_ladspa_process (GstSignalProcessor * gsp, guint nframes)
|
2004-03-14 22:34:33 +00:00
|
|
|
{
|
2005-08-26 11:05:13 +00:00
|
|
|
GstSignalProcessorClass *gsp_class;
|
2001-12-23 15:26:43 +00:00
|
|
|
GstLADSPA *ladspa;
|
|
|
|
GstLADSPAClass *oclass;
|
2002-04-20 13:57:00 +00:00
|
|
|
LADSPA_Descriptor *desc;
|
2005-08-26 11:05:13 +00:00
|
|
|
guint i;
|
2002-01-22 04:42:11 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
gsp_class = GST_SIGNAL_PROCESSOR_GET_CLASS (gsp);
|
|
|
|
ladspa = (GstLADSPA *) gsp;
|
|
|
|
oclass = (GstLADSPAClass *) gsp_class;
|
2003-07-16 16:08:13 +00:00
|
|
|
desc = ladspa->descriptor;
|
2002-01-22 04:42:11 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
for (i = 0; i < gsp_class->num_audio_in; i++)
|
|
|
|
desc->connect_port (ladspa->handle, oclass->audio_in_portnums[i],
|
|
|
|
gsp->audio_in[i]);
|
|
|
|
for (i = 0; i < gsp_class->num_audio_out; i++)
|
|
|
|
desc->connect_port (ladspa->handle, oclass->audio_out_portnums[i],
|
|
|
|
gsp->audio_out[i]);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-08-26 11:05:13 +00:00
|
|
|
desc->run (ladspa->handle, nframes);
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
ladspa_describe_plugin (const char *pcFullFilename,
|
|
|
|
void *pvPluginHandle, LADSPA_Descriptor_Function pfDescriptorFunction)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
|
|
|
const LADSPA_Descriptor *desc;
|
2003-11-02 13:55:40 +00:00
|
|
|
gint i;
|
2008-02-04 19:15:39 +00:00
|
|
|
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2002-01-22 04:42:11 +00:00
|
|
|
/* walk through all the plugins in this pluginlibrary */
|
2001-12-23 15:26:43 +00:00
|
|
|
i = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
while ((desc = pfDescriptorFunction (i++))) {
|
2001-12-23 15:26:43 +00:00
|
|
|
gchar *type_name;
|
2008-02-04 19:15:39 +00:00
|
|
|
GTypeInfo typeinfo = {
|
|
|
|
sizeof (GstLADSPAClass),
|
|
|
|
(GBaseInitFunc) gst_ladspa_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_ladspa_class_init,
|
|
|
|
NULL,
|
|
|
|
desc,
|
|
|
|
sizeof (GstLADSPA),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_ladspa_init,
|
|
|
|
};
|
|
|
|
GType type;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2002-01-22 04:42:11 +00:00
|
|
|
/* construct the type */
|
2004-03-14 22:34:33 +00:00
|
|
|
type_name = g_strdup_printf ("ladspa-%s", desc->Label);
|
2003-07-16 16:08:13 +00:00
|
|
|
g_strcanon (type_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-');
|
2002-01-22 04:42:11 +00:00
|
|
|
/* if it's already registered, drop it */
|
2007-08-16 07:07:41 +00:00
|
|
|
if (g_type_from_name (type_name))
|
|
|
|
goto next;
|
2003-11-02 23:58:20 +00:00
|
|
|
|
2002-01-22 04:42:11 +00:00
|
|
|
/* create the type now */
|
2005-08-26 11:05:13 +00:00
|
|
|
type =
|
|
|
|
g_type_register_static (GST_TYPE_SIGNAL_PROCESSOR, type_name, &typeinfo,
|
|
|
|
0);
|
2008-02-04 19:15:39 +00:00
|
|
|
/* FIXME: not needed anymore when we can add pad templates, etc in class_init
|
|
|
|
* as class_data contains the LADSPA_Descriptor too */
|
|
|
|
g_type_set_qdata (type, GST_LADSPA_DESCRIPTOR_QDATA, (gpointer) desc);
|
|
|
|
|
2003-11-02 13:55:40 +00:00
|
|
|
if (!gst_element_register (ladspa_plugin, type_name, GST_RANK_NONE, type))
|
2007-08-16 07:07:41 +00:00
|
|
|
goto next;
|
2001-12-23 15:26:43 +00:00
|
|
|
|
2007-08-16 07:07:41 +00:00
|
|
|
next:
|
|
|
|
g_free (type_name);
|
2001-12-23 15:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-23 15:26:43 +00:00
|
|
|
{
|
2003-07-16 16:08:13 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (ladspa_debug, "ladspa",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG_FG_GREEN | GST_DEBUG_BG_BLACK | GST_DEBUG_BOLD, "LADSPA");
|
2003-07-16 16:08:13 +00:00
|
|
|
|
2008-02-04 19:15:39 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_SIGNAL_PROCESSOR);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
|
|
|
ladspa_plugin = plugin;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
LADSPAPluginSearch (ladspa_describe_plugin);
|
2001-12-23 15:26:43 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"ladspa",
|
|
|
|
"All LADSPA plugins",
|
2005-11-14 02:13:26 +00:00
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|