convert to using GstClockTime for all time values, finally.

Original commit message from CVS:
convert to using GstClockTime for all time values, finally.
parent 0cf8e97f
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>
* gst/auparse/Makefile.am:
......
......@@ -35,4 +35,4 @@ include $(top_srcdir)/common/release.mak
# include $(top_srcdir)/common/po.mak
check-valgrind:
@true
cd check && make check-valgrind
......@@ -97,6 +97,7 @@ GST_START_TEST (test_int16)
int i, j;
gint16 *data;
const GValue *list, *value;
GstClockTime endtime;
gdouble dB;
level = setup_level ();
......@@ -137,6 +138,7 @@ GST_START_TEST (test_int16)
fail_if (structure == NULL);
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
"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 */
for (i = 0; i < 2; ++i) {
......
common @ c7160d5b
Subproject commit 345fd9851051274dd758a19bbe33dbb561b4d303
Subproject commit c7160d5b7c76f00609cf7b6e9b782e99f626686c
plugin_LTLIBRARIES = libgstlevel.la
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_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
......
This diff is collapsed.
......@@ -59,7 +59,8 @@ struct _GstLevel {
gdouble decay_peak_ttl; /* time to live for peak in seconds */
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 */
gdouble *CS; /* normalized Cumulative Square */
......@@ -68,7 +69,7 @@ struct _GstLevel {
gdouble *decay_peak; /* running decaying normalized Peak */
gdouble *MS; /* normalized Mean Square of buffer */
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 {
......
......@@ -13,35 +13,41 @@ message_handler (GstBus * bus, GstMessage * message, gpointer data)
if (strcmp (name, "level") == 0) {
gint channels;
gdouble endtime, rms_dB, peak_dB, decay_dB;
GstClockTime endtime;
gdouble rms_dB, peak_dB, decay_dB;
gdouble rms;
const GValue *list;
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");
list = gst_structure_get_value (s, "rms");
/* we can get the number of channels as the length of any of the value
* lists */
list = gst_structure_get_value (s, "rms");
channels = gst_value_list_get_size (list);
/* we will only get values for the first channel, since we know sinesrc
* is mono */
value = gst_value_list_get_value (list, 0);
rms_dB = g_value_get_double (value);
list = gst_structure_get_value (s, "peak");
value = gst_value_list_get_value (list, 0);
peak_dB = g_value_get_double (value);
list = gst_structure_get_value (s, "decay");
value = gst_value_list_get_value (list, 0);
decay_dB = g_value_get_double (value);
g_print ("endtime: %f, channels: %d\n", endtime, channels);
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 */
rms = pow (10, rms_dB / 20);
g_print ("normalized rms value: %f\n", rms);
g_print ("endtime: %" GST_TIME_FORMAT ", channels: %d\n",
GST_TIME_ARGS (endtime), channels);
for (i = 0; i < channels; ++i) {
g_print ("channel %d\n", i);
list = gst_structure_get_value (s, "rms");
value = gst_value_list_get_value (list, i);
rms_dB = g_value_get_double (value);
list = gst_structure_get_value (s, "peak");
value = gst_value_list_get_value (list, i);
peak_dB = g_value_get_double (value);
list = gst_structure_get_value (s, "decay");
value = gst_value_list_get_value (list, i);
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 */
rms = pow (10, rms_dB / 20);
g_print (" normalized rms value: %f\n", rms);
}
}
}
/* 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
main (int argc, char *argv[])
{
GstElement *sinesrc, *level, *fakesink;
GstElement *sinesrc, *audioconvert, *level, *fakesink;
GstElement *pipeline;
GstCaps *caps;
GstBus *bus;
gint watch_id;
GMainLoop *loop;
gst_init (&argc, &argv);
caps = gst_caps_from_string ("audio/x-raw-int,channels=2");
pipeline = gst_pipeline_new (NULL);
g_assert (pipeline);
sinesrc = gst_element_factory_make ("sinesrc", NULL);
g_assert (sinesrc);
audioconvert = gst_element_factory_make ("audioconvert", NULL);
g_assert (audioconvert);
level = gst_element_factory_make ("level", NULL);
g_assert (level);
fakesink = gst_element_factory_make ("fakesink", NULL);
g_assert (fakesink);
gst_bin_add_many (GST_BIN (pipeline), sinesrc, level, fakesink, NULL);
gst_element_link (sinesrc, level);
gst_element_link (level, fakesink);
gst_bin_add_many (GST_BIN (pipeline), sinesrc, audioconvert, level,
fakesink, NULL);
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 */
g_object_set (G_OBJECT (level), "message", TRUE, NULL);
......
......@@ -97,6 +97,7 @@ GST_START_TEST (test_int16)
int i, j;
gint16 *data;
const GValue *list, *value;
GstClockTime endtime;
gdouble dB;
level = setup_level ();
......@@ -137,6 +138,7 @@ GST_START_TEST (test_int16)
fail_if (structure == NULL);
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
"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 */
for (i = 0; i < 2; ++i) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment