mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
convert to using GstClockTime for all time values, finally.
Original commit message from CVS: convert to using GstClockTime for all time values, finally.
This commit is contained in:
parent
0cf8e97f9c
commit
6115f0b56c
9 changed files with 147 additions and 78 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2005-09-23 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||||
|
|
||||||
|
* Makefile.am:
|
||||||
|
* check/elements/level.c: (GST_START_TEST):
|
||||||
|
* gst/level/Makefile.am:
|
||||||
|
* gst/level/gstlevel.c: (gst_level_class_init), (gst_level_init),
|
||||||
|
(gst_level_set_property), (gst_level_get_property),
|
||||||
|
(gst_level_set_caps), (gst_level_message_new),
|
||||||
|
(gst_level_transform_ip):
|
||||||
|
* gst/level/gstlevel.h:
|
||||||
|
* gst/level/level-example.c: (message_handler), (main):
|
||||||
|
convert to using GstClockTime for all time values, finally.
|
||||||
|
|
||||||
2005-09-23 Thomas Vander Stichele <thomas at apestaart dot org>
|
2005-09-23 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||||
|
|
||||||
* gst/auparse/Makefile.am:
|
* gst/auparse/Makefile.am:
|
||||||
|
|
|
@ -35,4 +35,4 @@ include $(top_srcdir)/common/release.mak
|
||||||
# include $(top_srcdir)/common/po.mak
|
# include $(top_srcdir)/common/po.mak
|
||||||
|
|
||||||
check-valgrind:
|
check-valgrind:
|
||||||
@true
|
cd check && make check-valgrind
|
||||||
|
|
|
@ -97,6 +97,7 @@ GST_START_TEST (test_int16)
|
||||||
int i, j;
|
int i, j;
|
||||||
gint16 *data;
|
gint16 *data;
|
||||||
const GValue *list, *value;
|
const GValue *list, *value;
|
||||||
|
GstClockTime endtime;
|
||||||
gdouble dB;
|
gdouble dB;
|
||||||
|
|
||||||
level = setup_level ();
|
level = setup_level ();
|
||||||
|
@ -137,6 +138,7 @@ GST_START_TEST (test_int16)
|
||||||
fail_if (structure == NULL);
|
fail_if (structure == NULL);
|
||||||
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
|
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
|
||||||
"level");
|
"level");
|
||||||
|
fail_unless (gst_structure_get_clock_time (structure, "endtime", &endtime));
|
||||||
|
|
||||||
/* block wave of half amplitude has -5.94 dB for rms, peak and decay */
|
/* block wave of half amplitude has -5.94 dB for rms, peak and decay */
|
||||||
for (i = 0; i < 2; ++i) {
|
for (i = 0; i < 2; ++i) {
|
||||||
|
|
2
common
2
common
|
@ -1 +1 @@
|
||||||
Subproject commit 345fd9851051274dd758a19bbe33dbb561b4d303
|
Subproject commit c7160d5b7c76f00609cf7b6e9b782e99f626686c
|
|
@ -1,7 +1,7 @@
|
||||||
plugin_LTLIBRARIES = libgstlevel.la
|
plugin_LTLIBRARIES = libgstlevel.la
|
||||||
|
|
||||||
libgstlevel_la_SOURCES = gstlevel.c
|
libgstlevel_la_SOURCES = gstlevel.c
|
||||||
libgstlevel_la_CFLAGS = $(GST_CFLAGS)
|
libgstlevel_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS)
|
||||||
libgstlevel_la_LIBADD = $(GST_BASE_LIBS)
|
libgstlevel_la_LIBADD = $(GST_BASE_LIBS)
|
||||||
libgstlevel_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
libgstlevel_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||||
|
|
||||||
|
|
|
@ -24,23 +24,47 @@
|
||||||
*
|
*
|
||||||
* <refsect2>
|
* <refsect2>
|
||||||
* <para>
|
* <para>
|
||||||
* Level analyses incoming audio buffers and generates an application
|
* Level analyses incoming audio buffers and, if the
|
||||||
* message per given interval of time.
|
* <link linkend="GstLevel--message">message property</link> is #TRUE.
|
||||||
|
* generates an application message named
|
||||||
|
* <classname>"level"</classname>:
|
||||||
|
* after each interval of time given by the
|
||||||
|
* <link linkend="GstLevel--interval">interval property</link>.
|
||||||
* The message's structure contains four fields:
|
* The message's structure contains four fields:
|
||||||
* <itemizedlist>
|
* <itemizedlist>
|
||||||
* <listitem>
|
* <listitem>
|
||||||
* <para>
|
* <para>
|
||||||
* <link linkend="gdouble">gdouble</link>
|
* #GstClockTime
|
||||||
* <classname>"endtime"</classname>:
|
* <classname>"endtime"</classname>:
|
||||||
* the end time of the buffer that
|
* the end time of the buffer that triggered the message
|
||||||
* triggered the message</para>
|
* </para>
|
||||||
* </listitem>
|
* </listitem>
|
||||||
* <listitem>
|
* <listitem>
|
||||||
* <para>
|
* <para>
|
||||||
* <link linkend="gdouble">gdouble</link>
|
* #GstValueList of #gdouble
|
||||||
* <classname>"endtime"</classname>:
|
* <classname>"peak"</classname>:
|
||||||
* the end time of the buffer that
|
* the peak power level in dB for each channel
|
||||||
* triggered the message</para>
|
* </para>
|
||||||
|
* </listitem>
|
||||||
|
* <listitem>
|
||||||
|
* <para>
|
||||||
|
* #GstValueList of #gdouble
|
||||||
|
* <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
|
||||||
|
* <link linkend="GstLevel--peak-falloff">the peak fallof rate</link>.
|
||||||
|
* </para>
|
||||||
|
* </listitem>
|
||||||
|
* <listitem>
|
||||||
|
* <para>
|
||||||
|
* #GstValueList of #gdouble
|
||||||
|
* <classname>"rms"</classname>:
|
||||||
|
* the Root Mean Square (or average power) level in dB for each channel
|
||||||
|
* </para>
|
||||||
* </listitem>
|
* </listitem>
|
||||||
* </itemizedlist>
|
* </itemizedlist>
|
||||||
* </para>
|
* </para>
|
||||||
|
@ -55,6 +79,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
#include <gst/audio/audio.h>
|
||||||
#include "gstlevel.h"
|
#include "gstlevel.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
|
@ -143,15 +168,16 @@ gst_level_class_init (GstLevelClass * klass)
|
||||||
|
|
||||||
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SIGNAL_LEVEL,
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SIGNAL_LEVEL,
|
||||||
g_param_spec_boolean ("message", "mesage",
|
g_param_spec_boolean ("message", "mesage",
|
||||||
"Post a level message for each interval", TRUE, G_PARAM_READWRITE));
|
"Post a level message for each passed interval",
|
||||||
|
TRUE, G_PARAM_READWRITE));
|
||||||
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SIGNAL_INTERVAL,
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SIGNAL_INTERVAL,
|
||||||
g_param_spec_double ("interval", "Interval",
|
g_param_spec_uint64 ("interval", "Interval",
|
||||||
"Interval between posts (in seconds)",
|
"Interval of time between message posts (in nanoseconds)",
|
||||||
0.01, 100.0, 0.1, G_PARAM_READWRITE));
|
1, G_MAXUINT64, GST_SECOND / 10, G_PARAM_READWRITE));
|
||||||
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PEAK_TTL,
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PEAK_TTL,
|
||||||
g_param_spec_double ("peak_ttl", "Peak TTL",
|
g_param_spec_uint64 ("peak_ttl", "Peak TTL",
|
||||||
"Time To Live of decay peak before it falls back",
|
"Time To Live of decay peak before it falls back (in nanoseconds)",
|
||||||
0, 100.0, 0.3, G_PARAM_READWRITE));
|
0, G_MAXUINT64, GST_SECOND / 10 * 3, G_PARAM_READWRITE));
|
||||||
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PEAK_FALLOFF,
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PEAK_FALLOFF,
|
||||||
g_param_spec_double ("peak_falloff", "Peak Falloff",
|
g_param_spec_double ("peak_falloff", "Peak Falloff",
|
||||||
"Decay rate of decay peak after TTL (in dB/sec)",
|
"Decay rate of decay peak after TTL (in dB/sec)",
|
||||||
|
@ -175,8 +201,8 @@ gst_level_init (GstLevel * filter, GstLevelClass * g_class)
|
||||||
filter->width = 0;
|
filter->width = 0;
|
||||||
filter->channels = 0;
|
filter->channels = 0;
|
||||||
|
|
||||||
filter->interval = 0.1;
|
filter->interval = GST_SECOND / 10;
|
||||||
filter->decay_peak_ttl = 0.4;
|
filter->decay_peak_ttl = GST_SECOND / 10 * 3;
|
||||||
filter->decay_peak_falloff = 10.0; /* dB falloff (/sec) */
|
filter->decay_peak_falloff = 10.0; /* dB falloff (/sec) */
|
||||||
|
|
||||||
filter->message = TRUE;
|
filter->message = TRUE;
|
||||||
|
@ -193,10 +219,10 @@ gst_level_set_property (GObject * object, guint prop_id,
|
||||||
filter->message = g_value_get_boolean (value);
|
filter->message = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
case PROP_SIGNAL_INTERVAL:
|
case PROP_SIGNAL_INTERVAL:
|
||||||
filter->interval = g_value_get_double (value);
|
filter->interval = g_value_get_uint64 (value);
|
||||||
break;
|
break;
|
||||||
case PROP_PEAK_TTL:
|
case PROP_PEAK_TTL:
|
||||||
filter->decay_peak_ttl = g_value_get_double (value);
|
filter->decay_peak_ttl = g_value_get_uint64 (value);
|
||||||
break;
|
break;
|
||||||
case PROP_PEAK_FALLOFF:
|
case PROP_PEAK_FALLOFF:
|
||||||
filter->decay_peak_falloff = g_value_get_double (value);
|
filter->decay_peak_falloff = g_value_get_double (value);
|
||||||
|
@ -217,10 +243,10 @@ gst_level_get_property (GObject * object, guint prop_id,
|
||||||
g_value_set_boolean (value, filter->message);
|
g_value_set_boolean (value, filter->message);
|
||||||
break;
|
break;
|
||||||
case PROP_SIGNAL_INTERVAL:
|
case PROP_SIGNAL_INTERVAL:
|
||||||
g_value_set_double (value, filter->interval);
|
g_value_set_uint64 (value, filter->interval);
|
||||||
break;
|
break;
|
||||||
case PROP_PEAK_TTL:
|
case PROP_PEAK_TTL:
|
||||||
g_value_set_double (value, filter->decay_peak_ttl);
|
g_value_set_uint64 (value, filter->decay_peak_ttl);
|
||||||
break;
|
break;
|
||||||
case PROP_PEAK_FALLOFF:
|
case PROP_PEAK_FALLOFF:
|
||||||
g_value_set_double (value, filter->decay_peak_falloff);
|
g_value_set_double (value, filter->decay_peak_falloff);
|
||||||
|
@ -251,7 +277,7 @@ gst_level_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
|
||||||
|
|
||||||
filter = GST_LEVEL (trans);
|
filter = GST_LEVEL (trans);
|
||||||
|
|
||||||
filter->num_samples = 0;
|
filter->num_frames = 0;
|
||||||
|
|
||||||
structure = gst_caps_get_structure (in, 0);
|
structure = gst_caps_get_structure (in, 0);
|
||||||
filter->rate = structure_get_int (structure, "rate");
|
filter->rate = structure_get_int (structure, "rate");
|
||||||
|
@ -269,13 +295,14 @@ gst_level_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
|
||||||
filter->peak = g_new (double, filter->channels);
|
filter->peak = g_new (double, filter->channels);
|
||||||
filter->last_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 = g_new (double, filter->channels);
|
||||||
filter->decay_peak_age = g_new (double, filter->channels);
|
|
||||||
|
filter->decay_peak_age = g_new (GstClockTime, filter->channels);
|
||||||
filter->RMS_dB = g_new (double, filter->channels);
|
filter->RMS_dB = g_new (double, filter->channels);
|
||||||
|
|
||||||
for (i = 0; i < filter->channels; ++i) {
|
for (i = 0; i < filter->channels; ++i) {
|
||||||
filter->CS[i] = filter->peak[i] = filter->last_peak[i] =
|
filter->CS[i] = filter->peak[i] = filter->last_peak[i] =
|
||||||
filter->decay_peak[i] = filter->decay_peak_age[i] =
|
filter->decay_peak[i] = filter->RMS_dB[i] = 0.0;
|
||||||
filter->RMS_dB[i] = 0.0;
|
filter->decay_peak_age[i] = 0LL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -326,14 +353,15 @@ DEFINE_LEVEL_CALCULATOR (gint16);
|
||||||
DEFINE_LEVEL_CALCULATOR (gint8);
|
DEFINE_LEVEL_CALCULATOR (gint8);
|
||||||
|
|
||||||
static GstMessage *
|
static GstMessage *
|
||||||
gst_level_message_new (GstLevel * l, gdouble endtime)
|
gst_level_message_new (GstLevel * l, GstClockTime endtime)
|
||||||
{
|
{
|
||||||
GstStructure *s;
|
GstStructure *s;
|
||||||
GValue v = { 0, };
|
GValue v = { 0, };
|
||||||
|
|
||||||
g_value_init (&v, GST_TYPE_LIST);
|
g_value_init (&v, GST_TYPE_LIST);
|
||||||
|
|
||||||
s = gst_structure_new ("level", "endtime", G_TYPE_DOUBLE, endtime, NULL);
|
s = gst_structure_new ("level", "endtime", GST_TYPE_CLOCK_TIME,
|
||||||
|
endtime, NULL);
|
||||||
/* will copy-by-value */
|
/* will copy-by-value */
|
||||||
gst_structure_set_value (s, "rms", &v);
|
gst_structure_set_value (s, "rms", &v);
|
||||||
gst_structure_set_value (s, "peak", &v);
|
gst_structure_set_value (s, "peak", &v);
|
||||||
|
@ -373,7 +401,9 @@ gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
GstLevel *filter;
|
GstLevel *filter;
|
||||||
gpointer in_data;
|
gpointer in_data;
|
||||||
double CS = 0.0;
|
double CS = 0.0;
|
||||||
gint num_int_samples = 0; /* number of samples for all channels combined */
|
gint num_frames = 0;
|
||||||
|
gint num_int_samples = 0; /* number of interleaved samples
|
||||||
|
* ie. total count for all channels combined */
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
filter = GST_LEVEL (trans);
|
filter = GST_LEVEL (trans);
|
||||||
|
@ -387,6 +417,8 @@ gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
g_return_val_if_fail (num_int_samples % filter->channels == 0,
|
g_return_val_if_fail (num_int_samples % filter->channels == 0,
|
||||||
GST_FLOW_ERROR);
|
GST_FLOW_ERROR);
|
||||||
|
|
||||||
|
num_frames = num_int_samples / filter->channels;
|
||||||
|
|
||||||
for (i = 0; i < filter->channels; ++i) {
|
for (i = 0; i < filter->channels; ++i) {
|
||||||
CS = 0.0;
|
CS = 0.0;
|
||||||
switch (filter->width) {
|
switch (filter->width) {
|
||||||
|
@ -405,12 +437,14 @@ gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
filter->CS[i] += CS;
|
filter->CS[i] += CS;
|
||||||
}
|
}
|
||||||
|
|
||||||
filter->num_samples += num_int_samples / filter->channels;
|
filter->num_frames += num_frames;
|
||||||
|
|
||||||
for (i = 0; i < filter->channels; ++i) {
|
for (i = 0; i < filter->channels; ++i) {
|
||||||
filter->decay_peak_age[i] += num_int_samples / filter->channels;
|
filter->decay_peak_age[i] +=
|
||||||
GST_LOG_OBJECT (filter, "filter peak info [%d]: peak %f, age %f\n", i,
|
GST_FRAMES_TO_CLOCK_TIME (num_frames, filter->rate);
|
||||||
filter->last_peak[i], filter->decay_peak_age[i]);
|
GST_LOG_OBJECT (filter, "filter peak info [%d]: peak %f, age %"
|
||||||
|
GST_TIME_FORMAT, i,
|
||||||
|
filter->last_peak[i], GST_TIME_ARGS (filter->decay_peak_age[i]));
|
||||||
|
|
||||||
/* update running peak */
|
/* update running peak */
|
||||||
if (filter->peak[i] > filter->last_peak[i])
|
if (filter->peak[i] > filter->last_peak[i])
|
||||||
|
@ -418,28 +452,29 @@ gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
|
|
||||||
/* update decay peak */
|
/* update decay peak */
|
||||||
if (filter->peak[i] >= filter->decay_peak[i]) {
|
if (filter->peak[i] >= filter->decay_peak[i]) {
|
||||||
GST_LOG_OBJECT (filter, "new peak, %f\n", filter->peak[i]);
|
GST_LOG_OBJECT (filter, "new peak, %f", filter->peak[i]);
|
||||||
filter->decay_peak[i] = filter->peak[i];
|
filter->decay_peak[i] = filter->peak[i];
|
||||||
filter->decay_peak_age[i] = 0;
|
filter->decay_peak_age[i] = 0LL;
|
||||||
} else {
|
} else {
|
||||||
/* make decay peak fall off if too old */
|
/* make decay peak fall off if too old */
|
||||||
if (filter->decay_peak_age[i] > filter->rate * filter->decay_peak_ttl) {
|
if (filter->decay_peak_age[i] > filter->decay_peak_ttl) {
|
||||||
double falloff_dB;
|
double falloff_dB;
|
||||||
double falloff;
|
double falloff;
|
||||||
double length; /* length of buffer in seconds */
|
double length; /* length of buffer in seconds */
|
||||||
|
|
||||||
|
|
||||||
length = (double) num_int_samples / (filter->channels * filter->rate);
|
length = (double) num_frames / filter->rate;
|
||||||
falloff_dB = filter->decay_peak_falloff * length;
|
falloff_dB = filter->decay_peak_falloff * length;
|
||||||
falloff = pow (10, falloff_dB / -20.0);
|
falloff = pow (10, falloff_dB / -20.0);
|
||||||
|
|
||||||
GST_LOG_OBJECT (filter,
|
GST_LOG_OBJECT (filter,
|
||||||
"falloff: length %f, dB falloff %f, falloff factor %e\n",
|
"falloff: length %f, dB falloff %f, falloff factor %e",
|
||||||
length, falloff_dB, falloff);
|
length, falloff_dB, falloff);
|
||||||
filter->decay_peak[i] *= falloff;
|
filter->decay_peak[i] *= falloff;
|
||||||
GST_LOG_OBJECT (filter,
|
GST_LOG_OBJECT (filter,
|
||||||
"peak is %f samples old, decayed with factor %e to %f\n",
|
"peak is %" GST_TIME_FORMAT " old, decayed with factor %e to %f",
|
||||||
filter->decay_peak_age[i], falloff, filter->decay_peak[i]);
|
GST_TIME_ARGS (filter->decay_peak_age[i]), falloff,
|
||||||
|
filter->decay_peak[i]);
|
||||||
} else {
|
} else {
|
||||||
GST_LOG_OBJECT (filter, "peak not old enough, not decaying");
|
GST_LOG_OBJECT (filter, "peak not old enough, not decaying");
|
||||||
}
|
}
|
||||||
|
@ -448,23 +483,25 @@ gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
|
|
||||||
/* do we need to emit ? */
|
/* do we need to emit ? */
|
||||||
|
|
||||||
if (filter->num_samples >= (gint) (filter->interval * filter->rate)) {
|
if (filter->num_frames >=
|
||||||
|
(gint) ((gdouble) filter->interval / GST_SECOND * filter->rate)) {
|
||||||
if (filter->message) {
|
if (filter->message) {
|
||||||
GstMessage *m;
|
GstMessage *m;
|
||||||
double endtime, RMS;
|
GstClockTime endtime;
|
||||||
|
double RMS;
|
||||||
double RMSdB, lastdB, decaydB;
|
double RMSdB, lastdB, decaydB;
|
||||||
|
|
||||||
/* FIXME: convert to a GstClockTime instead */
|
/* FIXME: convert to a GstClockTime instead */
|
||||||
endtime = (double) GST_BUFFER_TIMESTAMP (in) / GST_SECOND
|
endtime = GST_BUFFER_TIMESTAMP (in)
|
||||||
+ (double) num_int_samples / (filter->rate * filter->channels);
|
+ GST_FRAMES_TO_CLOCK_TIME (num_frames, filter->rate);
|
||||||
|
|
||||||
m = gst_level_message_new (filter, endtime);
|
m = gst_level_message_new (filter, endtime);
|
||||||
|
|
||||||
for (i = 0; i < filter->channels; ++i) {
|
for (i = 0; i < filter->channels; ++i) {
|
||||||
RMS = sqrt (filter->CS[i] / filter->num_samples);
|
RMS = sqrt (filter->CS[i] / filter->num_frames);
|
||||||
GST_LOG_OBJECT (filter,
|
GST_LOG_OBJECT (filter,
|
||||||
"CS: %f, num_samples %d, channel %d, RMS %f",
|
"CS: %f, num_frames %d, channel %d, RMS %f",
|
||||||
filter->CS[i], filter->num_samples, i, RMS);
|
filter->CS[i], filter->num_frames, i, RMS);
|
||||||
/* RMS values are calculated in amplitude, so 20 * log 10 */
|
/* RMS values are calculated in amplitude, so 20 * log 10 */
|
||||||
RMSdB = 20 * log10 (RMS);
|
RMSdB = 20 * log10 (RMS);
|
||||||
/* peak values are square sums, ie. power, so 10 * log 10 */
|
/* peak values are square sums, ie. power, so 10 * log 10 */
|
||||||
|
@ -472,8 +509,9 @@ gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
decaydB = 10 * log10 (filter->decay_peak[i]);
|
decaydB = 10 * log10 (filter->decay_peak[i]);
|
||||||
|
|
||||||
GST_LOG_OBJECT (filter,
|
GST_LOG_OBJECT (filter,
|
||||||
"time %f, channel %d, RMS %f dB, peak %f dB, decay %f dB",
|
"time %" GST_TIME_FORMAT
|
||||||
endtime, i, RMSdB, lastdB, decaydB);
|
", channel %d, RMS %f dB, peak %f dB, decay %f dB",
|
||||||
|
GST_TIME_ARGS (endtime), i, RMSdB, lastdB, decaydB);
|
||||||
|
|
||||||
gst_level_message_append_channel (m, RMSdB, lastdB, decaydB);
|
gst_level_message_append_channel (m, RMSdB, lastdB, decaydB);
|
||||||
|
|
||||||
|
@ -484,7 +522,7 @@ gst_level_transform_ip (GstBaseTransform * trans, GstBuffer * in)
|
||||||
|
|
||||||
gst_element_post_message (GST_ELEMENT (filter), m);
|
gst_element_post_message (GST_ELEMENT (filter), m);
|
||||||
}
|
}
|
||||||
filter->num_samples = 0;
|
filter->num_frames = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
|
|
@ -59,7 +59,8 @@ struct _GstLevel {
|
||||||
|
|
||||||
gdouble decay_peak_ttl; /* time to live for peak in seconds */
|
gdouble decay_peak_ttl; /* time to live for peak in seconds */
|
||||||
gdouble decay_peak_falloff; /* falloff in dB/sec */
|
gdouble decay_peak_falloff; /* falloff in dB/sec */
|
||||||
gint num_samples; /* one-channel sample count since last emit */
|
gint num_frames; /* frame count (1 sample per channel)
|
||||||
|
* since last emit */
|
||||||
|
|
||||||
/* per-channel arrays for intermediate values */
|
/* per-channel arrays for intermediate values */
|
||||||
gdouble *CS; /* normalized Cumulative Square */
|
gdouble *CS; /* normalized Cumulative Square */
|
||||||
|
@ -68,7 +69,7 @@ struct _GstLevel {
|
||||||
gdouble *decay_peak; /* running decaying normalized Peak */
|
gdouble *decay_peak; /* running decaying normalized Peak */
|
||||||
gdouble *MS; /* normalized Mean Square of buffer */
|
gdouble *MS; /* normalized Mean Square of buffer */
|
||||||
gdouble *RMS_dB; /* RMS in dB to emit */
|
gdouble *RMS_dB; /* RMS in dB to emit */
|
||||||
gdouble *decay_peak_age; /* age of last peak in one-channel samples */
|
GstClockTime *decay_peak_age; /* age of last peak */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstLevelClass {
|
struct _GstLevelClass {
|
||||||
|
|
|
@ -13,35 +13,41 @@ message_handler (GstBus * bus, GstMessage * message, gpointer data)
|
||||||
|
|
||||||
if (strcmp (name, "level") == 0) {
|
if (strcmp (name, "level") == 0) {
|
||||||
gint channels;
|
gint channels;
|
||||||
gdouble endtime, rms_dB, peak_dB, decay_dB;
|
GstClockTime endtime;
|
||||||
|
gdouble rms_dB, peak_dB, decay_dB;
|
||||||
gdouble rms;
|
gdouble rms;
|
||||||
const GValue *list;
|
const GValue *list;
|
||||||
const GValue *value;
|
const GValue *value;
|
||||||
|
|
||||||
if (!gst_structure_get_double (s, "endtime", &endtime))
|
gint i;
|
||||||
|
|
||||||
|
if (!gst_structure_get_clock_time (s, "endtime", &endtime))
|
||||||
g_warning ("Could not parse endtime");
|
g_warning ("Could not parse endtime");
|
||||||
list = gst_structure_get_value (s, "rms");
|
|
||||||
/* we can get the number of channels as the length of any of the value
|
/* we can get the number of channels as the length of any of the value
|
||||||
* lists */
|
* lists */
|
||||||
|
list = gst_structure_get_value (s, "rms");
|
||||||
channels = gst_value_list_get_size (list);
|
channels = gst_value_list_get_size (list);
|
||||||
|
|
||||||
/* we will only get values for the first channel, since we know sinesrc
|
g_print ("endtime: %" GST_TIME_FORMAT ", channels: %d\n",
|
||||||
* is mono */
|
GST_TIME_ARGS (endtime), channels);
|
||||||
value = gst_value_list_get_value (list, 0);
|
for (i = 0; i < channels; ++i) {
|
||||||
rms_dB = g_value_get_double (value);
|
g_print ("channel %d\n", i);
|
||||||
list = gst_structure_get_value (s, "peak");
|
list = gst_structure_get_value (s, "rms");
|
||||||
value = gst_value_list_get_value (list, 0);
|
value = gst_value_list_get_value (list, i);
|
||||||
peak_dB = g_value_get_double (value);
|
rms_dB = g_value_get_double (value);
|
||||||
list = gst_structure_get_value (s, "decay");
|
list = gst_structure_get_value (s, "peak");
|
||||||
value = gst_value_list_get_value (list, 0);
|
value = gst_value_list_get_value (list, i);
|
||||||
decay_dB = g_value_get_double (value);
|
peak_dB = g_value_get_double (value);
|
||||||
g_print ("endtime: %f, channels: %d\n", endtime, channels);
|
list = gst_structure_get_value (s, "decay");
|
||||||
g_print ("RMS: %f dB, peak: %f dB, decay: %f dB\n",
|
value = gst_value_list_get_value (list, i);
|
||||||
rms_dB, peak_dB, decay_dB);
|
decay_dB = g_value_get_double (value);
|
||||||
|
g_print (" RMS: %f dB, peak: %f dB, decay: %f dB\n",
|
||||||
|
rms_dB, peak_dB, decay_dB);
|
||||||
|
|
||||||
/* converting from dB to normal gives us a value between 0.0 and 1.0 */
|
/* converting from dB to normal gives us a value between 0.0 and 1.0 */
|
||||||
rms = pow (10, rms_dB / 20);
|
rms = pow (10, rms_dB / 20);
|
||||||
g_print ("normalized rms value: %f\n", rms);
|
g_print (" normalized rms value: %f\n", rms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* we handled the message we want, and ignored the ones we didn't want.
|
/* we handled the message we want, and ignored the ones we didn't want.
|
||||||
|
@ -52,26 +58,33 @@ message_handler (GstBus * bus, GstMessage * message, gpointer data)
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
GstElement *sinesrc, *level, *fakesink;
|
GstElement *sinesrc, *audioconvert, *level, *fakesink;
|
||||||
GstElement *pipeline;
|
GstElement *pipeline;
|
||||||
|
GstCaps *caps;
|
||||||
GstBus *bus;
|
GstBus *bus;
|
||||||
gint watch_id;
|
gint watch_id;
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
|
|
||||||
gst_init (&argc, &argv);
|
gst_init (&argc, &argv);
|
||||||
|
|
||||||
|
caps = gst_caps_from_string ("audio/x-raw-int,channels=2");
|
||||||
|
|
||||||
pipeline = gst_pipeline_new (NULL);
|
pipeline = gst_pipeline_new (NULL);
|
||||||
g_assert (pipeline);
|
g_assert (pipeline);
|
||||||
sinesrc = gst_element_factory_make ("sinesrc", NULL);
|
sinesrc = gst_element_factory_make ("sinesrc", NULL);
|
||||||
g_assert (sinesrc);
|
g_assert (sinesrc);
|
||||||
|
audioconvert = gst_element_factory_make ("audioconvert", NULL);
|
||||||
|
g_assert (audioconvert);
|
||||||
level = gst_element_factory_make ("level", NULL);
|
level = gst_element_factory_make ("level", NULL);
|
||||||
g_assert (level);
|
g_assert (level);
|
||||||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||||
g_assert (fakesink);
|
g_assert (fakesink);
|
||||||
|
|
||||||
gst_bin_add_many (GST_BIN (pipeline), sinesrc, level, fakesink, NULL);
|
gst_bin_add_many (GST_BIN (pipeline), sinesrc, audioconvert, level,
|
||||||
gst_element_link (sinesrc, level);
|
fakesink, NULL);
|
||||||
gst_element_link (level, fakesink);
|
g_assert (gst_element_link (sinesrc, audioconvert));
|
||||||
|
g_assert (gst_element_link_filtered (audioconvert, level, caps));
|
||||||
|
g_assert (gst_element_link (level, fakesink));
|
||||||
|
|
||||||
/* make sure we'll get messages */
|
/* make sure we'll get messages */
|
||||||
g_object_set (G_OBJECT (level), "message", TRUE, NULL);
|
g_object_set (G_OBJECT (level), "message", TRUE, NULL);
|
||||||
|
|
|
@ -97,6 +97,7 @@ GST_START_TEST (test_int16)
|
||||||
int i, j;
|
int i, j;
|
||||||
gint16 *data;
|
gint16 *data;
|
||||||
const GValue *list, *value;
|
const GValue *list, *value;
|
||||||
|
GstClockTime endtime;
|
||||||
gdouble dB;
|
gdouble dB;
|
||||||
|
|
||||||
level = setup_level ();
|
level = setup_level ();
|
||||||
|
@ -137,6 +138,7 @@ GST_START_TEST (test_int16)
|
||||||
fail_if (structure == NULL);
|
fail_if (structure == NULL);
|
||||||
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
|
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
|
||||||
"level");
|
"level");
|
||||||
|
fail_unless (gst_structure_get_clock_time (structure, "endtime", &endtime));
|
||||||
|
|
||||||
/* block wave of half amplitude has -5.94 dB for rms, peak and decay */
|
/* block wave of half amplitude has -5.94 dB for rms, peak and decay */
|
||||||
for (i = 0; i < 2; ++i) {
|
for (i = 0; i < 2; ++i) {
|
||||||
|
|
Loading…
Reference in a new issue