[vlc-devel] [PATCH 2/8] Add utilities for parsing equalizer band strings
Ronald Wright
logiconcepts819 at gmail.com
Tue Dec 1 14:57:20 CET 2015
---
include/vlc_eqz_util.h | 91 +++++++++++++
po/POTFILES.in | 2 +
src/Makefile.am | 2 +
src/libvlccore.sym | 3 +
src/misc/eqz_util.c | 294 ++++++++++++++++++++++++++++++++++++++++++
test/Makefile.am | 3 +
test/src/misc/eqz_util.c | 323 +++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 718 insertions(+)
create mode 100644 include/vlc_eqz_util.h
create mode 100644 src/misc/eqz_util.c
create mode 100644 test/src/misc/eqz_util.c
diff --git a/include/vlc_eqz_util.h b/include/vlc_eqz_util.h
new file mode 100644
index 0000000..f453eb1
--- /dev/null
+++ b/include/vlc_eqz_util.h
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * vlc_eqz_util.h: 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.
+ *****************************************************************************/
+
+#ifndef VLC_EQZ_UTIL_H
+#define VLC_EQZ_UTIL_H
+
+/**
+ * \file
+ * \brief This file is the interface definition of several useful equalizer
+ * utility functions (implementation in src/misc/eqz_util.c)
+ */
+
+/*****************************************************************************
+ * Documentation
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Type definitions
+ *****************************************************************************/
+
+/**
+ * The preset interpolation data type. This is a pointer to a private structure
+ * defined in misc/eqz_util.c.
+ */
+typedef struct vlc_band_parser_t vlc_band_parser_t;
+
+/*****************************************************************************
+ * Interpolation routines
+ *****************************************************************************/
+
+/**
+ * Start a new band parser.
+ *
+ * \param p_obj The object that holds VLC object data
+ * \param pp_parser_ctx The object that shall hold band parse data
+ * \param psz_bands The bands string (e.g. "2 0 -2 -4 -2 0 2 4 2 0")
+ * \param i_type The current equalizer type
+ * \param pf_amp An optional memory location to store interpolated values
+ * \retval VLC_SUCCESS Success
+ * \retval VLC_ENOMEM Memory failure
+ *
+ * \note If pf_amp is NULL, then memory is automatically allocated in the
+ * preset parser data context according to the given equalizer type. If
+ * the provided bands string provides a valid number of bands (i.e. 10,
+ * 15, or 31), then the preset values are interpolated according to the
+ * current equalizer type. Otherwise, each value is mapped to the
+ * corresponding band of the current equalizer type, starting at the
+ * lowest band, until there are no more spaces or values left.
+ */
+VLC_API int vlc_band_parser_init( vlc_object_t * p_obj,
+ vlc_band_parser_t ** pp_parser_ctx,
+ const char * psz_bands, int i_type,
+ float * pf_amp );
+
+/**
+ * Find the amplification factors from the given band parse context.
+ *
+ * \param p_parser_ctx The object that holds band parse data
+ * \return A pointer to the amplification array in the context
+ */
+VLC_API const float *
+vlc_get_amp_array( const vlc_band_parser_t * p_parser_ctx );
+
+/**
+ * Destroy the band parse context.
+ *
+ * \param p_parser_ctx The object that holds band parse data
+ */
+VLC_API void vlc_band_parser_destroy( vlc_band_parser_t * p_parser_ctx );
+
+#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index db9e4ca..3a2dec2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -16,6 +16,7 @@ include/vlc_configuration.h
include/vlc_demux.h
include/vlc/deprecated.h
include/vlc_epg.h
+include/vlc_eqz_util.h
include/vlc_es.h
include/vlc_es_out.h
include/vlc_events.h
@@ -106,6 +107,7 @@ src/libvlc.h
src/libvlc-module.c
src/misc/block.c
src/misc/cpu.c
+src/misc/eqz_util.c
src/misc/error.c
src/misc/es_format.c
src/misc/events.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 0d534ba..98bd770 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,6 +42,7 @@ pluginsinclude_HEADERS = \
../include/vlc_dialog.h \
../include/vlc_demux.h \
../include/vlc_epg.h \
+ ../include/vlc_eqz_util.h \
../include/vlc_es.h \
../include/vlc_es_out.h \
../include/vlc_events.h \
@@ -435,6 +436,7 @@ SOURCES_libvlc_common = \
misc/fifo.c \
misc/fourcc.c \
misc/fourcc_list.h \
+ misc/eqz_util.c \
misc/es_format.c \
misc/interpolation.c \
misc/picture.c \
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index f03e451..f7a9300 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -523,6 +523,9 @@ vlc_interpolant_create
vlc_interpolant_destroy
vlc_GetCPUCount
vlc_CPU
+vlc_band_parser_destroy
+vlc_band_parser_init
+vlc_get_amp_array
vlc_error
vlc_event_attach
vlc_event_detach
diff --git a/src/misc/eqz_util.c b/src/misc/eqz_util.c
new file mode 100644
index 0000000..ab4c94b
--- /dev/null
+++ b/src/misc/eqz_util.c
@@ -0,0 +1,294 @@
+/*****************************************************************************
+ * vlc_eqz_util.h: 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <math.h>
+#include <vlc_common.h>
+#include <vlc_charset.h>
+#include <vlc_interpolation.h>
+#include <vlc_eqz_util.h>
+
+#include "../../modules/audio_filter/equalizer_presets.h"
+
+/*****************************************************************************
+ * Documentation : Read vlc_interpolation.h
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Private types.
+ *****************************************************************************/
+
+struct vlc_band_parser_t
+{
+ int i_orig_bands;
+ vlc_interpolant_t * p_itp;
+ float * pf_amp;
+ int i_type;
+ float f_orig_amp[];
+};
+
+/*****************************************************************************
+ * Implementation of routines.
+ *****************************************************************************/
+
+/* Determine the most valid equalizer identifier from the number of bands and
+ * a string with a possibly invalid identifier */
+static char GetValidIdentifier( vlc_object_t *p_obj, int i_cur_type,
+ const char * psz_identifier, int i_bands )
+{
+ char eqz_identifier;
+ switch( i_bands )
+ {
+ case EQZ_ISO10_BANDS_MAX:
+ /* fall-through */
+ case EQZ_ISO15_BANDS_MAX:
+ /* fall-through */
+ case EQZ_ISO31_BANDS_MAX:
+ {
+ size_t i_id_len = psz_identifier ? strlen( psz_identifier ) : 0;
+ if( i_id_len != 1 ||
+ ( psz_identifier[0] != EQZ_VLC_IDENTIFIER &&
+ psz_identifier[0] != EQZ_ISO_IDENTIFIER ) )
+ {
+ eqz_identifier = EqzGetDefaultIdentifier( i_bands );
+ if( i_id_len == 0 )
+ {
+ /* No identifier specified in string */
+ if( i_bands == EQZ_ISO10_BANDS_MAX )
+ {
+ msg_Warn( p_obj, "equalizer identifier not specified "
+ "for 10 bands; assuming VLC bands" );
+ }
+ }
+ else
+ {
+ /* Found invalid identifier */
+ msg_Warn( p_obj, "invalid equalizer identifier '%s'; "
+ "assuming default equalizer type for %d bands ('%c')",
+ psz_identifier, i_bands, eqz_identifier );
+ }
+ }
+ else if( i_bands != EQZ_ISO10_BANDS_MAX &&
+ psz_identifier[0] == EQZ_VLC_IDENTIFIER )
+ {
+ /* Found VLC equalizer type for 15 and 31 bands, but we only
+ * provide ISO bands in these cases */
+ eqz_identifier = EQZ_ISO_IDENTIFIER;
+ msg_Warn( p_obj, "equalizer identifier '%s' not defined for "
+ "%d bands; assuming ISO bands", psz_identifier, i_bands );
+ }
+ else
+ {
+ /* Found VLC or ISO identifier for 10 bands and ISO identifier
+ * for 15 and 31 bands */
+ eqz_identifier = psz_identifier[0];
+ }
+ break;
+ }
+ default:
+ {
+ /* Default is to assume current mode */
+ int i_cur_bands = EqzGetNumBandsByType( i_cur_type );
+ int i_smallest_bands = __MIN( i_cur_bands, i_bands );
+ eqz_identifier = EqzGetIdentifier( i_cur_type );
+ if( i_smallest_bands == 1 )
+ {
+ msg_Warn( p_obj, "found only one band (which is not 10, 15, "
+ "or 31, as it ought to be); assuming it corresponds to "
+ "the first band of the currently active equalizer type "
+ "(%d-band %s equalizer)", i_cur_bands,
+ EqzGetStringIdentifier( eqz_identifier ) );
+ }
+ else
+ {
+ msg_Warn( p_obj, "found unexpected number of bands (%d, which "
+ "is not 10, 15, or 31, as it ought to be); assuming the "
+ "%s%d bands correspond to the %s%d bands of the currently "
+ "active equalizer type (%d-band %s equalizer)", i_bands,
+ i_cur_bands < i_bands ? "first " : "", i_smallest_bands,
+ i_cur_bands > i_bands ? "first " : "", i_smallest_bands,
+ i_cur_bands, EqzGetStringIdentifier( eqz_identifier ) );
+ }
+ break;
+ }
+ }
+ return eqz_identifier;
+}
+
+/* Try setting up an interpolant */
+static int SetUpInterpolant( int i_bands, int i_type, float * pf_amp,
+ vlc_interpolant_t ** itp )
+{
+ int i_ret_val = VLC_ENOMEM;
+ float * pf_freq = malloc( i_bands * sizeof( *pf_freq ) );
+ if( likely( pf_freq != NULL ) )
+ {
+ for( int k = 0; k < i_bands; k++ )
+ pf_freq[k] = EqzGetTrueFrequency( i_type, k );
+ i_ret_val = vlc_interpolant_create( itp, pf_freq, pf_amp, i_bands );
+ free( pf_freq );
+ }
+ return i_ret_val;
+}
+
+int vlc_band_parser_init( vlc_object_t * p_obj,
+ vlc_band_parser_t ** pp_parser_ctx,
+ const char * psz_bands, int i_type, float * pf_amp )
+{
+ vlc_band_parser_t * p_parser_ctx;
+ vlc_interpolant_t * p_itp = NULL;
+ float * pf_orig_amp;
+ int i = 0, i_toks = 0;
+
+ /* Duplicate memory of bands string value */
+ char *p = strdup( psz_bands ), *q = NULL, *saved;
+ if( unlikely( !p ) )
+ return VLC_ENOMEM;
+
+ /* Allocate memory for storing the context data */
+ int i_ret_val = VLC_ENOMEM;
+ int i_size = EQZ_BANDS_MAX;
+ if( !pf_amp )
+ i_size += EqzGetNumBandsByType( i_type );
+ p_parser_ctx = malloc( sizeof( *p_parser_ctx ) + i_size * sizeof( *pf_amp ) );
+ if( likely( p_parser_ctx != NULL ) )
+ {
+ pf_orig_amp = p_parser_ctx->f_orig_amp;
+ if( !pf_amp )
+ pf_amp = pf_orig_amp + EQZ_BANDS_MAX;
+
+ for( char *tok = strtok_r( p, " ", &saved ); tok != NULL;
+ tok = strtok_r( NULL, " ", &saved ) )
+ {
+ if( i < EQZ_BANDS_MAX )
+ {
+ char *r = tok;
+ float f = us_strtof( tok, &r );
+ if( r == tok || *r != '\0' || isnan( f ) )
+ pf_orig_amp[i++] = 0.f;
+ else
+ pf_orig_amp[i++] = f;
+ }
+
+ /* Even if we exceed EQZ_BANDS_MAX or encounter malformed tokens,
+ * keep counting the number of tokens */
+ i_toks++;
+ q = tok;
+ }
+
+ /* Check whether we have a potential identifier at the end of the
+ * string. One way to check is if the last token is numeric. If not,
+ * then we consider it as a potential identifier. */
+ if( q ) /* q is non-NULL if we have at least one token */
+ {
+ char *r = q;
+ float f = us_strtof( q, &r );
+ if( r == q || *r != '\0' || isnan( f ) )
+ {
+ /* In this case, the last token could not be converted into a
+ * float, so we treat it as a potential identifier by excluding
+ * it from all counts */
+ if( i < EQZ_BANDS_MAX )
+ i--; /* potential identifier found within bounds */
+ i_toks--;
+ }
+ else
+ q = NULL; /* don't treat any tokens as potential identifiers */
+ }
+
+ i_ret_val = VLC_SUCCESS;
+ if( i > 0 )
+ {
+ /* Should there be a mismatch in the number or type of bands,
+ * interpolate */
+ char id = GetValidIdentifier( p_obj, i_type, q, i_toks );
+ if( i != EqzGetNumBandsByType( i_type ) ||
+ id != EqzGetIdentifier( i_type ) )
+ {
+ int i_bands_type = EqzGetTypeByNumBands( i_toks, id );
+ if( i_bands_type != EQZ_UNKNOWN_TYPE )
+ /* Try creating the interpolant */
+ i_ret_val = SetUpInterpolant( i, i_bands_type, pf_orig_amp,
+ &p_itp );
+ }
+ }
+ }
+
+ /* Check status of i_ret_val. If it is not equal to VLC_SUCCESS, then
+ * clean up. Otherwise, set up structure */
+ if( i_ret_val == VLC_SUCCESS )
+ {
+ p_parser_ctx->p_itp = p_itp;
+ p_parser_ctx->i_orig_bands = i;
+ p_parser_ctx->pf_amp = pf_amp;
+ p_parser_ctx->i_type = i_type;
+ *pp_parser_ctx = p_parser_ctx;
+ }
+ else
+ {
+ free( p_parser_ctx );
+ }
+
+ free( p );
+ return i_ret_val;
+}
+
+const float * vlc_get_amp_array( const vlc_band_parser_t * p_parser_ctx )
+{
+ int i_band = EqzGetNumBandsByType( p_parser_ctx->i_type );
+ if( p_parser_ctx->p_itp )
+ {
+ /* Construct the interpolated set of bands */
+ for( int k = 0; k < i_band; k++ )
+ {
+ float f_freq = EqzGetTrueFrequency( p_parser_ctx->i_type, k );
+ p_parser_ctx->pf_amp[k] = vlc_interpolate( p_parser_ctx->p_itp, f_freq );
+ }
+ }
+ else
+ {
+ /* Read bands as they are */
+ int k;
+ for( k = 0; k < p_parser_ctx->i_orig_bands; k++ )
+ p_parser_ctx->pf_amp[k] = p_parser_ctx->f_orig_amp[k];
+ while( k < i_band )
+ p_parser_ctx->pf_amp[k++] = 0.f;
+ }
+ return p_parser_ctx->pf_amp;
+}
+
+void vlc_band_parser_destroy( vlc_band_parser_t * p_parser_ctx )
+{
+ if( likely( p_parser_ctx ) )
+ {
+ free( p_parser_ctx->p_itp );
+ free( p_parser_ctx );
+ }
+}
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..c00714c
--- /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 4.9 2.7 0.6 -2 -1 0 0.3 5 i",
+ { 6.4, 4.0, 2.1, -0.1, -2.0, -0.4, 0.2, 2.2, 3.7, 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.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.2, 5.6, 4.9, 4.2,
+ 3.5, 2.7, 2.0, 1.3, 0.6, -0.3, -1.4, -2.0, -1.9, -1.5,
+ -1.0, -0.6, -0.3, 0.0, 0.1, 0.2, 0.3, 1.0, 2.7, 5.0, 5.0, },
+ },
+ /* 5th set of tests */
+ {
+ "15-band ISO string 1",
+ "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",
+ { 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, },
+ },
+ /* 6th set of tests */
+ {
+ "15-band ISO string 2",
+ "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 i",
+ { 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,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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_parser_t * p_ctx;
+ assert( vlc_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_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_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