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"
|
|
|
|
|
2004-07-26 18:34:01 +00:00
|
|
|
GST_DEBUG_CATEGORY (level_debug);
|
|
|
|
#define GST_CAT_DEFAULT level_debug
|
|
|
|
|
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 =
|
2004-10-26 15:36:17 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2004-07-27 17:42:47 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
|
|
|
"rate = (int) [ 1, MAX ], "
|
2004-10-26 11:36:53 +00:00
|
|
|
"channels = (int) [ 1, 2 ], "
|
2004-07-27 17:42:47 +00:00
|
|
|
"endianness = (int) BYTE_ORDER, "
|
|
|
|
"width = (int) { 8, 16 }, "
|
|
|
|
"depth = (int) { 8, 16 }, " "signed = (boolean) true")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2003-09-21 13:08:29 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate src_template_factory =
|
2004-10-26 15:36:17 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2004-07-27 17:42:47 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
|
|
|
"rate = (int) [ 1, MAX ], "
|
2004-10-26 11:36:53 +00:00
|
|
|
"channels = (int) [ 1, 2 ], "
|
2004-07-27 17:42:47 +00:00
|
|
|
"endianness = (int) BYTE_ORDER, "
|
|
|
|
"width = (int) { 8, 16 }, "
|
|
|
|
"depth = (int) { 8, 16 }, " "signed = (boolean) true")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* Filter signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:27:31 +00:00
|
|
|
/* FILL ME */
|
2003-09-21 12:21:49 +00:00
|
|
|
SIGNAL_LEVEL,
|
2001-12-22 23:27:31 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_level_class_init (GstLevelClass * klass);
|
|
|
|
static void gst_level_base_init (GstLevelClass * klass);
|
|
|
|
static void gst_level_init (GstLevel * filter);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +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);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_level_get_type (void)
|
2002-08-27 17:45:07 +00:00
|
|
|
{
|
2001-12-22 23:27:31 +00:00
|
|
|
static GType level_type = 0;
|
|
|
|
|
2004-03-14 22:34:33 +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
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
level_type = g_type_register_static (GST_TYPE_ELEMENT, "GstLevel",
|
2004-03-15 19:32:27 +00:00
|
|
|
&level_info, 0);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
return level_type;
|
|
|
|
}
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +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);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
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;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
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);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!ret)
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2003-11-19 03:46:21 +00:00
|
|
|
|
|
|
|
/* allocate channel variable arrays */
|
2004-07-26 18:34:01 +00:00
|
|
|
g_free (filter->CS);
|
|
|
|
g_free (filter->peak);
|
|
|
|
g_free (filter->last_peak);
|
|
|
|
g_free (filter->decay_peak);
|
|
|
|
g_free (filter->decay_peak_age);
|
|
|
|
g_free (filter->MS);
|
|
|
|
g_free (filter->RMS_dB);
|
2003-11-19 03:46:21 +00:00
|
|
|
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);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-19 03:46:21 +00:00
|
|
|
for (i = 0; i < filter->channels; ++i) {
|
|
|
|
filter->CS[i] = filter->peak[i] = filter->last_peak[i] =
|
2004-03-15 19:32:27 +00:00
|
|
|
filter->decay_peak[i] = filter->decay_peak_age[i] =
|
|
|
|
filter->MS[i] = filter->RMS_dB[i] = 0.0;
|
2003-11-19 03:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GST_PAD_LINK_OK;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2003-09-21 12:21:49 +00:00
|
|
|
static void inline
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_level_fast_16bit_chain (gint16 * in, guint num, gint channels,
|
|
|
|
gint resolution, double *CS, double *peak)
|
2003-09-21 12:21:49 +00:00
|
|
|
#include "filter.func"
|
2004-03-14 22:34:33 +00:00
|
|
|
static void inline
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_level_fast_8bit_chain (gint8 * in, guint num, gint channels,
|
2004-03-14 22:34:33 +00:00
|
|
|
gint resolution, double *CS, double *peak)
|
2003-09-21 12:21:49 +00:00
|
|
|
#include "filter.func"
|
2004-03-14 22:34:33 +00:00
|
|
|
static void 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
|
|
|
|
2004-05-08 13:03:59 +00:00
|
|
|
if (!gst_pad_is_negotiated (pad)) {
|
|
|
|
GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION, (NULL),
|
|
|
|
("sinkpad not negotiated"));
|
|
|
|
gst_data_unref (_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-26 16:45:04 +00:00
|
|
|
in_data = (gint16 *) GST_BUFFER_DATA (buf);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-07-27 16:41:15 +00:00
|
|
|
/* total number of interleaved samples */
|
2003-09-21 12:21:49 +00:00
|
|
|
num_samples = GST_BUFFER_SIZE (buf) / (filter->width / 8);
|
|
|
|
if (num_samples % filter->channels != 0)
|
2004-03-14 22:34:33 +00:00
|
|
|
g_warning
|
2004-03-15 19:32:27 +00:00
|
|
|
("WARNING: level: programming error, data not properly interleaved");
|
2003-09-21 12:21:49 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < filter->channels; ++i) {
|
|
|
|
switch (filter->width) {
|
2003-09-21 12:21:49 +00:00
|
|
|
case 16:
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_level_fast_16bit_chain (in_data + i, num_samples,
|
|
|
|
filter->channels, filter->width - 1, &CS, &filter->peak[i]);
|
|
|
|
break;
|
2003-09-21 12:21:49 +00:00
|
|
|
case 8:
|
2004-03-15 19:32:27 +00:00
|
|
|
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:21:49 +00:00
|
|
|
}
|
2004-07-26 18:34:01 +00:00
|
|
|
GST_LOG_OBJECT (filter, "channel %d, cumulative sum %f, peak %f", i, 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
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < filter->channels; ++i) {
|
2003-09-21 12:21:49 +00:00
|
|
|
filter->decay_peak_age[i] += num_samples;
|
2004-07-26 18:34:01 +00:00
|
|
|
/* g_print ("filter peak info [%d]: peak %f, age %f\n", i,
|
2004-03-14 22:34:33 +00:00
|
|
|
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])
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->last_peak[i] = filter->peak[i];
|
2003-09-21 12:21:49 +00:00
|
|
|
|
|
|
|
/* update decay peak */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (filter->peak[i] >= filter->decay_peak[i]) {
|
|
|
|
/* g_print ("new peak, %f\n", filter->peak[i]); */
|
|
|
|
filter->decay_peak[i] = filter->peak[i];
|
|
|
|
filter->decay_peak_age[i] = 0;
|
|
|
|
} else {
|
2003-09-21 12:21:49 +00:00
|
|
|
/* make decay peak fall off if too old */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (filter->decay_peak_age[i] > filter->rate * filter->decay_peak_ttl) {
|
2004-03-15 19:32:27 +00:00
|
|
|
double falloff_dB;
|
|
|
|
double falloff;
|
|
|
|
double length; /* length of buffer in seconds */
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
length = (double) num_samples / (filter->channels * filter->rate);
|
|
|
|
falloff_dB = filter->decay_peak_falloff * length;
|
|
|
|
falloff = pow (10, falloff_dB / -20.0);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
/* g_print ("falloff: length %f, dB falloff %f, falloff factor %e\n",
|
|
|
|
length, falloff_dB, falloff); */
|
|
|
|
filter->decay_peak[i] *= falloff;
|
|
|
|
/* 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 ? */
|
2004-03-14 22:34:33 +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;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
for (i = 0; i < filter->channels; ++i) {
|
2004-03-15 19:32:27 +00:00
|
|
|
RMS = sqrt (filter->CS[i] / (filter->num_samples / filter->channels));
|
|
|
|
peak = filter->last_peak[i];
|
|
|
|
num_samples = GST_BUFFER_SIZE (buf) / (filter->width / 8);
|
|
|
|
endtime = (double) GST_BUFFER_TIMESTAMP (buf) / GST_SECOND
|
|
|
|
+ (double) num_samples / (double) filter->rate;
|
|
|
|
|
|
|
|
g_signal_emit (G_OBJECT (filter), gst_filter_signals[SIGNAL_LEVEL], 0,
|
|
|
|
endtime, i,
|
|
|
|
20 * log10 (RMS), 20 * log10 (filter->last_peak[i]),
|
|
|
|
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;
|
2003-09-21 12:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
filter->num_samples = 0;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +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;
|
|
|
|
|
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
|
2004-03-14 22:34:33 +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;
|
|
|
|
|
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;
|
2004-03-14 22:34:33 +00:00
|
|
|
case ARG_SIGNAL_INTERVAL:
|
2003-09-21 12:21:49 +00:00
|
|
|
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;
|
2004-03-14 22:34:33 +00:00
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_level_base_init (GstLevelClass * klass)
|
2003-11-02 18:17:48 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +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,
|
2004-03-14 22:34:33 +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);
|
|
|
|
}
|
|
|
|
|
2002-08-27 17:45:07 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_level_class_init (GstLevelClass * klass)
|
2002-08-27 17:45:07 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2002-08-27 17:45:07 +00:00
|
|
|
|
|
|
|
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,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_boolean ("signal", "Signal",
|
2004-03-15 19:32:27 +00:00
|
|
|
"Emit level signals for each interval", TRUE, G_PARAM_READWRITE));
|
2003-09-21 12:21:49 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIGNAL_INTERVAL,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_double ("interval", "Interval",
|
2004-03-15 19:32:27 +00:00
|
|
|
"Interval between emissions (in seconds)",
|
|
|
|
0.01, 100.0, 0.1, G_PARAM_READWRITE));
|
2003-09-21 12:21:49 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PEAK_TTL,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_double ("peak_ttl", "Peak TTL",
|
2004-03-15 19:32:27 +00:00
|
|
|
"Time To Live of decay peak before it falls back",
|
|
|
|
0, 100.0, 0.3, G_PARAM_READWRITE));
|
2003-09-21 12:21:49 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PEAK_FALLOFF,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_double ("peak_falloff", "Peak Falloff",
|
2004-03-15 19:32:27 +00:00
|
|
|
"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
|
|
|
|
2004-03-14 22:34:33 +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,
|
2004-06-08 10:14:50 +00:00
|
|
|
gst_level_marshal_VOID__DOUBLE_INT_DOUBLE_DOUBLE_DOUBLE,
|
2004-03-14 22:34:33 +00:00
|
|
|
G_TYPE_NONE, 5,
|
|
|
|
G_TYPE_DOUBLE, G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
2004-07-26 18:34:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (level_debug, "level", 0, "Level calculation");
|
2002-08-27 17:45:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_level_init (GstLevel * filter)
|
2002-08-27 17:45:07 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +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);
|
2004-03-24 14:04:53 +00:00
|
|
|
gst_pad_set_getcaps_function (filter->sinkpad, gst_pad_proxy_getcaps);
|
2004-05-08 13:03:59 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
|
|
|
gst_pad_set_chain_function (filter->sinkpad, gst_level_chain);
|
|
|
|
|
2004-03-14 22:34:33 +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);
|
2004-03-24 14:04:53 +00:00
|
|
|
gst_pad_set_getcaps_function (filter->srcpad, gst_pad_proxy_getcaps);
|
2002-08-27 17:45:07 +00:00
|
|
|
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;
|
2004-03-15 19:32:27 +00:00
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
return gst_element_register (plugin, "level", GST_RANK_NONE, GST_TYPE_LEVEL);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"level",
|
|
|
|
"Audio level plugin",
|
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)
|