equalizer: enable presets for the n-band equalizer
authorStefan Sauer <ensonic@users.sf.net>
Fri, 17 Aug 2012 12:59:57 +0000 (14:59 +0200)
committerStefan Sauer <ensonic@users.sf.net>
Fri, 17 Aug 2012 13:01:40 +0000 (15:01 +0200)
Add a test for saving and restoring the preset.

gst/equalizer/gstiirequalizer.c
gst/equalizer/gstiirequalizer10bands.c
gst/equalizer/gstiirequalizer3bands.c
tests/check/elements/equalizer.c

index 13bf9ec..acc8277 100644 (file)
@@ -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
index 5907d33..00ae910 100644 (file)
@@ -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 */
 
index c44bb19..b336d5e 100644 (file)
@@ -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 */
 
index 5510cb7..a43268e 100644 (file)
@@ -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;
 }