[vlc-devel] [PATCH v3 03/10] Add test for monotone cubic interpolation support
Ronald Wright
logiconcepts819 at gmail.com
Sun Nov 29 23:09:35 CET 2015
Note: This patch cannot be applied without patch 1.
---
test/Makefile.am | 3 +
test/src/misc/interpolation.c | 129 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 132 insertions(+)
create mode 100644 test/src/misc/interpolation.c
diff --git a/test/Makefile.am b/test/Makefile.am
index b732acf..94428d1 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_interpolation \
test_src_misc_variables \
test_src_crypto_update \
test_src_input_stream \
@@ -75,6 +76,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_interpolation_SOURCES = src/misc/interpolation.c
+test_src_misc_interpolation_LDADD = $(LIBVLCCORE)
test_src_misc_variables_SOURCES = src/misc/variables.c
test_src_misc_variables_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_config_chain_SOURCES = src/config/chain.c
diff --git a/test/src/misc/interpolation.c b/test/src/misc/interpolation.c
new file mode 100644
index 0000000..54a2395
--- /dev/null
+++ b/test/src/misc/interpolation.c
@@ -0,0 +1,129 @@
+/*****************************************************************************
+ * interpolation.c: test VLC interpolation utility
+ *****************************************************************************
+ * 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/interpolation.c"
+#include "../modules/audio_filter/equalizer_presets.h"
+
+#include <stdio.h>
+#include "../../libvlc/test.h"
+
+static void test_bad_interpolant_param( void )
+{
+ /* This case tests whether vlc_interpolant_create correctly detects an
+ * invalid parameter. vlc_interpolant_create returns VLC_EBADVAR if less
+ * than 2 sample points are given. Here, we give it 1 sample point to see
+ * if vlc_interpolant_create returns VLC_EBADVAR as it should. */
+
+ vlc_interpolant_t * p_itp;
+
+ float f_points_1[1] = { 0.0, };
+ float f_values_1[1] = { 0.0, };
+
+ assert( vlc_interpolant_create( &p_itp, f_points_1, f_values_1, 1 ) == VLC_EBADVAR );
+}
+
+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 test_interpolation( const float * pf_points1,
+ const float * pf_values1, int i_count1,
+ const float * pf_points2,
+ const float * pf_values2, int i_count2 )
+{
+ vlc_interpolant_t * itp;
+
+ assert( vlc_interpolant_create( &itp, pf_points1, pf_values1, i_count1 ) == VLC_SUCCESS );
+
+ for( int i = 0; i < i_count2; i++ )
+ {
+ float f_interp_value = vlc_interpolate( itp, pf_points2[i] );
+ assert( values_close_enough( f_interp_value, pf_values2[i] ) );
+ }
+
+ vlc_interpolant_destroy( itp );
+}
+
+static void load_with_true_frequencies( float * pf_table, int i_type )
+{
+ /* Remember: display frequencies are slightly different from the true
+ * frequencies used in the filtering process, and the
+ * interpolation points for interpolated preset values are the
+ * true frequencies, not the display frequencies */
+ int i_band_count = EqzGetNumBandsByType( i_type );
+ for( int i = 0; i < i_band_count; i++ )
+ {
+ pf_table[i] = EqzGetTrueFrequency( i_type, i );
+ }
+}
+
+static void test_some_interpolants( void )
+{
+ /* Test interpolations of equalizer presets */
+ float true_vlc_freq_table_10b[EQZ_VLC10_BANDS_MAX];
+ float true_iso_freq_table_10b[EQZ_ISO10_BANDS_MAX];
+ float true_iso_freq_table_15b[EQZ_ISO15_BANDS_MAX];
+ float true_iso_freq_table_31b[EQZ_ISO31_BANDS_MAX];
+
+ load_with_true_frequencies( true_vlc_freq_table_10b, EQZ_VLC10_TYPE );
+ load_with_true_frequencies( true_iso_freq_table_10b, EQZ_ISO10_TYPE );
+ load_with_true_frequencies( true_iso_freq_table_15b, EQZ_ISO15_TYPE );
+ load_with_true_frequencies( true_iso_freq_table_31b, EQZ_ISO31_TYPE );
+
+ for( int i = 0; i < NB_PRESETS; i++ )
+ {
+ test_interpolation( true_vlc_freq_table_10b,
+ eqz_preset_vlc_10b[i].f_amp, EQZ_VLC10_BANDS_MAX,
+ true_iso_freq_table_10b,
+ eqz_preset_iso_10b[i].f_amp, EQZ_ISO10_BANDS_MAX );
+
+ test_interpolation( true_vlc_freq_table_10b,
+ eqz_preset_vlc_10b[i].f_amp, EQZ_VLC10_BANDS_MAX,
+ true_iso_freq_table_15b,
+ eqz_preset_iso_15b[i].f_amp, EQZ_ISO15_BANDS_MAX );
+
+ test_interpolation( true_vlc_freq_table_10b,
+ eqz_preset_vlc_10b[i].f_amp, EQZ_VLC10_BANDS_MAX,
+ true_iso_freq_table_31b,
+ eqz_preset_iso_31b[i].f_amp, EQZ_ISO31_BANDS_MAX );
+
+ }
+}
+
+int main( void )
+{
+ log( "Testing bad interpolant parameters\n" );
+ test_bad_interpolant_param();
+
+ log( "Testing interpolation of equalizer preset values\n" );
+ test_some_interpolants();
+
+ return 0;
+}
--
1.9.1
More information about the vlc-devel
mailing list