2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:27:31 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
2003-09-21 12:21:49 +00:00
|
|
|
* gstlevel.c: signals RMS, peak and decaying peak levels
|
|
|
|
* Copyright (C) 2000,2001,2002,2003
|
|
|
|
* Thomas Vander Stichele <thomas at apestaart dot org>
|
|
|
|
*
|
2001-12-22 23:27:31 +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 22:14:17 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:27:31 +00:00
|
|
|
#include <gst/gst.h>
|
2003-12-22 01:47:09 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2001-12-22 23:27:31 +00:00
|
|
|
#include "gstlevel.h"
|
|
|
|
#include "math.h"
|
|
|
|
|
2002-09-18 19:02:51 +00:00
|
|
|
/* elementfactory information */
|
2001-12-22 23:27:31 +00:00
|
|
|
static GstElementDetails level_details = {
|
|
|
|
"Level",
|
2003-11-16 22:02:22 +00:00
|
|
|
"Filter/Analyzer/Audio",
|
2003-09-21 12:21:49 +00:00
|
|
|
"RMS/Peak/Decaying Peak Level signaller for audio/raw",
|
2003-11-02 18:17:48 +00:00
|
|
|
"Thomas <thomas@apestaart.org>"
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
|
|
|
|
2003-09-21 13:08:29 +00:00
|
|
|
/* pad templates */
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate sink_template_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
2003-09-21 13:08:29 +00:00
|
|
|
"level_sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS)
|
|
|
|
);
|
2003-09-21 13:08:29 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate src_template_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
2003-09-21 13:08:29 +00:00
|
|
|
"level_src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS)
|
|
|
|
);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* Filter signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
2003-09-21 12:21:49 +00:00
|
|
|
SIGNAL_LEVEL,
|
2001-12-22 23:27:31 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2003-09-21 12:21:49 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_SIGNAL_LEVEL,
|
|
|
|
ARG_SIGNAL_INTERVAL,
|
|
|
|
ARG_PEAK_TTL,
|
|
|
|
ARG_PEAK_FALLOFF
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gst_level_class_init (GstLevelClass *klass);
|
2003-11-02 18:17:48 +00:00
|
|
|
static void gst_level_base_init (GstLevelClass *klass);
|
2001-12-22 23:27:31 +00:00
|
|
|
static void gst_level_init (GstLevel *filter);
|
|
|
|
|
2003-11-19 03:46:21 +00:00
|
|
|
static GstElementStateReturn gst_level_change_state (GstElement *element);
|
2001-12-22 23:27:31 +00:00
|
|
|
static void gst_level_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_level_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
|
|
|
|
2003-10-08 16:08:18 +00:00
|
|
|
static void gst_level_chain (GstPad *pad, GstData *_data);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2003-09-21 12:21:49 +00:00
|
|
|
static guint gst_filter_signals[LAST_SIGNAL] = { 0 };
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
GType
|
2002-08-27 17:45:07 +00:00
|
|
|
gst_level_get_type (void)
|
|
|
|
{
|
2001-12-22 23:27:31 +00:00
|
|
|
static GType level_type = 0;
|
|
|
|
|
2002-08-27 17:45:07 +00:00
|
|
|
if (!level_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo level_info =
|
|
|
|
{
|
2003-11-02 18:17:48 +00:00
|
|
|
sizeof (GstLevelClass),
|
|
|
|
(GBaseInitFunc) gst_level_base_init, NULL,
|
2002-08-27 17:45:07 +00:00
|
|
|
(GClassInitFunc) gst_level_class_init, NULL, NULL,
|
|
|
|
sizeof (GstLevel), 0,
|
|
|
|
(GInstanceInitFunc) gst_level_init
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
2002-08-27 17:45:07 +00:00
|
|
|
level_type = g_type_register_static (GST_TYPE_ELEMENT, "GstLevel",
|
|
|
|
&level_info, 0);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
return level_type;
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_level_link (GstPad *pad, const GstCaps *caps)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2002-08-27 17:45:07 +00:00
|
|
|
GstLevel *filter;
|
|
|
|
GstPad *otherpad;
|
2003-09-21 12:21:49 +00:00
|
|
|
GstPadLinkReturn res;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2003-09-21 12:21:49 +00:00
|
|
|
int i;
|
2003-12-22 01:47:09 +00:00
|
|
|
gboolean ret;
|
2002-08-27 17:45:07 +00:00
|
|
|
|
|
|
|
filter = GST_LEVEL (gst_pad_get_parent (pad));
|
2003-01-10 10:22:25 +00:00
|
|
|
g_return_val_if_fail (filter != NULL, GST_PAD_LINK_REFUSED);
|
|
|
|
g_return_val_if_fail (GST_IS_LEVEL (filter), GST_PAD_LINK_REFUSED);
|
2002-08-27 17:45:07 +00:00
|
|
|
otherpad = (pad == filter->srcpad ? filter->sinkpad : filter->srcpad);
|
|
|
|
|
2003-11-19 03:46:21 +00:00
|
|
|
res = gst_pad_try_set_caps (otherpad, caps);
|
|
|
|
/* if ok, set filter */
|
|
|
|
if (res != GST_PAD_LINK_OK && res != GST_PAD_LINK_DONE) {
|
2003-09-21 12:21:49 +00:00
|
|
|
return res;
|
2002-08-27 17:45:07 +00:00
|
|
|
}
|
2003-11-19 03:46:21 +00:00
|
|
|
|
|
|
|
filter->num_samples = 0;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
ret = gst_structure_get_int (structure, "rate", &filter->rate);
|
|
|
|
ret &= gst_structure_get_int (structure, "width", &filter->width);
|
|
|
|
ret &= gst_structure_get_int (structure, "channels", &filter->channels);
|
|
|
|
|
|
|
|
if (!ret) return GST_PAD_LINK_REFUSED;
|
2003-11-19 03:46:21 +00:00
|
|
|
|
|
|
|
/* allocate channel variable arrays */
|
|
|
|
if (filter->CS) g_free (filter->CS);
|
|
|
|
if (filter->peak) g_free (filter->peak);
|
|
|
|
if (filter->last_peak) g_free (filter->last_peak);
|
|
|
|
if (filter->decay_peak) g_free (filter->decay_peak);
|
|
|
|
if (filter->decay_peak_age) g_free (filter->decay_peak_age);
|
|
|
|
if (filter->MS) g_free (filter->MS);
|
|
|
|
if (filter->RMS_dB) g_free (filter->RMS_dB);
|
|
|
|
filter->CS = g_new (double, filter->channels);
|
|
|
|
filter->peak = g_new (double, filter->channels);
|
|
|
|
filter->last_peak = g_new (double, filter->channels);
|
|
|
|
filter->decay_peak = g_new (double, filter->channels);
|
|
|
|
filter->decay_peak_age = g_new (double, filter->channels);
|
|
|
|
filter->MS = g_new (double, filter->channels);
|
|
|
|
filter->RMS_dB = g_new (double, filter->channels);
|
|
|
|
for (i = 0; i < filter->channels; ++i) {
|
|
|
|
filter->CS[i] = filter->peak[i] = filter->last_peak[i] =
|
|
|
|
filter->decay_peak[i] = filter->decay_peak_age[i] =
|
|
|
|
filter->MS[i] = filter->RMS_dB[i] = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
filter->inited = TRUE;
|
|
|
|
|
|
|
|
return GST_PAD_LINK_OK;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2003-09-21 12:21:49 +00:00
|
|
|
static void inline
|
|
|
|
gst_level_fast_16bit_chain (gint16* in, guint num, gint channels,
|
|
|
|
gint resolution, double *CS, double *peak)
|
|
|
|
#include "filter.func"
|
|
|
|
|
|
|
|
static void inline
|
|
|
|
gst_level_fast_8bit_chain (gint8* in, guint num, gint channels,
|
|
|
|
gint resolution, double *CS, double *peak)
|
|
|
|
#include "filter.func"
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_level_chain (GstPad *pad, GstData *_data)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2003-10-08 16:08:18 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-22 23:27:31 +00:00
|
|
|
GstLevel *filter;
|
|
|
|
gint16 *in_data;
|
|
|
|
|
2003-09-21 12:21:49 +00:00
|
|
|
double CS = 0.0;
|
|
|
|
gint num_samples = 0;
|
|
|
|
gint i;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-08-27 17:45:07 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-08-27 17:45:07 +00:00
|
|
|
filter = GST_LEVEL (GST_OBJECT_PARENT (pad));
|
|
|
|
g_return_if_fail (filter != NULL);
|
|
|
|
g_return_if_fail (GST_IS_LEVEL (filter));
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-09-21 12:21:49 +00:00
|
|
|
for (i = 0; i < filter->channels; ++i)
|
|
|
|
filter->CS[i] = filter->peak[i] = filter->MS[i] = filter->RMS_dB[i] = 0.0;
|
|
|
|
|
2003-09-26 16:45:04 +00:00
|
|
|
in_data = (gint16 *) GST_BUFFER_DATA (buf);
|
2003-09-21 12:21:49 +00:00
|
|
|
|
|
|
|
num_samples = GST_BUFFER_SIZE (buf) / (filter->width / 8);
|
|
|
|
if (num_samples % filter->channels != 0)
|
|
|
|
g_warning ("WARNING: level: programming error, data not properly interleaved");
|
|
|
|
|
|
|
|
for (i = 0; i < filter->channels; ++i)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2003-09-21 12:21:49 +00:00
|
|
|
switch (filter->width)
|
|
|
|
{
|
|
|
|
case 16:
|
|
|
|
gst_level_fast_16bit_chain (in_data + i, num_samples,
|
|
|
|
filter->channels, filter->width - 1,
|
|
|
|
&CS, &filter->peak[i]);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
gst_level_fast_8bit_chain (((gint8 *) in_data) + i, num_samples,
|
|
|
|
filter->channels, filter->width - 1,
|
|
|
|
&CS, &filter->peak[i]);
|
|
|
|
break;
|
|
|
|
}
|
2003-09-21 12:52:55 +00:00
|
|
|
/* g_print ("DEBUG: CS %f, peak %f\n", CS, filter->peak[i]); */
|
2003-09-21 12:21:49 +00:00
|
|
|
filter->CS[i] += CS;
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_pad_push (filter->srcpad, GST_DATA (buf));
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-09-21 12:21:49 +00:00
|
|
|
filter->num_samples += num_samples;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-09-21 12:21:49 +00:00
|
|
|
for (i = 0; i < filter->channels; ++i)
|
|
|
|
{
|
|
|
|
filter->decay_peak_age[i] += num_samples;
|
2003-09-21 12:52:55 +00:00
|
|
|
/* g_print ("filter peak info [%d]: peak %f, age %f\n", i,
|
|
|
|
filter->last_peak[i], filter->decay_peak_age[i]); */
|
2003-09-21 12:21:49 +00:00
|
|
|
/* update running peak */
|
|
|
|
if (filter->peak[i] > filter->last_peak[i])
|
|
|
|
filter->last_peak[i] = filter->peak[i];
|
|
|
|
|
|
|
|
/* update decay peak */
|
|
|
|
if (filter->peak[i] >= filter->decay_peak[i])
|
|
|
|
{
|
2003-09-21 12:52:55 +00:00
|
|
|
/* g_print ("new peak, %f\n", filter->peak[i]); */
|
2003-09-21 12:21:49 +00:00
|
|
|
filter->decay_peak[i] = filter->peak[i];
|
|
|
|
filter->decay_peak_age[i] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* make decay peak fall off if too old */
|
|
|
|
if (filter->decay_peak_age[i] > filter->rate * filter->decay_peak_ttl)
|
|
|
|
{
|
|
|
|
double falloff_dB;
|
|
|
|
double falloff;
|
|
|
|
double length; /* length of buffer in seconds */
|
|
|
|
|
|
|
|
|
|
|
|
length = (double) num_samples / (filter->channels * filter->rate);
|
|
|
|
falloff_dB = filter->decay_peak_falloff * length;
|
|
|
|
falloff = pow (10, falloff_dB / -20.0);
|
|
|
|
|
2003-09-21 12:52:55 +00:00
|
|
|
/* g_print ("falloff: length %f, dB falloff %f, falloff factor %e\n",
|
|
|
|
length, falloff_dB, falloff); */
|
2003-09-21 12:21:49 +00:00
|
|
|
filter->decay_peak[i] *= falloff;
|
2003-09-21 12:52:55 +00:00
|
|
|
/* g_print ("peak is %f samples old, decayed with factor %e to %f\n",
|
|
|
|
filter->decay_peak_age[i], falloff, filter->decay_peak[i]); */
|
2003-09-21 12:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-09-21 12:21:49 +00:00
|
|
|
/* do we need to emit ? */
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-09-21 12:21:49 +00:00
|
|
|
if (filter->num_samples >= filter->interval * (gdouble) filter->rate)
|
|
|
|
{
|
|
|
|
if (filter->signal)
|
|
|
|
{
|
2003-09-26 16:45:04 +00:00
|
|
|
gdouble RMS, peak, endtime;
|
2003-09-21 12:21:49 +00:00
|
|
|
for (i = 0; i < filter->channels; ++i)
|
|
|
|
{
|
|
|
|
RMS = sqrt (filter->CS[i] / (filter->num_samples / filter->channels));
|
|
|
|
peak = filter->last_peak[i];
|
2003-09-26 16:45:04 +00:00
|
|
|
num_samples = GST_BUFFER_SIZE (buf) / (filter->width / 8);
|
|
|
|
endtime = (double) GST_BUFFER_TIMESTAMP (buf) / GST_SECOND
|
|
|
|
+ (double) num_samples / (double) filter->rate;
|
2003-09-21 12:21:49 +00:00
|
|
|
|
|
|
|
g_signal_emit (G_OBJECT (filter), gst_filter_signals[SIGNAL_LEVEL], 0,
|
2003-09-26 16:45:04 +00:00
|
|
|
endtime, i,
|
|
|
|
20 * log10 (RMS), 20 * log10 (filter->last_peak[i]),
|
2003-09-21 12:21:49 +00:00
|
|
|
20 * log10 (filter->decay_peak[i]));
|
|
|
|
/* we emitted, so reset cumulative and normal peak */
|
|
|
|
filter->CS[i] = 0.0;
|
|
|
|
filter->last_peak[i] = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filter->num_samples = 0;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-19 03:46:21 +00:00
|
|
|
static GstElementStateReturn gst_level_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstLevel *filter = GST_LEVEL (element);
|
|
|
|
|
|
|
|
switch(GST_STATE_TRANSITION(element)){
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
if (!filter->inited) return GST_STATE_FAILURE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_ELEMENT_CLASS(parent_class)->change_state(element);
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
static void
|
2002-08-30 13:37:31 +00:00
|
|
|
gst_level_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GstLevel *filter;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2002-08-30 13:37:31 +00:00
|
|
|
g_return_if_fail (GST_IS_LEVEL (object));
|
|
|
|
filter = GST_LEVEL (object);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2003-09-21 12:21:49 +00:00
|
|
|
case ARG_SIGNAL_LEVEL:
|
|
|
|
filter->signal = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_SIGNAL_INTERVAL:
|
|
|
|
filter->interval = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case ARG_PEAK_TTL:
|
|
|
|
filter->decay_peak_ttl = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case ARG_PEAK_FALLOFF:
|
|
|
|
filter->decay_peak_falloff = g_value_get_double (value);
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-30 13:37:31 +00:00
|
|
|
gst_level_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GstLevel *filter;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2002-08-30 13:37:31 +00:00
|
|
|
g_return_if_fail (GST_IS_LEVEL (object));
|
|
|
|
filter = GST_LEVEL (object);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2003-09-21 12:21:49 +00:00
|
|
|
case ARG_SIGNAL_LEVEL:
|
|
|
|
g_value_set_boolean (value, filter->signal);
|
|
|
|
break;
|
|
|
|
case ARG_SIGNAL_INTERVAL:
|
|
|
|
g_value_set_double (value, filter->interval);
|
|
|
|
break;
|
|
|
|
case ARG_PEAK_TTL:
|
|
|
|
g_value_set_double (value, filter->decay_peak_ttl);
|
|
|
|
break;
|
|
|
|
case ARG_PEAK_FALLOFF:
|
|
|
|
g_value_set_double (value, filter->decay_peak_falloff);
|
|
|
|
break;
|
|
|
|
default:
|
2001-12-22 23:27:31 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-02 18:17:48 +00:00
|
|
|
static void
|
|
|
|
gst_level_base_init (GstLevelClass *klass)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_static_pad_template_get (&sink_template_factory));
|
2003-11-02 18:17:48 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_static_pad_template_get (&src_template_factory));
|
2003-11-02 18:17:48 +00:00
|
|
|
gst_element_class_set_details (element_class, &level_details);
|
2003-11-19 03:46:21 +00:00
|
|
|
|
|
|
|
element_class->change_state = gst_level_change_state;
|
2003-11-02 18:17:48 +00:00
|
|
|
}
|
|
|
|
|
2002-08-27 17:45:07 +00:00
|
|
|
static void
|
|
|
|
gst_level_class_init (GstLevelClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
gstelement_class = (GstElementClass*) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2003-09-21 12:21:49 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIGNAL_LEVEL,
|
|
|
|
g_param_spec_boolean ("signal", "Signal",
|
|
|
|
"Emit level signals for each interval",
|
|
|
|
TRUE, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIGNAL_INTERVAL,
|
|
|
|
g_param_spec_double ("interval", "Interval",
|
|
|
|
"Interval between emissions (in seconds)",
|
|
|
|
0.01, 100.0, 0.1, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PEAK_TTL,
|
|
|
|
g_param_spec_double ("peak_ttl", "Peak TTL",
|
|
|
|
"Time To Live of decay peak before it falls back",
|
|
|
|
0, 100.0, 0.3, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PEAK_FALLOFF,
|
|
|
|
g_param_spec_double ("peak_falloff", "Peak Falloff",
|
|
|
|
"Decay rate of decay peak after TTL (in dB/sec)",
|
|
|
|
0.0, G_MAXDOUBLE, 10.0, G_PARAM_READWRITE));
|
2002-08-27 17:45:07 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_level_set_property;
|
|
|
|
gobject_class->get_property = gst_level_get_property;
|
2003-09-21 12:21:49 +00:00
|
|
|
|
|
|
|
gst_filter_signals[SIGNAL_LEVEL] =
|
|
|
|
g_signal_new ("level", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstLevelClass, level), NULL, NULL,
|
2003-09-26 16:45:04 +00:00
|
|
|
gstlevel_cclosure_marshal_VOID__DOUBLE_INT_DOUBLE_DOUBLE_DOUBLE,
|
|
|
|
G_TYPE_NONE, 5,
|
|
|
|
G_TYPE_DOUBLE, G_TYPE_INT,
|
|
|
|
G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
2002-08-27 17:45:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_level_init (GstLevel *filter)
|
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
filter->sinkpad = gst_pad_new_from_template (gst_static_pad_template_get (&sink_template_factory), "sink");
|
2003-11-19 03:46:21 +00:00
|
|
|
gst_pad_set_link_function (filter->sinkpad, gst_level_link);
|
2003-12-22 01:47:09 +00:00
|
|
|
filter->srcpad = gst_pad_new_from_template (gst_static_pad_template_get (&src_template_factory), "src");
|
2003-11-19 03:46:21 +00:00
|
|
|
gst_pad_set_link_function (filter->srcpad, gst_level_link);
|
2002-08-27 17:45:07 +00:00
|
|
|
|
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
|
|
|
gst_pad_set_chain_function (filter->sinkpad, gst_level_chain);
|
|
|
|
filter->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
2003-09-21 12:21:49 +00:00
|
|
|
|
|
|
|
filter->CS = NULL;
|
|
|
|
filter->peak = NULL;
|
|
|
|
filter->MS = NULL;
|
|
|
|
filter->RMS_dB = NULL;
|
|
|
|
|
|
|
|
filter->rate = 0;
|
|
|
|
filter->width = 0;
|
|
|
|
filter->channels = 0;
|
|
|
|
|
|
|
|
filter->interval = 0.1;
|
|
|
|
filter->decay_peak_ttl = 0.4;
|
|
|
|
filter->decay_peak_falloff = 10.0; /* dB falloff (/sec) */
|
2002-08-27 17:45:07 +00:00
|
|
|
}
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static gboolean
|
2003-11-02 18:17:48 +00:00
|
|
|
plugin_init (GstPlugin *plugin)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2003-11-02 18:17:48 +00:00
|
|
|
return gst_element_register (plugin, "level",
|
|
|
|
GST_RANK_NONE, GST_TYPE_LEVEL);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 18:17:48 +00:00
|
|
|
GST_PLUGIN_DEFINE (
|
2001-12-22 23:27:31 +00:00
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"level",
|
2003-11-02 18:17:48 +00:00
|
|
|
"Audio level plugin",
|
|
|
|
plugin_init,
|
|
|
|
VERSION,
|
|
|
|
GST_LICENSE,
|
|
|
|
GST_PACKAGE,
|
|
|
|
GST_ORIGIN
|
|
|
|
)
|