From 1f255a585b8a059c293c005fee308a2b308ebe4d Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Fri, 17 Aug 2012 14:59:57 +0200 Subject: [PATCH] equalizer: enable presets for the n-band equalizer Add a test for saving and restoring the preset. --- gst/equalizer/gstiirequalizer.c | 4 +- gst/equalizer/gstiirequalizer10bands.c | 4 +- gst/equalizer/gstiirequalizer3bands.c | 4 +- tests/check/elements/equalizer.c | 52 ++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/gst/equalizer/gstiirequalizer.c b/gst/equalizer/gstiirequalizer.c index 13bf9ece40..acc827795b 100644 --- a/gst/equalizer/gstiirequalizer.c +++ b/gst/equalizer/gstiirequalizer.c @@ -62,7 +62,8 @@ static GstFlowReturn gst_iir_equalizer_transform_ip (GstBaseTransform * btrans, G_DEFINE_TYPE_WITH_CODE (GstIirEqualizer, gst_iir_equalizer, GST_TYPE_AUDIO_FILTER, G_IMPLEMENT_INTERFACE (GST_TYPE_CHILD_PROXY, - gst_iir_equalizer_child_proxy_interface_init)); + gst_iir_equalizer_child_proxy_interface_init) + G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL)); /* child object */ @@ -348,7 +349,6 @@ gst_iir_equalizer_child_proxy_interface_init (gpointer g_iface, iface->get_children_count = gst_iir_equalizer_child_proxy_get_children_count; } - /* equalizer implementation */ static void diff --git a/gst/equalizer/gstiirequalizer10bands.c b/gst/equalizer/gstiirequalizer10bands.c index 5907d33dfa..00ae9109ca 100644 --- a/gst/equalizer/gstiirequalizer10bands.c +++ b/gst/equalizer/gstiirequalizer10bands.c @@ -63,8 +63,8 @@ GST_DEBUG_CATEGORY_EXTERN (equalizer_debug); #define gst_iir_equalizer_10bands_parent_class parent_class -G_DEFINE_TYPE_WITH_CODE (GstIirEqualizer10Bands, gst_iir_equalizer_10bands, - GST_TYPE_IIR_EQUALIZER, G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL)); +G_DEFINE_TYPE (GstIirEqualizer10Bands, gst_iir_equalizer_10bands, + GST_TYPE_IIR_EQUALIZER); /* equalizer implementation */ diff --git a/gst/equalizer/gstiirequalizer3bands.c b/gst/equalizer/gstiirequalizer3bands.c index c44bb19fe0..b336d5e83f 100644 --- a/gst/equalizer/gstiirequalizer3bands.c +++ b/gst/equalizer/gstiirequalizer3bands.c @@ -54,8 +54,8 @@ GST_DEBUG_CATEGORY_EXTERN (equalizer_debug); #define GST_CAT_DEFAULT equalizer_debug #define gst_iir_equalizer_3bands_parent_class parent_class -G_DEFINE_TYPE_WITH_CODE (GstIirEqualizer3Bands, gst_iir_equalizer_3bands, - GST_TYPE_IIR_EQUALIZER, G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL)); +G_DEFINE_TYPE (GstIirEqualizer3Bands, gst_iir_equalizer_3bands, + GST_TYPE_IIR_EQUALIZER); /* equalizer implementation */ diff --git a/tests/check/elements/equalizer.c b/tests/check/elements/equalizer.c index 5510cb780a..a43268e7d2 100644 --- a/tests/check/elements/equalizer.c +++ b/tests/check/elements/equalizer.c @@ -310,6 +310,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 ((GstChildProxy *) 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 ((GstChildProxy *) 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 ((GstChildProxy *) 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 ((GstChildProxy *) 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) { @@ -321,6 +372,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; }