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>
|
2005-09-01 20:23:22 +00:00
|
|
|
* Copyright (C) 2000,2001,2002,2003,2005
|
2003-09-21 12:21:49 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2005-09-14 20:51:47 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-level
|
|
|
|
*
|
2008-05-08 10:20:52 +00:00
|
|
|
* Level analyses incoming audio buffers and, if the #GstLevel:message property
|
|
|
|
* is #TRUE, generates an element message named
|
2005-09-23 18:15:51 +00:00
|
|
|
* <classname>"level"</classname>:
|
2008-05-08 10:20:52 +00:00
|
|
|
* after each interval of time given by the #GstLevel:interval property.
|
2009-10-02 10:10:44 +00:00
|
|
|
* The message's structure contains these fields:
|
2005-09-14 20:51:47 +00:00
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
2005-09-23 18:15:51 +00:00
|
|
|
* #GstClockTime
|
2008-08-10 11:32:03 +00:00
|
|
|
* <classname>"timestamp"</classname>:
|
|
|
|
* the timestamp of the buffer that triggered the message.
|
|
|
|
* </para>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
|
|
|
* #GstClockTime
|
|
|
|
* <classname>"stream-time"</classname>:
|
|
|
|
* the stream time of the buffer.
|
|
|
|
* </para>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
|
|
|
* #GstClockTime
|
|
|
|
* <classname>"running-time"</classname>:
|
|
|
|
* the running_time of the buffer.
|
|
|
|
* </para>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
|
|
|
* #GstClockTime
|
|
|
|
* <classname>"duration"</classname>:
|
|
|
|
* the duration of the buffer.
|
|
|
|
* </para>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
|
|
|
* #GstClockTime
|
2005-09-14 20:51:47 +00:00
|
|
|
* <classname>"endtime"</classname>:
|
2008-08-10 11:32:03 +00:00
|
|
|
* the end time of the buffer that triggered the message as stream time (this
|
|
|
|
* is deprecated, as it can be calculated from stream-time + duration)
|
2005-09-23 18:15:51 +00:00
|
|
|
* </para>
|
2005-09-14 20:51:47 +00:00
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
2012-02-16 16:01:29 +00:00
|
|
|
* #GValueArray of #gdouble
|
2005-09-23 18:15:51 +00:00
|
|
|
* <classname>"peak"</classname>:
|
|
|
|
* the peak power level in dB for each channel
|
|
|
|
* </para>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
2012-02-16 16:01:29 +00:00
|
|
|
* #GValueArray of #gdouble
|
2005-09-23 18:15:51 +00:00
|
|
|
* <classname>"decay"</classname>:
|
|
|
|
* the decaying peak power level in dB for each channel
|
|
|
|
* the decaying peak level follows the peak level, but starts dropping
|
|
|
|
* if no new peak is reached after the time given by
|
|
|
|
* the <link linkend="GstLevel--peak-ttl">the time to live</link>.
|
|
|
|
* When the decaying peak level drops, it does so at the decay rate
|
|
|
|
* as specified by the
|
2005-09-24 12:10:02 +00:00
|
|
|
* <link linkend="GstLevel--peak-falloff">the peak falloff rate</link>.
|
2005-09-23 18:15:51 +00:00
|
|
|
* </para>
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* <para>
|
2012-02-16 16:01:29 +00:00
|
|
|
* #GValueArray of #gdouble
|
2005-09-23 18:15:51 +00:00
|
|
|
* <classname>"rms"</classname>:
|
|
|
|
* the Root Mean Square (or average power) level in dB for each channel
|
|
|
|
* </para>
|
2005-09-14 20:51:47 +00:00
|
|
|
* </listitem>
|
2008-08-10 11:32:03 +00:00
|
|
|
* </itemizedlist>
|
2009-01-28 10:29:42 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
2005-09-14 20:51:47 +00:00
|
|
|
* <title>Example application</title>
|
2009-01-28 10:29:42 +00:00
|
|
|
* |[
|
|
|
|
* <xi:include xmlns:xi="http://www.w3.org/2003/XInclude" parse="text" href="../../../../tests/examples/level/level-example.c" />
|
|
|
|
* ]|
|
2005-09-14 20:51:47 +00:00
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2003-11-06 22:14:17 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2012-02-16 16:01:29 +00:00
|
|
|
|
|
|
|
/* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
|
|
|
|
* with newer GLib versions (>= 2.31.0) */
|
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2007-02-21 10:18:12 +00:00
|
|
|
#include <string.h>
|
2008-01-23 17:05:32 +00:00
|
|
|
#include <math.h>
|
2001-12-22 23:27:31 +00:00
|
|
|
#include <gst/gst.h>
|
2005-09-23 18:15:51 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2008-05-08 10:20:52 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
#include "gstlevel.h"
|
|
|
|
|
2006-06-22 19:31:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (level_debug);
|
2004-07-26 18:34:01 +00:00
|
|
|
#define GST_CAT_DEFAULT level_debug
|
|
|
|
|
2010-08-24 11:25:02 +00:00
|
|
|
#define EPSILON 1e-35f
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate sink_template_factory =
|
2011-08-19 12:01:45 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-08-19 12:01:45 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw, "
|
|
|
|
"format = (string) { S8, " GST_AUDIO_NE (S16) ", " GST_AUDIO_NE (S32)
|
|
|
|
GST_AUDIO_NE (F32) "," GST_AUDIO_NE (F64) " },"
|
2012-01-04 10:31:07 +00:00
|
|
|
"layout = (string) interleaved, "
|
2011-08-19 12:01:45 +00:00
|
|
|
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
|
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 =
|
2011-08-19 12:01:45 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-08-19 12:01:45 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw, "
|
|
|
|
"format = (string) { S8, " GST_AUDIO_NE (S16) ", " GST_AUDIO_NE (S32)
|
|
|
|
GST_AUDIO_NE (F32) "," GST_AUDIO_NE (F64) " },"
|
2012-01-04 10:31:07 +00:00
|
|
|
"layout = (string) interleaved, "
|
2011-08-19 12:01:45 +00:00
|
|
|
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2005-07-04 14:02:46 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_SIGNAL_LEVEL,
|
|
|
|
PROP_SIGNAL_INTERVAL,
|
|
|
|
PROP_PEAK_TTL,
|
|
|
|
PROP_PEAK_FALLOFF
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
|
|
|
|
2011-06-30 08:38:49 +00:00
|
|
|
#define gst_level_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstLevel, gst_level, GST_TYPE_BASE_TRANSFORM);
|
2005-07-04 14:02:46 +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);
|
2007-11-26 10:04:49 +00:00
|
|
|
static void gst_level_finalize (GObject * obj);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
static gboolean gst_level_set_caps (GstBaseTransform * trans, GstCaps * in,
|
|
|
|
GstCaps * out);
|
2007-03-07 11:24:05 +00:00
|
|
|
static gboolean gst_level_start (GstBaseTransform * trans);
|
2005-09-09 17:56:43 +00:00
|
|
|
static GstFlowReturn gst_level_transform_ip (GstBaseTransform * trans,
|
|
|
|
GstBuffer * in);
|
2005-07-04 14:02:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_level_class_init (GstLevelClass * klass)
|
|
|
|
{
|
2007-11-26 10:04:49 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2011-06-30 08:38:49 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2007-11-26 10:04:49 +00:00
|
|
|
GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS (klass);
|
2005-07-04 14:02:46 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_level_set_property;
|
|
|
|
gobject_class->get_property = gst_level_get_property;
|
2007-11-26 10:04:49 +00:00
|
|
|
gobject_class->finalize = gst_level_finalize;
|
2005-07-04 14:02:46 +00:00
|
|
|
|
2007-11-26 10:04:49 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SIGNAL_LEVEL,
|
2010-01-07 14:38:36 +00:00
|
|
|
g_param_spec_boolean ("message", "message",
|
2005-09-23 18:15:51 +00:00
|
|
|
"Post a level message for each passed interval",
|
2010-10-13 14:21:23 +00:00
|
|
|
TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-11-26 10:04:49 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SIGNAL_INTERVAL,
|
2005-09-23 18:15:51 +00:00
|
|
|
g_param_spec_uint64 ("interval", "Interval",
|
|
|
|
"Interval of time between message posts (in nanoseconds)",
|
2010-10-13 14:21:23 +00:00
|
|
|
1, G_MAXUINT64, GST_SECOND / 10,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-11-26 10:04:49 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PEAK_TTL,
|
2005-11-22 12:41:35 +00:00
|
|
|
g_param_spec_uint64 ("peak-ttl", "Peak TTL",
|
2005-09-23 18:15:51 +00:00
|
|
|
"Time To Live of decay peak before it falls back (in nanoseconds)",
|
2010-10-13 14:21:23 +00:00
|
|
|
0, G_MAXUINT64, GST_SECOND / 10 * 3,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-11-26 10:04:49 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PEAK_FALLOFF,
|
2005-11-22 12:41:35 +00:00
|
|
|
g_param_spec_double ("peak-falloff", "Peak Falloff",
|
2005-07-04 14:02:46 +00:00
|
|
|
"Decay rate of decay peak after TTL (in dB/sec)",
|
2010-10-13 14:21:23 +00:00
|
|
|
0.0, G_MAXDOUBLE, 10.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2005-07-04 14:02:46 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (level_debug, "level", 0, "Level calculation");
|
|
|
|
|
2011-06-30 08:38:49 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_template_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_template_factory));
|
|
|
|
gst_element_class_set_details_simple (element_class, "Level",
|
|
|
|
"Filter/Analyzer/Audio",
|
|
|
|
"RMS/Peak/Decaying Peak Level messager for audio/raw",
|
|
|
|
"Thomas Vander Stichele <thomas at apestaart dot org>");
|
|
|
|
|
2007-02-12 12:43:00 +00:00
|
|
|
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_level_set_caps);
|
2007-03-07 11:24:05 +00:00
|
|
|
trans_class->start = GST_DEBUG_FUNCPTR (gst_level_start);
|
2007-02-12 12:43:00 +00:00
|
|
|
trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_level_transform_ip);
|
2005-09-09 17:56:43 +00:00
|
|
|
trans_class->passthrough_on_same_caps = TRUE;
|
2005-07-04 14:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 08:38:49 +00:00
|
|
|
gst_level_init (GstLevel * filter)
|
2005-07-04 14:02:46 +00:00
|
|
|
{
|
|
|
|
filter->CS = NULL;
|
|
|
|
filter->peak = NULL;
|
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
gst_audio_info_init (&filter->info);
|
2005-07-04 14:02:46 +00:00
|
|
|
|
2005-09-23 18:15:51 +00:00
|
|
|
filter->interval = GST_SECOND / 10;
|
|
|
|
filter->decay_peak_ttl = GST_SECOND / 10 * 3;
|
2005-07-04 14:02:46 +00:00
|
|
|
filter->decay_peak_falloff = 10.0; /* dB falloff (/sec) */
|
2005-09-14 20:51:47 +00:00
|
|
|
|
|
|
|
filter->message = TRUE;
|
2007-02-21 10:18:12 +00:00
|
|
|
|
|
|
|
filter->process = NULL;
|
2008-01-08 14:58:18 +00:00
|
|
|
|
|
|
|
gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (filter), TRUE);
|
2005-07-04 14:02:46 +00:00
|
|
|
}
|
|
|
|
|
2006-01-10 12:38:59 +00:00
|
|
|
static void
|
2007-11-26 10:04:49 +00:00
|
|
|
gst_level_finalize (GObject * obj)
|
2006-01-10 12:38:59 +00:00
|
|
|
{
|
|
|
|
GstLevel *filter = GST_LEVEL (obj);
|
|
|
|
|
|
|
|
g_free (filter->CS);
|
|
|
|
g_free (filter->peak);
|
|
|
|
g_free (filter->last_peak);
|
|
|
|
g_free (filter->decay_peak);
|
|
|
|
g_free (filter->decay_peak_base);
|
|
|
|
g_free (filter->decay_peak_age);
|
|
|
|
|
|
|
|
filter->CS = NULL;
|
|
|
|
filter->peak = NULL;
|
|
|
|
filter->last_peak = NULL;
|
|
|
|
filter->decay_peak = NULL;
|
|
|
|
filter->decay_peak_base = NULL;
|
|
|
|
filter->decay_peak_age = NULL;
|
|
|
|
|
2007-11-26 10:04:49 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
2006-01-10 12:38:59 +00:00
|
|
|
}
|
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
static void
|
|
|
|
gst_level_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstLevel *filter = GST_LEVEL (object);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_SIGNAL_LEVEL:
|
2005-09-01 20:23:22 +00:00
|
|
|
filter->message = g_value_get_boolean (value);
|
2005-07-04 14:02:46 +00:00
|
|
|
break;
|
|
|
|
case PROP_SIGNAL_INTERVAL:
|
2006-09-11 20:38:41 +00:00
|
|
|
filter->interval = g_value_get_uint64 (value);
|
2011-08-19 12:01:45 +00:00
|
|
|
if (GST_AUDIO_INFO_RATE (&filter->info)) {
|
2009-10-31 22:29:24 +00:00
|
|
|
filter->interval_frames =
|
2011-08-19 12:01:45 +00:00
|
|
|
GST_CLOCK_TIME_TO_FRAMES (filter->interval,
|
|
|
|
GST_AUDIO_INFO_RATE (&filter->info));
|
2009-10-31 22:29:24 +00:00
|
|
|
}
|
2005-07-04 14:02:46 +00:00
|
|
|
break;
|
|
|
|
case PROP_PEAK_TTL:
|
2006-03-30 23:37:16 +00:00
|
|
|
filter->decay_peak_ttl =
|
|
|
|
gst_guint64_to_gdouble (g_value_get_uint64 (value));
|
2005-07-04 14:02:46 +00:00
|
|
|
break;
|
|
|
|
case PROP_PEAK_FALLOFF:
|
|
|
|
filter->decay_peak_falloff = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
default:
|
2007-11-26 10:04:49 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2005-07-04 14:02:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
static void
|
|
|
|
gst_level_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2002-08-27 17:45:07 +00:00
|
|
|
{
|
2005-07-04 14:02:46 +00:00
|
|
|
GstLevel *filter = GST_LEVEL (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_SIGNAL_LEVEL:
|
2005-09-01 20:23:22 +00:00
|
|
|
g_value_set_boolean (value, filter->message);
|
2005-07-04 14:02:46 +00:00
|
|
|
break;
|
|
|
|
case PROP_SIGNAL_INTERVAL:
|
2005-09-23 18:15:51 +00:00
|
|
|
g_value_set_uint64 (value, filter->interval);
|
2005-07-04 14:02:46 +00:00
|
|
|
break;
|
|
|
|
case PROP_PEAK_TTL:
|
2005-09-23 18:15:51 +00:00
|
|
|
g_value_set_uint64 (value, filter->decay_peak_ttl);
|
2005-07-04 14:02:46 +00:00
|
|
|
break;
|
|
|
|
case PROP_PEAK_FALLOFF:
|
|
|
|
g_value_set_double (value, filter->decay_peak_falloff);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-21 10:18:12 +00:00
|
|
|
|
|
|
|
/* process one (interleaved) channel of incoming samples
|
|
|
|
* calculate square sum of samples
|
|
|
|
* normalize and average over number of samples
|
|
|
|
* returns a normalized cumulative square value, which can be averaged
|
|
|
|
* to return the average power as a double between 0 and 1
|
|
|
|
* also returns the normalized peak power (square of the highest amplitude)
|
|
|
|
*
|
|
|
|
* caller must assure num is a multiple of channels
|
|
|
|
* samples for multiple channels are interleaved
|
|
|
|
* input sample data enters in *in_data as 8 or 16 bit data
|
|
|
|
* this filter only accepts signed audio data, so mid level is always 0
|
|
|
|
*
|
|
|
|
* for 16 bit, this code considers the non-existant 32768 value to be
|
|
|
|
* full-scale; so 32767 will not map to 1.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFINE_INT_LEVEL_CALCULATOR(TYPE, RESOLUTION) \
|
2008-05-08 10:20:52 +00:00
|
|
|
static void inline \
|
2007-05-10 01:21:19 +00:00
|
|
|
gst_level_calculate_##TYPE (gpointer data, guint num, guint channels, \
|
2007-02-21 10:18:12 +00:00
|
|
|
gdouble *NCS, gdouble *NPS) \
|
|
|
|
{ \
|
|
|
|
TYPE * in = (TYPE *)data; \
|
|
|
|
register guint j; \
|
|
|
|
gdouble squaresum = 0.0; /* square sum of the integer samples */ \
|
|
|
|
register gdouble square = 0.0; /* Square */ \
|
|
|
|
register gdouble peaksquare = 0.0; /* Peak Square Sample */ \
|
|
|
|
gdouble normalizer; /* divisor to get a [-1.0, 1.0] range */ \
|
|
|
|
\
|
2007-11-26 10:04:49 +00:00
|
|
|
/* *NCS = 0.0; Normalized Cumulative Square */ \
|
|
|
|
/* *NPS = 0.0; Normalized Peask Square */ \
|
2007-02-21 10:18:12 +00:00
|
|
|
\
|
2008-05-08 10:20:52 +00:00
|
|
|
normalizer = (gdouble) (G_GINT64_CONSTANT(1) << (RESOLUTION * 2)); \
|
2007-02-21 10:18:12 +00:00
|
|
|
\
|
2008-05-08 10:20:52 +00:00
|
|
|
/* oil_squaresum_shifted_s16(&squaresum,in,num); */ \
|
2007-02-21 10:18:12 +00:00
|
|
|
for (j = 0; j < num; j += channels) \
|
|
|
|
{ \
|
|
|
|
square = ((gdouble) in[j]) * in[j]; \
|
|
|
|
if (square > peaksquare) peaksquare = square; \
|
|
|
|
squaresum += square; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
*NCS = squaresum / normalizer; \
|
|
|
|
*NPS = peaksquare / normalizer; \
|
|
|
|
}
|
|
|
|
|
2008-05-08 10:20:52 +00:00
|
|
|
DEFINE_INT_LEVEL_CALCULATOR (gint32, 31);
|
2007-02-21 10:18:12 +00:00
|
|
|
DEFINE_INT_LEVEL_CALCULATOR (gint16, 15);
|
|
|
|
DEFINE_INT_LEVEL_CALCULATOR (gint8, 7);
|
|
|
|
|
|
|
|
#define DEFINE_FLOAT_LEVEL_CALCULATOR(TYPE) \
|
|
|
|
static void inline \
|
2007-05-10 01:21:19 +00:00
|
|
|
gst_level_calculate_##TYPE (gpointer data, guint num, guint channels, \
|
2007-02-21 10:18:12 +00:00
|
|
|
gdouble *NCS, gdouble *NPS) \
|
|
|
|
{ \
|
|
|
|
TYPE * in = (TYPE *)data; \
|
|
|
|
register guint j; \
|
|
|
|
gdouble squaresum = 0.0; /* square sum of the integer samples */ \
|
|
|
|
register gdouble square = 0.0; /* Square */ \
|
|
|
|
register gdouble peaksquare = 0.0; /* Peak Square Sample */ \
|
|
|
|
\
|
2007-11-26 10:04:49 +00:00
|
|
|
/* *NCS = 0.0; Normalized Cumulative Square */ \
|
|
|
|
/* *NPS = 0.0; Normalized Peask Square */ \
|
2007-02-21 10:18:12 +00:00
|
|
|
\
|
2007-11-26 10:04:49 +00:00
|
|
|
/* oil_squaresum_f64(&squaresum,in,num); */ \
|
2007-02-21 10:18:12 +00:00
|
|
|
for (j = 0; j < num; j += channels) \
|
|
|
|
{ \
|
|
|
|
square = ((gdouble) in[j]) * in[j]; \
|
|
|
|
if (square > peaksquare) peaksquare = square; \
|
|
|
|
squaresum += square; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
*NCS = squaresum; \
|
|
|
|
*NPS = peaksquare; \
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_FLOAT_LEVEL_CALCULATOR (gfloat);
|
|
|
|
DEFINE_FLOAT_LEVEL_CALCULATOR (gdouble);
|
|
|
|
|
2008-05-08 10:20:52 +00:00
|
|
|
/* we would need stride to deinterleave also
|
|
|
|
static void inline
|
|
|
|
gst_level_calculate_gdouble (gpointer data, guint num, guint channels,
|
|
|
|
gdouble *NCS, gdouble *NPS)
|
|
|
|
{
|
|
|
|
oil_squaresum_f64(NCS,(gdouble *)data,num);
|
|
|
|
*NPS = 0.0;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_level_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2007-02-21 10:18:12 +00:00
|
|
|
GstLevel *filter = GST_LEVEL (trans);
|
2011-08-19 12:01:45 +00:00
|
|
|
GstAudioInfo info;
|
|
|
|
gint i, channels, rate;
|
2002-08-27 17:45:07 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
if (!gst_audio_info_from_caps (&info, in))
|
|
|
|
return FALSE;
|
2007-02-21 10:18:12 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
switch (GST_AUDIO_INFO_FORMAT (&info)) {
|
|
|
|
case GST_AUDIO_FORMAT_S8:
|
|
|
|
filter->process = gst_level_calculate_gint8;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S16:
|
|
|
|
filter->process = gst_level_calculate_gint16;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_S32:
|
|
|
|
filter->process = gst_level_calculate_gint32;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_F32:
|
|
|
|
filter->process = gst_level_calculate_gfloat;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_FORMAT_F64:
|
|
|
|
filter->process = gst_level_calculate_gdouble;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
filter->process = NULL;
|
|
|
|
break;
|
2007-02-21 10:18:12 +00:00
|
|
|
}
|
2003-11-19 03:46:21 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
filter->info = info;
|
|
|
|
|
|
|
|
channels = GST_AUDIO_INFO_CHANNELS (&info);
|
|
|
|
rate = GST_AUDIO_INFO_RATE (&info);
|
|
|
|
|
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);
|
2005-09-24 12:10:02 +00:00
|
|
|
g_free (filter->decay_peak_base);
|
2004-07-26 18:34:01 +00:00
|
|
|
g_free (filter->decay_peak_age);
|
2011-08-19 12:01:45 +00:00
|
|
|
filter->CS = g_new (gdouble, channels);
|
|
|
|
filter->peak = g_new (gdouble, channels);
|
|
|
|
filter->last_peak = g_new (gdouble, channels);
|
|
|
|
filter->decay_peak = g_new (gdouble, channels);
|
|
|
|
filter->decay_peak_base = g_new (gdouble, channels);
|
2005-09-23 18:15:51 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
filter->decay_peak_age = g_new (GstClockTime, channels);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
for (i = 0; i < channels; ++i) {
|
2003-11-19 03:46:21 +00:00
|
|
|
filter->CS[i] = filter->peak[i] = filter->last_peak[i] =
|
2005-09-24 12:10:02 +00:00
|
|
|
filter->decay_peak[i] = filter->decay_peak_base[i] = 0.0;
|
2009-10-31 22:14:08 +00:00
|
|
|
filter->decay_peak_age[i] = G_GUINT64_CONSTANT (0);
|
2003-11-19 03:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
filter->interval_frames = GST_CLOCK_TIME_TO_FRAMES (filter->interval, rate);
|
2009-10-31 22:29:24 +00:00
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:24:05 +00:00
|
|
|
static gboolean
|
|
|
|
gst_level_start (GstBaseTransform * trans)
|
|
|
|
{
|
|
|
|
GstLevel *filter = GST_LEVEL (trans);
|
|
|
|
|
|
|
|
filter->num_frames = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
static GstMessage *
|
2008-08-10 15:52:42 +00:00
|
|
|
gst_level_message_new (GstLevel * level, GstClockTime timestamp,
|
2008-08-10 11:32:03 +00:00
|
|
|
GstClockTime duration)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2008-08-11 10:53:06 +00:00
|
|
|
GstBaseTransform *trans = GST_BASE_TRANSFORM_CAST (level);
|
2005-07-04 14:02:46 +00:00
|
|
|
GstStructure *s;
|
|
|
|
GValue v = { 0, };
|
2008-08-10 11:32:03 +00:00
|
|
|
GstClockTime endtime, running_time, stream_time;
|
2005-07-04 14:02:46 +00:00
|
|
|
|
2008-08-10 11:32:03 +00:00
|
|
|
running_time = gst_segment_to_running_time (&trans->segment, GST_FORMAT_TIME,
|
|
|
|
timestamp);
|
|
|
|
stream_time = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
|
|
|
|
timestamp);
|
|
|
|
/* endtime is for backwards compatibility */
|
|
|
|
endtime = stream_time + duration;
|
|
|
|
|
|
|
|
s = gst_structure_new ("level",
|
|
|
|
"endtime", GST_TYPE_CLOCK_TIME, endtime,
|
|
|
|
"timestamp", G_TYPE_UINT64, timestamp,
|
|
|
|
"stream-time", G_TYPE_UINT64, stream_time,
|
|
|
|
"running-time", G_TYPE_UINT64, running_time,
|
|
|
|
"duration", G_TYPE_UINT64, duration, NULL);
|
2005-07-04 14:02:46 +00:00
|
|
|
|
2012-02-16 16:01:29 +00:00
|
|
|
g_value_init (&v, G_TYPE_VALUE_ARRAY);
|
|
|
|
g_value_take_boxed (&v, g_value_array_new (0));
|
|
|
|
gst_structure_take_value (s, "rms", &v);
|
|
|
|
|
|
|
|
g_value_init (&v, G_TYPE_VALUE_ARRAY);
|
|
|
|
g_value_take_boxed (&v, g_value_array_new (0));
|
|
|
|
gst_structure_take_value (s, "peak", &v);
|
|
|
|
|
|
|
|
g_value_init (&v, G_TYPE_VALUE_ARRAY);
|
|
|
|
g_value_take_boxed (&v, g_value_array_new (0));
|
|
|
|
gst_structure_take_value (s, "decay", &v);
|
2006-01-13 18:35:00 +00:00
|
|
|
|
2008-08-10 15:52:42 +00:00
|
|
|
return gst_message_new_element (GST_OBJECT (level), s);
|
2005-07-04 14:02:46 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
static void
|
|
|
|
gst_level_message_append_channel (GstMessage * m, gdouble rms, gdouble peak,
|
|
|
|
gdouble decay)
|
|
|
|
{
|
2012-02-16 16:01:29 +00:00
|
|
|
const GValue *array_val;
|
2005-07-04 14:02:46 +00:00
|
|
|
GstStructure *s;
|
2012-02-16 16:01:29 +00:00
|
|
|
GValueArray *arr;
|
2005-07-04 14:02:46 +00:00
|
|
|
GValue v = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&v, G_TYPE_DOUBLE);
|
|
|
|
|
|
|
|
s = (GstStructure *) gst_message_get_structure (m);
|
|
|
|
|
2012-02-16 16:01:29 +00:00
|
|
|
array_val = gst_structure_get_value (s, "rms");
|
|
|
|
arr = (GValueArray *) g_value_get_boxed (array_val);
|
2005-07-04 14:02:46 +00:00
|
|
|
g_value_set_double (&v, rms);
|
2012-02-16 16:01:29 +00:00
|
|
|
g_value_array_append (arr, &v); /* copies by value */
|
2005-07-04 14:02:46 +00:00
|
|
|
|
2012-02-16 16:01:29 +00:00
|
|
|
array_val = gst_structure_get_value (s, "peak");
|
|
|
|
arr = (GValueArray *) g_value_get_boxed (array_val);
|
2005-07-04 14:02:46 +00:00
|
|
|
g_value_set_double (&v, peak);
|
2012-02-16 16:01:29 +00:00
|
|
|
g_value_array_append (arr, &v); /* copies by value */
|
2005-07-04 14:02:46 +00:00
|
|
|
|
2012-02-16 16:01:29 +00:00
|
|
|
array_val = gst_structure_get_value (s, "decay");
|
|
|
|
arr = (GValueArray *) g_value_get_boxed (array_val);
|
2005-07-04 14:02:46 +00:00
|
|
|
g_value_set_double (&v, decay);
|
2012-02-16 16:01:29 +00:00
|
|
|
g_value_array_append (arr, &v); /* copies by value */
|
2006-01-13 18:35:00 +00:00
|
|
|
|
|
|
|
g_value_unset (&v);
|
2005-07-04 14:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2005-09-09 17:56:43 +00:00
|
|
|
gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
2005-07-04 14:02:46 +00:00
|
|
|
{
|
|
|
|
GstLevel *filter;
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
|
|
|
guint8 *in_data;
|
2011-06-30 08:38:49 +00:00
|
|
|
gsize in_size;
|
2009-10-16 18:14:14 +00:00
|
|
|
gdouble CS;
|
2007-11-26 10:04:49 +00:00
|
|
|
guint i;
|
2007-02-21 10:18:12 +00:00
|
|
|
guint num_frames = 0;
|
|
|
|
guint num_int_samples = 0; /* number of interleaved samples
|
2005-09-23 18:15:51 +00:00
|
|
|
* ie. total count for all channels combined */
|
2009-10-16 18:14:14 +00:00
|
|
|
GstClockTimeDiff falloff_time;
|
2011-08-19 12:01:45 +00:00
|
|
|
gint channels, rate, bps;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
filter = GST_LEVEL (trans);
|
2004-05-08 13:03:59 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
channels = GST_AUDIO_INFO_CHANNELS (&filter->info);
|
|
|
|
bps = GST_AUDIO_INFO_BPS (&filter->info);
|
|
|
|
rate = GST_AUDIO_INFO_RATE (&filter->info);
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (in, &map, GST_MAP_READ);
|
|
|
|
in_data = map.data;
|
|
|
|
in_size = map.size;
|
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
num_int_samples = in_size / bps;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2007-11-26 10:04:49 +00:00
|
|
|
GST_LOG_OBJECT (filter, "analyzing %u sample frames at ts %" GST_TIME_FORMAT,
|
|
|
|
num_int_samples, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (in)));
|
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
g_return_val_if_fail (num_int_samples % channels == 0, GST_FLOW_ERROR);
|
2003-09-21 12:21:49 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
num_frames = num_int_samples / channels;
|
2005-09-23 18:15:51 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
for (i = 0; i < channels; ++i) {
|
2007-11-26 12:26:20 +00:00
|
|
|
if (!GST_BUFFER_FLAG_IS_SET (in, GST_BUFFER_FLAG_GAP)) {
|
2011-08-19 12:01:45 +00:00
|
|
|
filter->process (in_data, num_int_samples, channels, &CS,
|
2007-11-26 12:26:20 +00:00
|
|
|
&filter->peak[i]);
|
|
|
|
GST_LOG_OBJECT (filter,
|
|
|
|
"channel %d, cumulative sum %f, peak %f, over %d samples/%d channels",
|
2011-08-19 12:01:45 +00:00
|
|
|
i, CS, filter->peak[i], num_int_samples, channels);
|
2007-11-26 12:26:20 +00:00
|
|
|
filter->CS[i] += CS;
|
|
|
|
} else {
|
|
|
|
filter->peak[i] = 0.0;
|
|
|
|
}
|
2011-08-19 12:01:45 +00:00
|
|
|
in_data += bps;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
filter->decay_peak_age[i] += GST_FRAMES_TO_CLOCK_TIME (num_frames, rate);
|
2005-09-24 12:10:02 +00:00
|
|
|
GST_LOG_OBJECT (filter, "filter peak info [%d]: decay peak %f, age %"
|
2005-09-23 18:15:51 +00:00
|
|
|
GST_TIME_FORMAT, i,
|
2005-09-24 12:10:02 +00:00
|
|
|
filter->decay_peak[i], GST_TIME_ARGS (filter->decay_peak_age[i]));
|
2005-08-10 10:54:02 +00:00
|
|
|
|
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
|
|
|
|
2005-09-24 12:10:02 +00:00
|
|
|
/* make decay peak fall off if too old */
|
2009-10-16 18:14:14 +00:00
|
|
|
falloff_time =
|
|
|
|
GST_CLOCK_DIFF (gst_gdouble_to_guint64 (filter->decay_peak_ttl),
|
|
|
|
filter->decay_peak_age[i]);
|
|
|
|
if (falloff_time > 0) {
|
|
|
|
gdouble falloff_dB;
|
|
|
|
gdouble falloff;
|
|
|
|
gdouble length; /* length of falloff time in seconds */
|
|
|
|
|
2009-10-31 22:29:57 +00:00
|
|
|
length = (gdouble) falloff_time / (gdouble) GST_SECOND;
|
2005-09-24 12:10:02 +00:00
|
|
|
falloff_dB = filter->decay_peak_falloff * length;
|
|
|
|
falloff = pow (10, falloff_dB / -20.0);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (filter,
|
|
|
|
"falloff: current %f, base %f, interval %" GST_TIME_FORMAT
|
|
|
|
", dB falloff %f, factor %e",
|
|
|
|
filter->decay_peak[i], filter->decay_peak_base[i],
|
|
|
|
GST_TIME_ARGS (falloff_time), falloff_dB, falloff);
|
|
|
|
filter->decay_peak[i] = filter->decay_peak_base[i] * falloff;
|
|
|
|
GST_LOG_OBJECT (filter,
|
|
|
|
"peak is %" GST_TIME_FORMAT " old, decayed with factor %e to %f",
|
|
|
|
GST_TIME_ARGS (filter->decay_peak_age[i]), falloff,
|
|
|
|
filter->decay_peak[i]);
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (filter, "peak not old enough, not decaying");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the peak of this run is higher, the decay peak gets reset */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (filter->peak[i] >= filter->decay_peak[i]) {
|
2005-09-23 18:15:51 +00:00
|
|
|
GST_LOG_OBJECT (filter, "new peak, %f", filter->peak[i]);
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->decay_peak[i] = filter->peak[i];
|
2005-09-24 12:10:02 +00:00
|
|
|
filter->decay_peak_base[i] = filter->peak[i];
|
2006-04-09 17:31:37 +00:00
|
|
|
filter->decay_peak_age[i] = G_GINT64_CONSTANT (0);
|
2003-09-21 12:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2008-08-10 11:32:03 +00:00
|
|
|
if (G_UNLIKELY (!filter->num_frames)) {
|
|
|
|
/* remember start timestamp for message */
|
|
|
|
filter->message_ts = GST_BUFFER_TIMESTAMP (in);
|
|
|
|
}
|
2007-11-26 10:04:49 +00:00
|
|
|
filter->num_frames += num_frames;
|
|
|
|
|
2005-09-24 12:10:02 +00:00
|
|
|
/* do we need to message ? */
|
2009-10-31 22:29:24 +00:00
|
|
|
if (filter->num_frames >= filter->interval_frames) {
|
2005-09-01 20:23:22 +00:00
|
|
|
if (filter->message) {
|
2005-07-04 14:02:46 +00:00
|
|
|
GstMessage *m;
|
2008-08-10 11:32:03 +00:00
|
|
|
GstClockTime duration =
|
2011-08-19 12:01:45 +00:00
|
|
|
GST_FRAMES_TO_CLOCK_TIME (filter->num_frames, rate);
|
2005-07-04 14:02:46 +00:00
|
|
|
|
2008-08-10 11:32:03 +00:00
|
|
|
m = gst_level_message_new (filter, filter->message_ts, duration);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-09-24 12:10:02 +00:00
|
|
|
GST_LOG_OBJECT (filter,
|
2008-08-10 11:32:03 +00:00
|
|
|
"message: ts %" GST_TIME_FORMAT ", num_frames %d",
|
|
|
|
GST_TIME_ARGS (filter->message_ts), filter->num_frames);
|
2005-09-24 12:10:02 +00:00
|
|
|
|
2011-08-19 12:01:45 +00:00
|
|
|
for (i = 0; i < channels; ++i) {
|
2009-10-16 18:14:14 +00:00
|
|
|
gdouble RMS;
|
|
|
|
gdouble RMSdB, lastdB, decaydB;
|
2005-09-24 12:10:02 +00:00
|
|
|
|
2005-09-23 18:15:51 +00:00
|
|
|
RMS = sqrt (filter->CS[i] / filter->num_frames);
|
2005-08-10 10:54:02 +00:00
|
|
|
GST_LOG_OBJECT (filter,
|
2005-09-24 12:10:02 +00:00
|
|
|
"message: channel %d, CS %f, num_frames %d, RMS %f",
|
|
|
|
i, filter->CS[i], filter->num_frames, RMS);
|
|
|
|
GST_LOG_OBJECT (filter,
|
|
|
|
"message: last_peak: %f, decay_peak: %f",
|
|
|
|
filter->last_peak[i], filter->decay_peak[i]);
|
2005-08-10 10:54:02 +00:00
|
|
|
/* RMS values are calculated in amplitude, so 20 * log 10 */
|
2010-08-24 11:25:02 +00:00
|
|
|
RMSdB = 20 * log10 (RMS + EPSILON);
|
2005-08-10 10:54:02 +00:00
|
|
|
/* peak values are square sums, ie. power, so 10 * log 10 */
|
2010-08-24 11:25:02 +00:00
|
|
|
lastdB = 10 * log10 (filter->last_peak[i] + EPSILON);
|
|
|
|
decaydB = 10 * log10 (filter->decay_peak[i] + EPSILON);
|
2005-08-10 10:54:02 +00:00
|
|
|
|
2005-09-24 12:10:02 +00:00
|
|
|
if (filter->decay_peak[i] < filter->last_peak[i]) {
|
2006-02-06 15:28:56 +00:00
|
|
|
/* this can happen in certain cases, for example when
|
|
|
|
* the last peak is between decay_peak and decay_peak_base */
|
|
|
|
GST_DEBUG_OBJECT (filter,
|
|
|
|
"message: decay peak dB %f smaller than last peak dB %f, copying",
|
2005-09-24 12:10:02 +00:00
|
|
|
decaydB, lastdB);
|
2006-02-06 15:28:56 +00:00
|
|
|
filter->decay_peak[i] = filter->last_peak[i];
|
2005-09-24 12:10:02 +00:00
|
|
|
}
|
2005-08-10 10:54:02 +00:00
|
|
|
GST_LOG_OBJECT (filter,
|
2005-09-24 12:10:02 +00:00
|
|
|
"message: RMS %f dB, peak %f dB, decay %f dB",
|
|
|
|
RMSdB, lastdB, decaydB);
|
2005-08-10 10:54:02 +00:00
|
|
|
|
|
|
|
gst_level_message_append_channel (m, RMSdB, lastdB, decaydB);
|
2005-07-04 14:02:46 +00:00
|
|
|
|
|
|
|
/* reset cumulative and normal peak */
|
2004-03-15 19:32:27 +00:00
|
|
|
filter->CS[i] = 0.0;
|
|
|
|
filter->last_peak[i] = 0.0;
|
2003-09-21 12:21:49 +00:00
|
|
|
}
|
2005-07-04 14:02:46 +00:00
|
|
|
|
|
|
|
gst_element_post_message (GST_ELEMENT (filter), m);
|
2003-09-21 12:21:49 +00:00
|
|
|
}
|
2005-09-23 18:15:51 +00:00
|
|
|
filter->num_frames = 0;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (in, &map);
|
2011-06-30 08:38:49 +00:00
|
|
|
|
2005-07-04 14:02:46 +00:00
|
|
|
return GST_FLOW_OK;
|
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
|
|
|
{
|
2008-05-08 10:20:52 +00:00
|
|
|
/*oil_init (); */
|
|
|
|
|
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",
|
2005-11-14 02:13:35 +00:00
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|