[vlc-devel] [PATCH 1/2] libvlc: equalizer: Provide option to choose between VLC and ISO bands
Ron Wright
logiconcepts819 at gmail.com
Mon Aug 12 06:36:21 CEST 2013
Commit c180afe5f932ec1e5b066595c9d6685153029f64 introduced a set of
functions
that allow accessing and changing various equalizer settings via LibVLC,
but it
was surprising that no functions were added that allow deciding between VLC
frequencies and ISO frequencies and determing whether VLC frequencies or ISO
frequencies are being used. This patch addresses this issue.
---
include/vlc/libvlc_media_player.h | 29 ++++++++++++++++++++++++++++-
lib/audio.c | 29 +++++++++++++++++++++++++++--
lib/libvlc.sym | 2 ++
lib/media_player.c | 6 ++++++
lib/media_player_internal.h | 1 +
src/audio_output/output.c | 1 +
test/libvlc/equalizer.c | 16 ++++++++++++++--
7 files changed, 79 insertions(+), 5 deletions(-)
diff --git a/include/vlc/libvlc_media_player.h
b/include/vlc/libvlc_media_player.h
index 27f7b97..56b5f8b 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1690,10 +1690,13 @@ LIBVLC_API unsigned
libvlc_audio_equalizer_get_band_count( void );
* in a user interface.
*
* \param u_index index of the band, counting from zero
+ * \param b_use_vlc_frequencies true if function is to return VLC center
+ * frequencies or false if function is to return ISO center
frequencies,
+ * use return value of \see
libvlc_audio_equalizer_is_using_vlc_frequencies
* \return equalizer band frequency (Hz), or -1 if there is no such band
* \version LibVLC 2.2.0 or later
*/
-LIBVLC_API float libvlc_audio_equalizer_get_band_frequency( unsigned
u_index );
+LIBVLC_API float libvlc_audio_equalizer_get_band_frequency( unsigned
u_index, int b_use_vlc_frequencies );
/**
* Create a new default equalizer, with all frequency values zeroed.
@@ -1819,6 +1822,30 @@ LIBVLC_API float
libvlc_audio_equalizer_get_amp_at_index( libvlc_equalizer_t *p_
*/
LIBVLC_API int libvlc_media_player_set_equalizer(
libvlc_media_player_t *p_mi, libvlc_equalizer_t *p_equalizer );
+/**
+ * Determines whether VLC center frequencies or ISO center frequencies
are used.
+ *
+ * The VLC bands consist of the following center frequencies: 60 Hz,
170 Hz,
+ * 310 Hz, 600 Hz, 1 kHz, 3 kHz, 6 kHz, 12 kHz, 14 kHz, and 16 kHz. The ISO
+ * bands consist of the following center frequencies: 31.25 Hz, 62.5 Hz,
+ * 125 Hz, 250 Hz, 500 Hz, 1 kHz, 2 kHz, 4 kHz, 8 kHz, and 16 kHz.
+ *
+ * \return true if VLC center frequencies are used or false if ISO center
+ * frequencies are used
+ * \version LibVLC 2.2.0 or later
+ */
+LIBVLC_API int libvlc_audio_equalizer_is_using_vlc_frequencies(
libvlc_equalizer_t *p_equalizer );
+
+/**
+ * Decides whether to use VLC center frequencies or ISO center frequencies.
+ *
+ * \param b_use_vlc_frequencies true if VLC center frequencies are to
be used
+ * or false if ISO center frequencies are to be used
+ * \return zero on success, -1 on error
+ * \version LibVLC 2.2.0 or later
+ */
+LIBVLC_API int libvlc_audio_equalizer_set_using_vlc_frequencies(
libvlc_equalizer_t *p_equalizer, int b_use_vlc_frequencies );
+
/** @} audio */
/** @} media_player */
diff --git a/lib/audio.c b/lib/audio.c
index fd022ca..05723bc 100644
--- a/lib/audio.c
+++ b/lib/audio.c
@@ -460,12 +460,16 @@ unsigned libvlc_audio_equalizer_get_band_count( void )
/*****************************************************************************
* libvlc_audio_equalizer_get_band_frequency : Get the frequency for a
band
*****************************************************************************/
-float libvlc_audio_equalizer_get_band_frequency( unsigned u_index )
+float libvlc_audio_equalizer_get_band_frequency( unsigned u_index, int
b_use_vlc_frequencies )
{
if ( u_index >= EQZ_BANDS_MAX )
return -1.f;
- return f_vlc_frequency_table_10b[ u_index ];
+ const float *f_freq_table_10b = b_use_vlc_frequencies
+ ? f_vlc_frequency_table_10b
+ : f_iso_frequency_table_10b;
+
+ return f_freq_table_10b[ u_index ];
}
/*****************************************************************************
@@ -482,6 +486,8 @@ libvlc_equalizer_t *libvlc_audio_equalizer_new( void )
for ( unsigned i = 0; i < EQZ_BANDS_MAX; i++ )
p_equalizer->f_amp[ i ] = 0.f;
+ p_equalizer->b_use_vlc_frequencies = true;
+
return p_equalizer;
}
@@ -504,6 +510,8 @@ libvlc_equalizer_t
*libvlc_audio_equalizer_new_from_preset( unsigned u_index )
for ( unsigned i = 0; i < EQZ_BANDS_MAX; i++ )
p_equalizer->f_amp[ i ] = eqz_preset_10b[ u_index ].f_amp[ i ];
+ p_equalizer->b_use_vlc_frequencies = true;
+
return p_equalizer;
}
@@ -564,3 +572,20 @@ float libvlc_audio_equalizer_get_amp_at_index(
libvlc_equalizer_t *p_equalizer,
return p_equalizer->f_amp[ u_band ];
}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_is_using_vlc_frequencies : Determine whether
VLC center frequencies or ISO center frequencies are used
+
*****************************************************************************/
+int libvlc_audio_equalizer_is_using_vlc_frequencies( libvlc_equalizer_t
*p_equalizer )
+{
+ return (int) p_equalizer->b_use_vlc_frequencies;
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_set_using_vlc_frequencies : Decide whether to
use VLC center frequencies or ISO center frequencies
+
*****************************************************************************/
+int libvlc_audio_equalizer_set_using_vlc_frequencies(
libvlc_equalizer_t *p_equalizer, int b_use_vlc_frequencies )
+{
+ p_equalizer->b_use_vlc_frequencies = (bool) b_use_vlc_frequencies;
+ return 0;
+}
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 7c99668..da55518 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -14,6 +14,8 @@ libvlc_audio_equalizer_new_from_preset
libvlc_audio_equalizer_release
libvlc_audio_equalizer_set_amp_at_index
libvlc_audio_equalizer_set_preamp
+libvlc_audio_equalizer_is_using_vlc_frequencies
+libvlc_audio_equalizer_set_using_vlc_frequencies
libvlc_audio_output_device_count
libvlc_audio_output_device_id
libvlc_audio_output_device_list_get
diff --git a/lib/media_player.c b/lib/media_player.c
index b4a7250..315c97c 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -466,6 +466,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
/* Equalizer */
var_Create (mp, "equalizer-preamp", VLC_VAR_FLOAT);
var_Create (mp, "equalizer-bands", VLC_VAR_STRING);
+ var_Create (mp, "equalizer-vlcfreqs", VLC_VAR_BOOL);
mp->p_md = NULL;
mp->state = libvlc_NothingSpecial;
@@ -1424,11 +1425,13 @@ void
libvlc_media_player_set_video_title_display( libvlc_media_player_t *p_mi, l
int libvlc_media_player_set_equalizer( libvlc_media_player_t *p_mi,
libvlc_equalizer_t *p_equalizer )
{
float f_preamp;
+ bool b_use_vlc_frequencies;
char *psz_bands;
if ( p_equalizer )
{
f_preamp = p_equalizer->f_preamp;
+ b_use_vlc_frequencies = p_equalizer->b_use_vlc_frequencies;
psz_bands = malloc( EQZ_BANDS_MAX * EQZ_BAND_VALUE_SIZE + 1 );
if ( unlikely( psz_bands == NULL ) )
@@ -1451,16 +1454,19 @@ int libvlc_media_player_set_equalizer(
libvlc_media_player_t *p_mi, libvlc_equal
else
{
f_preamp = 0.f;
+ b_use_vlc_frequencies = true;
psz_bands = NULL;
}
var_SetFloat( p_mi, "equalizer-preamp", f_preamp );
+ var_SetBool( p_mi, "equalizer-vlcfreqs", b_use_vlc_frequencies );
var_SetString( p_mi, "equalizer-bands", psz_bands );
audio_output_t *p_aout = input_resource_HoldAout(
p_mi->input.p_resource );
if ( p_aout )
{
var_SetFloat( p_aout, "equalizer-preamp", f_preamp );
+ var_SetBool( p_aout, "equalizer-vlcfreqs", b_use_vlc_frequencies );
var_SetString( p_aout, "equalizer-bands", psz_bands );
vlc_object_release( p_aout );
diff --git a/lib/media_player_internal.h b/lib/media_player_internal.h
index 27fbf1f..36db49a 100644
--- a/lib/media_player_internal.h
+++ b/lib/media_player_internal.h
@@ -71,6 +71,7 @@ struct libvlc_equalizer_t
{
float f_preamp;
float f_amp[EQZ_BANDS_MAX];
+ bool b_use_vlc_frequencies;
};
#endif
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 185eee6..69c06de 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -300,6 +300,7 @@ audio_output_t *aout_New (vlc_object_t *parent)
}
var_Create (aout, "equalizer-preamp", VLC_VAR_FLOAT |
VLC_VAR_DOINHERIT);
+ var_Create (aout, "equalizer-vlcfreqs", VLC_VAR_BOOL |
VLC_VAR_DOINHERIT);
var_Create (aout, "equalizer-bands", VLC_VAR_STRING |
VLC_VAR_DOINHERIT);
return aout;
diff --git a/test/libvlc/equalizer.c b/test/libvlc/equalizer.c
index e7c5ad5..d184f46 100644
--- a/test/libvlc/equalizer.c
+++ b/test/libvlc/equalizer.c
@@ -51,11 +51,15 @@ static void test_equalizer (const char ** argv, int
argc)
assert (u_bands > 0);
for (unsigned i = 0; i < u_bands; i++)
- assert (-1.0f != libvlc_audio_equalizer_get_band_frequency(i));
+ {
+ assert (-1.0f != libvlc_audio_equalizer_get_band_frequency(i, 1));
+ assert (-1.0f != libvlc_audio_equalizer_get_band_frequency(i, 0));
+ }
// band out of range
- assert (-1.0f == libvlc_audio_equalizer_get_band_frequency(u_bands));
+ assert (-1.0f == libvlc_audio_equalizer_get_band_frequency(u_bands,
1));
+ assert (-1.0f == libvlc_audio_equalizer_get_band_frequency(u_bands,
0));
// initialisation
@@ -121,6 +125,14 @@ static void test_equalizer (const char ** argv, int
argc)
assert (0.0f == libvlc_audio_equalizer_get_amp_at_index
(equalizer, u_bands));
assert (-1 == libvlc_audio_equalizer_set_amp_at_index (equalizer,
19.9f, u_bands));
+ // use of VLC and ISO frequency settings
+
+ log ("Testing equalizer use of VLC and ISO frequency settings\n");
+
+ assert (0 != libvlc_audio_equalizer_is_using_vlc_frequencies
(equalizer));
+ assert (0 == libvlc_audio_equalizer_set_using_vlc_frequencies
(equalizer, 0));
+ assert (0 == libvlc_audio_equalizer_is_using_vlc_frequencies
(equalizer));
+
// no equalizer
log ("Testing release NULL\n");
--
1.7.10.4
More information about the vlc-devel
mailing list