From 3eb8f5393d4764df6f601bf6c4c4acb1724482d9 Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Fri, 17 Aug 2012 14:31:50 +0200 Subject: equalizer: enable presets for the n-band equalizer Add a test for saving and restoring the preset. --- gst/equalizer/gstiirequalizer.c | 7 +++++ gst/equalizer/gstiirequalizer10bands.c | 18 ++---------- gst/equalizer/gstiirequalizer3bands.c | 18 ++---------- tests/check/elements/equalizer.c | 52 ++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/gst/equalizer/gstiirequalizer.c b/gst/equalizer/gstiirequalizer.c index ffd2c4348..bf9ec4d9d 100644 --- a/gst/equalizer/gstiirequalizer.c +++ b/gst/equalizer/gstiirequalizer.c @@ -71,9 +71,16 @@ _do_init (GType object_type) NULL, /* interface_finalize */ NULL /* interface_data */ }; + const GInterfaceInfo preset_interface_info = { + NULL, /* interface_init */ + NULL, /* interface_finalize */ + NULL /* interface_data */ + }; g_type_add_interface_static (object_type, GST_TYPE_CHILD_PROXY, &child_proxy_interface_info); + g_type_add_interface_static (object_type, GST_TYPE_PRESET, + &preset_interface_info); } GST_BOILERPLATE_FULL (GstIirEqualizer, gst_iir_equalizer, diff --git a/gst/equalizer/gstiirequalizer10bands.c b/gst/equalizer/gstiirequalizer10bands.c index 5680309ab..1afabc0a1 100644 --- a/gst/equalizer/gstiirequalizer10bands.c +++ b/gst/equalizer/gstiirequalizer10bands.c @@ -61,22 +61,8 @@ static void gst_iir_equalizer_10bands_get_property (GObject * object, GST_DEBUG_CATEGORY_EXTERN (equalizer_debug); #define GST_CAT_DEFAULT equalizer_debug - -static void -_do_init (GType object_type) -{ - const GInterfaceInfo preset_interface_info = { - NULL, /* interface_init */ - NULL, /* interface_finalize */ - NULL /* interface_data */ - }; - - g_type_add_interface_static (object_type, GST_TYPE_PRESET, - &preset_interface_info); -} - -GST_BOILERPLATE_FULL (GstIirEqualizer10Bands, gst_iir_equalizer_10bands, - GstIirEqualizer, GST_TYPE_IIR_EQUALIZER, _do_init); +GST_BOILERPLATE (GstIirEqualizer10Bands, gst_iir_equalizer_10bands, + GstIirEqualizer, GST_TYPE_IIR_EQUALIZER); /* equalizer implementation */ diff --git a/gst/equalizer/gstiirequalizer3bands.c b/gst/equalizer/gstiirequalizer3bands.c index 71fcfb6ea..c125c7322 100644 --- a/gst/equalizer/gstiirequalizer3bands.c +++ b/gst/equalizer/gstiirequalizer3bands.c @@ -53,22 +53,8 @@ static void gst_iir_equalizer_3bands_get_property (GObject * object, GST_DEBUG_CATEGORY_EXTERN (equalizer_debug); #define GST_CAT_DEFAULT equalizer_debug - -static void -_do_init (GType object_type) -{ - const GInterfaceInfo preset_interface_info = { - NULL, /* interface_init */ - NULL, /* interface_finalize */ - NULL /* interface_data */ - }; - - g_type_add_interface_static (object_type, GST_TYPE_PRESET, - &preset_interface_info); -} - -GST_BOILERPLATE_FULL (GstIirEqualizer3Bands, gst_iir_equalizer_3bands, - GstIirEqualizer, GST_TYPE_IIR_EQUALIZER, _do_init); +GST_BOILERPLATE (GstIirEqualizer3Bands, gst_iir_equalizer_3bands, + GstIirEqualizer, GST_TYPE_IIR_EQUALIZER); /* equalizer implementation */ diff --git a/tests/check/elements/equalizer.c b/tests/check/elements/equalizer.c index 29b2e3862..ea76581bc 100644 --- a/tests/check/elements/equalizer.c +++ b/tests/check/elements/equalizer.c @@ -294,6 +294,57 @@ GST_START_TEST (test_equalizer_band_number_changing) GST_END_TEST; +GST_START_TEST (test_equalizer_presets) +{ + GstElement *eq1, *eq2; + gint type; + gdouble gain, freq; + + eq1 = gst_check_setup_element ("equalizer-nbands"); + g_object_set (G_OBJECT (eq1), "num-bands", 3, NULL); + + /* set properties to non-defaults */ + gst_child_proxy_set ((GstObject *) eq1, + "band0::type", 0, "band0::gain", -3.0, "band0::freq", 100.0, + "band1::type", 1, "band1::gain", +3.0, "band1::freq", 1000.0, + "band2::type", 2, "band2::gain", +9.0, "band2::freq", 10000.0, NULL); + + /* save preset */ + gst_preset_save_preset ((GstPreset *) eq1, "_testpreset_"); + GST_INFO_OBJECT (eq1, "Preset saved"); + + eq2 = gst_check_setup_element ("equalizer-nbands"); + g_object_set (G_OBJECT (eq2), "num-bands", 3, NULL); + + /* load preset */ + gst_preset_load_preset ((GstPreset *) eq2, "_testpreset_"); + GST_INFO_OBJECT (eq1, "Preset loaded"); + + /* compare properties */ + gst_child_proxy_get ((GstObject *) eq2, + "band0::type", &type, "band0::gain", &gain, "band0::freq", &freq, NULL); + ck_assert_int_eq (type, 0); + fail_unless (gain == -3.0, NULL); + fail_unless (freq == 100.0, NULL); + gst_child_proxy_get ((GstObject *) eq2, + "band1::type", &type, "band1::gain", &gain, "band1::freq", &freq, NULL); + ck_assert_int_eq (type, 1); + fail_unless (gain == +3.0, NULL); + fail_unless (freq == 1000.0, NULL); + gst_child_proxy_get ((GstObject *) eq2, + "band2::type", &type, "band2::gain", &gain, "band2::freq", &freq, NULL); + ck_assert_int_eq (type, 2); + fail_unless (gain == +9.0, NULL); + fail_unless (freq == 10000.0, NULL); + + gst_preset_delete_preset ((GstPreset *) eq1, "_testpreset_"); + gst_check_teardown_element (eq1); + gst_check_teardown_element (eq2); +} + +GST_END_TEST; + + static Suite * equalizer_suite (void) { @@ -305,6 +356,7 @@ equalizer_suite (void) tcase_add_test (tc_chain, test_equalizer_5bands_minus_24); tcase_add_test (tc_chain, test_equalizer_5bands_plus_12); tcase_add_test (tc_chain, test_equalizer_band_number_changing); + tcase_add_test (tc_chain, test_equalizer_presets); return s; } -- cgit v1.2.1