[vlc-devel] [PATCH v3 04/10] Add test for equalizer band string parsing utilities
Ronald Wright
logiconcepts819 at gmail.com
Sun Nov 29 23:09:36 CET 2015
Note: This patch cannot be applied without patch 2.
---
test/Makefile.am | 3 +
test/src/misc/eqz_util.c | 323 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 326 insertions(+)
create mode 100644 test/src/misc/eqz_util.c
diff --git a/test/Makefile.am b/test/Makefile.am
index 94428d1..01fe25b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -19,6 +19,7 @@ check_PROGRAMS = \
test_libvlc_media_list \
test_libvlc_media_player \
test_src_config_chain \
+ test_src_misc_eqz_util \
test_src_misc_interpolation \
test_src_misc_variables \
test_src_crypto_update \
@@ -76,6 +77,8 @@ test_libvlc_media_player_SOURCES = libvlc/media_player.c
test_libvlc_media_player_LDADD = $(LIBVLC)
test_libvlc_meta_SOURCES = libvlc/meta.c
test_libvlc_meta_LDADD = $(LIBVLC)
+test_src_misc_eqz_util_SOURCES = src/misc/eqz_util.c
+test_src_misc_eqz_util_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_misc_interpolation_SOURCES = src/misc/interpolation.c
test_src_misc_interpolation_LDADD = $(LIBVLCCORE)
test_src_misc_variables_SOURCES = src/misc/variables.c
diff --git a/test/src/misc/eqz_util.c b/test/src/misc/eqz_util.c
new file mode 100644
index 0000000..36a5293
--- /dev/null
+++ b/test/src/misc/eqz_util.c
@@ -0,0 +1,323 @@
+/*****************************************************************************
+ * eqz_util.c: test utility for VLC equalizer utility functions
+ *****************************************************************************
+ * Copyright (C) 2015 Ronald Wright
+ * $Id$
+ *
+ * Author: Ronald Wright <logiconcepts819 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include "../src/misc/eqz_util.c"
+#include "../modules/audio_filter/equalizer_presets.h"
+
+#include <stdio.h>
+#include "../../libvlc/test.h"
+#include "../lib/libvlc_internal.h"
+
+#define MAX_TEST_NAME_SIZE 32
+#define MAX_BANDS_STRING_SIZE 128
+#define NUM_TESTS 16
+
+/* Preset test set structure */
+typedef struct preset_test_t
+{
+ /* Test input */
+ char psz_test_name[MAX_TEST_NAME_SIZE]; /* Name of the test */
+ char psz_bands_string[MAX_BANDS_STRING_SIZE]; /* Bands string to use */
+
+ /* Expected interpolation output */
+ float f_amp_vlc_10[EQZ_VLC10_BANDS_MAX]; /* Output as 10 VLC bands */
+ float f_amp_iso_10[EQZ_ISO10_BANDS_MAX]; /* Output as 10 ISO bands */
+ float f_amp_iso_15[EQZ_ISO15_BANDS_MAX]; /* Output as 15 ISO bands */
+ float f_amp_iso_31[EQZ_ISO31_BANDS_MAX]; /* Output as 31 ISO bands */
+}
+preset_test_t;
+
+/* Suite of tests */
+static preset_test_t preset_test_suite[NUM_TESTS] =
+{
+ /* 1st set of tests */
+ {
+ "10-band VLC string 1",
+ "6.5 4 2 0 -2 0 0 2 4 5",
+ { 6.5, 4.0, 2.0, 0.0, -2.0, 0.0, 0.0, 2.0, 4.0, 5.0, },
+ { 6.5, 6.4, 4.9, 2.7, 0.6, -2.0, -1.0, 0.0, 0.3, 5.0, },
+ { 6.5, 6.5, 6.4, 5.6, 4.2, 2.7, 1.3, -0.2, -2.0, -1.6,
+ -0.3, 0.0, 0.0, 1.0, 5.0, },
+ { 6.5, 6.5, 6.5, 6.5, 6.5, 6.4, 6.1, 5.6, 4.9, 4.2,
+ 3.5, 2.7, 2.0, 1.3, 0.6, -0.2, -1.3, -2.0, -1.9, -1.6,
+ -1.0, -0.3, 0.0, 0.0, 0.0, 0.0, 0.3, 1.0, 2.6, 5.0, 5.0, },
+ },
+ /* 2nd set of tests */
+ {
+ "10-band VLC string 2",
+ "6.5 4 2 0 -2 0 0 2 4 5 v",
+ { 6.5, 4.0, 2.0, 0.0, -2.0, 0.0, 0.0, 2.0, 4.0, 5.0, },
+ { 6.5, 6.4, 4.9, 2.7, 0.6, -2.0, -1.0, 0.0, 0.3, 5.0, },
+ { 6.5, 6.5, 6.4, 5.6, 4.2, 2.7, 1.3, -0.2, -2.0, -1.6,
+ -0.3, 0.0, 0.0, 1.0, 5.0, },
+ { 6.5, 6.5, 6.5, 6.5, 6.5, 6.4, 6.1, 5.6, 4.9, 4.2,
+ 3.5, 2.7, 2.0, 1.3, 0.6, -0.2, -1.3, -2.0, -1.9, -1.6,
+ -1.0, -0.3, 0.0, 0.0, 0.0, 0.0, 0.3, 1.0, 2.6, 5.0, 5.0, },
+ },
+ /* 3rd set of tests */
+ {
+ "10-band VLC string 3",
+ "6.5 4 2 0 -2 0 0 2 4 5 x",
+ { 6.5, 4.0, 2.0, 0.0, -2.0, 0.0, 0.0, 2.0, 4.0, 5.0, },
+ { 6.5, 6.4, 4.9, 2.7, 0.6, -2.0, -1.0, 0.0, 0.3, 5.0, },
+ { 6.5, 6.5, 6.4, 5.6, 4.2, 2.7, 1.3, -0.2, -2.0, -1.6,
+ -0.3, 0.0, 0.0, 1.0, 5.0, },
+ { 6.5, 6.5, 6.5, 6.5, 6.5, 6.4, 6.1, 5.6, 4.9, 4.2,
+ 3.5, 2.7, 2.0, 1.3, 0.6, -0.2, -1.3, -2.0, -1.9, -1.6,
+ -1.0, -0.3, 0.0, 0.0, 0.0, 0.0, 0.3, 1.0, 2.6, 5.0, 5.0, },
+ },
+ /* 4th set of tests */
+ {
+ "10-band ISO string",
+ "6.5 6.4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.5, -2.0, -1.1, 0.0, 0.5, 5.0, },
+ { 6.5, 6.5, 6.4, 5.6, 4.2, 2.7, 1.3, -0.3, -2.0, -1.5,
+ -0.6, 0.0, 0.2, 1.0, 5.0, },
+ { 6.5, 6.5, 6.5, 6.5, 6.5, 6.4, 6.1, 5.6, 5.0, 4.2,
+ 3.5, 2.7, 2.0, 1.3, 0.5, -0.3, -1.3, -2.0, -1.9, -1.5,
+ -1.1, -0.6, -0.3, 0.0, 0.1, 0.2, 0.5, 1.0, 2.5, 5.0, 5.0, },
+ },
+ /* 7th set of tests */
+ {
+ "15-band ISO string 3",
+ "6.5 6.5 6.4 5.6 4.2 2.7 1.3 -0.3 -2.0 -1.5 -0.6 0 0.2 1 5 v",
+ { 6.4, 4.0, 2.0, -0.1, -2.0, -0.3, 0.2, 2.0, 3.5, 5.0, },
+ { 6.5, 6.4, 5.0, 2.7, 0.5, -2.0, -1.1, 0.0, 0.5, 5.0, },
+ { 6.5, 6.5, 6.4, 5.6, 4.2, 2.7, 1.3, -0.3, -2.0, -1.5,
+ -0.6, 0.0, 0.2, 1.0, 5.0, },
+ { 6.5, 6.5, 6.5, 6.5, 6.5, 6.4, 6.1, 5.6, 5.0, 4.2,
+ 3.5, 2.7, 2.0, 1.3, 0.5, -0.3, -1.3, -2.0, -1.9, -1.5,
+ -1.1, -0.6, -0.3, 0.0, 0.1, 0.2, 0.5, 1.0, 2.5, 5.0, 5.0, },
+ },
+ /* 8th set of tests */
+ {
+ "15-band ISO string 4",
+ "6.5 6.5 6.4 5.6 4.2 2.7 1.3 -0.3 -2.0 -1.5 -0.6 0 0.2 1 5 bla",
+ { 6.4, 4.0, 2.0, -0.1, -2.0, -0.3, 0.2, 2.0, 3.5, 5.0, },
+ { 6.5, 6.4, 5.0, 2.7, 0.5, -2.0, -1.1, 0.0, 0.5, 5.0, },
+ { 6.5, 6.5, 6.4, 5.6, 4.2, 2.7, 1.3, -0.3, -2.0, -1.5,
+ -0.6, 0.0, 0.2, 1.0, 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
+ {
+ "invalid string 3",
+ "4 zero 4",
+ { 4.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, },
+ { 4.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, },
+ { 4.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0, 0.0, },
+ { 4.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, },
+ },
+ /* 16th set of tests */
+ {
+ "ill-specified string",
+ "6.5 4 2 0 -2 0 0 2 4 5 4 3",
+ { 6.5, 4.0, 2.0, 0.0, -2.0, 0.0, 0.0, 2.0, 4.0, 5.0, },
+ { 6.5, 4.0, 2.0, 0.0, -2.0, 0.0, 0.0, 2.0, 4.0, 5.0, },
+ { 6.5, 4.0, 2.0, 0.0, -2.0, 0.0, 0.0, 2.0, 4.0, 5.0,
+ 4.0, 3.0, 0.0, 0.0, 0.0, },
+ { 6.5, 4.0, 2.0, 0.0, -2.0, 0.0, 0.0, 2.0, 4.0, 5.0,
+ 4.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, },
+ },
+};
+
+static bool values_close_enough( float f_value1, float f_value2 )
+{
+ /* Values rounded to the nearest tenth have a maximum error of 0.05 */
+ return fabsf( f_value1 - f_value2 ) <= 0.05f;
+}
+
+static void run_test( vlc_object_t *p_obj, int i_test, int i_type )
+{
+ log( "Testing %s mapped to %s\n", preset_test_suite[i_test].psz_test_name,
+ eqz_types_text[i_type] );
+
+ const char * psz_bands_string = preset_test_suite[i_test].psz_bands_string;
+ vlc_band_parse_t * p_ctx;
+ assert( vlc_eqz_util_band_parser_init( p_obj, &p_ctx, psz_bands_string,
+ i_type, NULL ) == VLC_SUCCESS );
+
+ const float * pf_expected_amp = NULL;
+ switch( i_type )
+ {
+ case EQZ_VLC10_TYPE:
+ pf_expected_amp = preset_test_suite[i_test].f_amp_vlc_10;
+ break;
+ case EQZ_ISO10_TYPE:
+ pf_expected_amp = preset_test_suite[i_test].f_amp_iso_10;
+ break;
+ case EQZ_ISO15_TYPE:
+ pf_expected_amp = preset_test_suite[i_test].f_amp_iso_15;
+ break;
+ case EQZ_ISO31_TYPE:
+ pf_expected_amp = preset_test_suite[i_test].f_amp_iso_31;
+ break;
+ }
+ assert( pf_expected_amp != NULL );
+
+ const float * pf_actual_amp = vlc_eqz_util_get_amp_array( p_ctx );
+
+ int i_bands = EqzGetNumBandsByType( i_type );
+ for( int i = 0; i < i_bands; i++ )
+ {
+ assert( values_close_enough( pf_expected_amp[i], pf_actual_amp[i] ) );
+ }
+
+ vlc_eqz_util_band_parser_destroy( p_ctx );
+}
+
+int main(void)
+{
+ libvlc_instance_t *p_vlc;
+
+ test_init();
+
+ p_vlc = libvlc_new( test_defaults_nargs, test_defaults_args );
+ assert( p_vlc != NULL );
+
+ vlc_object_t *p_obj = VLC_OBJECT( p_vlc->p_libvlc_int );
+
+ for( int i = 0; i < NUM_TESTS; i++ )
+ {
+ run_test( p_obj, i, EQZ_VLC10_TYPE );
+ run_test( p_obj, i, EQZ_ISO10_TYPE );
+ run_test( p_obj, i, EQZ_ISO15_TYPE );
+ run_test( p_obj, i, EQZ_ISO31_TYPE );
+ }
+
+ libvlc_release( p_vlc );
+
+ return 0;
+}
--
1.9.1
More information about the vlc-devel
mailing list