[vlc-devel] [PATCH] Add new API to libvlc for persistent equalizer settings.
Mark Lee
mark.lee at capricasoftware.co.uk
Mon Aug 20 18:07:42 CEST 2012
Hello,
Does anyone have any more comments on this patch?
If it's not acceptable in it's present form I am happy to make any needed
changes.
The last comment from a week ago was with regard to reference counting the
equalizer instances - I can just as easily include this or not if you let
me know.
Thanks.
On 12 August 2012 19:11, Mark Lee <mark.lee at capricasoftware.co.uk> wrote:
> Hello,
>
> My latest patch does include reference counting for the equalizer
> instances. It wasn't a big deal to add it, but if reference counting really
> is not wanted I can just as easily remove it and submit a new patch. I am
> happy to make whatever changes are needed.
>
> I will wait and see if there are any further comments before doing
> anything else on this.
>
> Thanks.
>
>
> On 12 August 2012 16:40, Mark Lee <mark.lee at capricasoftware.co.uk> wrote:
>
>> New methods are provided to:
>>
>> - get the available equalizer presets;
>> - get the available frequency bands (useful for creating a UI);
>> - create a new default equalizer, or create a new equalizer from a
>> preset;
>> - release a previously created equalizer;
>> - get/set preamp and individual frequency amplification values;
>> - get/set an equalizer on a media player.
>>
>> Equalizer settings are persistent, can be made whether media is currently
>> playing or not and will automatically be applied to subsequently played
>> media.
>> ---
>> include/vlc/libvlc_media_player.h | 206
>> ++++++++++++++++++++++++++++++
>> lib/audio.c | 171 +++++++++++++++++++++++++
>> lib/libvlc.sym | 14 ++
>> lib/media_player.c | 66 ++++++++++
>> lib/media_player_internal.h | 14 ++
>> modules/audio_filter/equalizer.c | 24 ++--
>> modules/audio_filter/equalizer_presets.h | 16 +++
>> 7 files changed, 500 insertions(+), 11 deletions(-)
>>
>> diff --git a/include/vlc/libvlc_media_player.h
>> b/include/vlc/libvlc_media_player.h
>> index 809ed5f..1290343 100644
>> --- a/include/vlc/libvlc_media_player.h
>> +++ b/include/vlc/libvlc_media_player.h
>> @@ -110,6 +110,13 @@ typedef enum libvlc_navigate_mode_t
>> } libvlc_navigate_mode_t;
>>
>> /**
>> + * Opaque equalizer handle.
>> + *
>> + * An equalizer can be associated with a media player.
>> + */
>> +typedef struct libvlc_equalizer_t libvlc_equalizer_t;
>> +
>> +/**
>> * Create an empty Media Player object
>> *
>> * \param p_libvlc_instance the libvlc instance in which the Media Player
>> @@ -1578,6 +1585,205 @@ LIBVLC_API int64_t libvlc_audio_get_delay(
>> libvlc_media_player_t *p_mi );
>> */
>> LIBVLC_API int libvlc_audio_set_delay( libvlc_media_player_t *p_mi,
>> int64_t i_delay );
>>
>> +/**
>> + * Get the number of equalizer presets.
>> + *
>> + * \return number of presets
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API unsigned libvlc_audio_equalizer_get_preset_count( void );
>> +
>> +/**
>> + * Get the name of a particular equalizer preset.
>> + *
>> + * This name can be used, for example, to prepare a preset label or menu
>> in a user
>> + * interface.
>> + *
>> + * \param u_index index of the preset, counting from zero
>> + * \return preset name, or NULL if there is no such preset
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API const char *libvlc_audio_equalizer_get_preset_name( unsigned
>> u_index );
>> +
>> +/**
>> + * Get the number of distinct frequency bands for an equalizer.
>> + *
>> + * \return number of frequency bands
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API unsigned libvlc_audio_equalizer_get_band_count( void );
>> +
>> +/**
>> + * Get a particular equalizer frequency band.
>> + *
>> + * This value can be used, for example, to create a label for an
>> equalizer band control
>> + * in a user interface.
>> + *
>> + * \param u_index index of the band, counting from zero
>> + * \return equalizer band frequency, or -1 if there is no such band
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API float libvlc_audio_equalizer_get_band_frequency( unsigned
>> u_index );
>> +
>> +/**
>> + * Create a new default equalizer, with all frequency values zeroed.
>> + *
>> + * The new equalizer can subsequently be associated with a media player
>> by using
>> + * libvlc_media_player_set_equalizer().
>> + *
>> + * Equalizer instances are reference-counted, and when the application
>> is finished with
>> + * an equalizer instance it should release it by using
>> libvlc_audio_equalizer_release().
>> + *
>> + * \return opaque equalizer handle, or NULL on error
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API libvlc_equalizer_t *libvlc_audio_equalizer_new( void );
>> +
>> +/**
>> + * Create a new equalizer, with initial frequency values copied from an
>> existing
>> + * preset.
>> + *
>> + * The new equalizer can subsequently be associated with a media player
>> by using
>> + * libvlc_media_player_set_equalizer().
>> + *
>> + * Equalizer instances are reference-counted, and when the application
>> is finished with
>> + * an equalizer instance it should release it by using
>> libvlc_audio_equalizer_release().
>> + *
>> + * \param u_index index of the preset, counting from zero
>> + * \return opaque equalizer handle, or NULL on error
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API libvlc_equalizer_t *libvlc_audio_equalizer_new_from_preset(
>> unsigned u_index );
>> +
>> +/**
>> + * Increment the reference count for an equalizer instance.
>> + *
>> + * Equalizer instances are reference-counted, and when the application
>> is finished with
>> + * an equalizer instance it should release it by using
>> libvlc_audio_equalizer_release().
>> + *
>> + * \param p_equalizer opaque equalizer handle
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API void libvlc_audio_equalizer_retain( libvlc_equalizer_t
>> *p_equalizer );
>> +
>> +/**
>> + * Release a previously created or retained equalizer.
>> + *
>> + * The equalizer was previously created by using
>> libvlc_audio_equalizer_new() or
>> + * libvlc_audio_equalizer_new_from_preset(), or a reference to the
>> equalizer was retained
>> + * by using libvlc_audio_equalizer_retain().
>> + *
>> + * Equalizer instances are reference-counted, and when the application
>> is finished with
>> + * an equalizer instance it should release it by using
>> libvlc_audio_equalizer_release().
>> + *
>> + * When the equalizer instance reference count reaches zero, the
>> equalizer is deallocated
>> + * and can no longer be used.
>> + *
>> + * It is safe to invoke this method with a NULL p_equalizer parameter
>> for no effect.
>> + *
>> + * \param p_equalizer opaque equalizer handle, or NULL
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API void libvlc_audio_equalizer_release( libvlc_equalizer_t
>> *p_equalizer );
>> +
>> +/**
>> + * Set a new pre-amplification value for an equalizer.
>> + *
>> + * The new value will be stored in the equalizer immediately, but will
>> not be applied to
>> + * any associated media player audio output until
>> libvlc_media_player_set_equalizer() is
>> + * invoked, or media is played via libvlc_media_player_play().
>> + *
>> + * \param p_equalizer opaque equalizer handle
>> + * \param f_preamp preamp value
>> + * \return zero on success, -1 on error
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API int libvlc_audio_equalizer_set_preamp( libvlc_equalizer_t
>> *p_equalizer, float f_preamp );
>> +
>> +/**
>> + * Get the current pre-amplification value from an equalizer.
>> + *
>> + * \param p_equalizer opaque equalizer handle
>> + * \return preamp value
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API float libvlc_audio_equalizer_get_preamp( libvlc_equalizer_t
>> *p_equalizer );
>> +
>> +/**
>> + * Set a new amplification value for a particular equalizer frequency
>> band.
>> + *
>> + * The new value will be stored in the equalizer immediately, but will
>> not be applied to
>> + * any associated media player audio output until
>> libvlc_media_player_set_equalizer() is
>> + * invoked, or new media is played via libvlc_media_player_play().
>> + *
>> + * \param p_equalizer opaque equalizer handle
>> + * \param f_amp amplification value
>> + * \param u_band index, counting from zero, of the frequency band to set
>> + * \return zero on success, -1 on error
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API int libvlc_audio_equalizer_set_amp_at_index(
>> libvlc_equalizer_t *p_equalizer, float f_amp, unsigned u_band );
>> +
>> +/**
>> + * Get the amplification value for a particular equalizer frequency band.
>> + *
>> + * \param p_equalizer opaque equalizer handle
>> + * \param u_band index, counting from zero, of the frequency band to get
>> + * \return amplification value; this will also return zero if there is
>> no such frequency band
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API float libvlc_audio_equalizer_get_amp_at_index(
>> libvlc_equalizer_t *p_equalizer, unsigned u_band );
>> +
>> +/**
>> + * Associate an equalizer with a media player.
>> + *
>> + * The equalizer is first created by using libvlc_audio_equalizer_new()
>> or
>> + * libvlc_audio_equalizer_new_from_preset().
>> + *
>> + * It is possible to associate new equalizer settings with a media
>> player whether the
>> + * media player is currently playing media or not.
>> + *
>> + * Invoking this method will immediately apply the new equalizer
>> settings to the audio
>> + * output of the currently playing media if there is any.
>> + *
>> + * If there is no currently playing media, the new equalizer settings
>> will be applied
>> + * later if and when new media is played.
>> + *
>> + * Equalizer settings will automatically be applied to subsequently
>> played media.
>> + *
>> + * To disable the equalizer for a media player, invoke this method
>> passing NULL for the
>> + * p_equalizer parameter.
>> + *
>> + * Invoking this method will cause the media player to release (and
>> therefore decrement
>> + * the reference-count of) any currently held equalizer instance, and
>> then retain (and
>> + * therefore increment the reference-count of) the supplied equalizer
>> instance.
>> + *
>> + * Any equalizer instance currently retained by a media player will be
>> released when
>> + * the media player is released. The application that initially
>> allocated the equalizer
>> + * is still responsible for releasing its own reference.
>> + *
>> + * \param p_mi opaque media player handle
>> + * \param p_equalizer opaque equalizer handle, or NULL to disable the
>> equalizer for this media player
>> + * \return zero on success, -1 on error
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API int libvlc_media_player_set_equalizer( libvlc_media_player_t
>> *p_mi, libvlc_equalizer_t *p_equalizer );
>> +
>> +/**
>> + * Get the current equalizer associated with a media player.
>> + *
>> + * If this media player currently holds a valid equalizer instance, then
>> invoking this
>> + * method will cause the reference-count of that equalizer to be
>> incremented.
>> + *
>> + * When the equalizer reference is no longer needed, it should be
>> released by invoking
>> + * libvlc_audio_equalizer_release().
>> + *
>> + * \param p_mi opaque media player handle
>> + * \return opaque equalizer handle, or NULL if there is no equalizer
>> associated with this media player
>> + * \version LibVLC 2.1.0 or later
>> + */
>> +LIBVLC_API libvlc_equalizer_t *libvlc_media_player_get_equalizer(
>> libvlc_media_player_t *p_mi );
>> +
>> /** @} audio */
>>
>> /** @} media_player */
>> diff --git a/lib/audio.c b/lib/audio.c
>> index 27d7cd4..c320efa 100644
>> --- a/lib/audio.c
>> +++ b/lib/audio.c
>> @@ -42,6 +42,8 @@
>> #include "libvlc_internal.h"
>> #include "media_player_internal.h"
>>
>> +#include "modules/audio_filter/equalizer_presets.h"
>> +
>> /*
>> * Remember to release the returned audio_output_t since it is locked at
>> * the end of this function.
>> @@ -507,3 +509,172 @@ int libvlc_audio_set_delay( libvlc_media_player_t
>> *p_mi, int64_t i_delay )
>> }
>> return ret;
>> }
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_get_preset_count : Get the number of equalizer
>> presets
>> +
>> *****************************************************************************/
>> +unsigned libvlc_audio_equalizer_get_preset_count( void )
>> +{
>> + return NB_PRESETS;
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_get_preset_name : Get the name for a preset
>> +
>> *****************************************************************************/
>> +const char *libvlc_audio_equalizer_get_preset_name( unsigned u_index )
>> +{
>> + if ( u_index >= NB_PRESETS )
>> + return NULL;
>> +
>> + return preset_list_text[ u_index ];
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_get_band_count : Get the number of equalizer
>> frequency bands
>> +
>> *****************************************************************************/
>> +unsigned libvlc_audio_equalizer_get_band_count( void )
>> +{
>> + return EQZ_BANDS_MAX;
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_get_band_frequency : Get the frequency for a
>> band
>> +
>> *****************************************************************************/
>> +float libvlc_audio_equalizer_get_band_frequency( unsigned u_index )
>> +{
>> + if ( u_index >= EQZ_BANDS_MAX )
>> + return -1.f;
>> +
>> + return f_vlc_frequency_table_10b[ u_index ];
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_new : Create a new audio equalizer with zeroed
>> values
>> +
>> *****************************************************************************/
>> +libvlc_equalizer_t *libvlc_audio_equalizer_new( void )
>> +{
>> + libvlc_equalizer_t *p_equalizer;
>> +
>> + p_equalizer = malloc( sizeof( *p_equalizer ) );
>> + if ( p_equalizer == NULL )
>> + return NULL;
>> +
>> + p_equalizer->i_refcount = 1;
>> +
>> + p_equalizer->f_preamp = 0.0f;
>> +
>> + for ( unsigned i = 0; i < EQZ_BANDS_MAX; i++ )
>> + p_equalizer->f_amp[ i ] = 0.0f;
>> +
>> + return p_equalizer;
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_new_from_preset : Create a new audio equalizer
>> based on a preset
>> +
>> *****************************************************************************/
>> +libvlc_equalizer_t *libvlc_audio_equalizer_new_from_preset( unsigned
>> u_index )
>> +{
>> + libvlc_equalizer_t *p_equalizer;
>> +
>> + if ( u_index >= NB_PRESETS )
>> + return NULL;
>> +
>> + p_equalizer = libvlc_audio_equalizer_new();
>> + if ( !p_equalizer )
>> + return NULL;
>> +
>> + p_equalizer->f_preamp = eqz_preset_10b[ u_index ].f_preamp;
>> +
>> + for ( unsigned i = 0; i < EQZ_BANDS_MAX; i++ )
>> + p_equalizer->f_amp[ i ] = eqz_preset_10b[ u_index ].f_amp[ i ];
>> +
>> + return p_equalizer;
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_retain : Retain a previously created equalizer
>> +
>> *****************************************************************************/
>> +void libvlc_audio_equalizer_retain( libvlc_equalizer_t *p_equalizer )
>> +{
>> + assert( p_equalizer );
>> +
>> + p_equalizer->i_refcount++;
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_release : Release a previously created
>> equalizer
>> +
>> *****************************************************************************/
>> +void libvlc_audio_equalizer_release( libvlc_equalizer_t *p_equalizer )
>> +{
>> + if ( !p_equalizer )
>> + return;
>> +
>> + p_equalizer->i_refcount--;
>> +
>> + if ( p_equalizer->i_refcount > 0 )
>> + return;
>> +
>> + free( p_equalizer );
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_set_preamp : Set the preamp value for an
>> equalizer
>> +
>> *****************************************************************************/
>> +int libvlc_audio_equalizer_set_preamp( libvlc_equalizer_t *p_equalizer,
>> float f_preamp )
>> +{
>> + if ( !p_equalizer )
>> + return -1;
>> +
>> + if ( f_preamp < -20.0f )
>> + f_preamp = -20.0f;
>> + else if ( f_preamp > 20.0f )
>> + f_preamp = 20.0f;
>> +
>> + p_equalizer->f_preamp = f_preamp;
>> + return 0;
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_get_preamp : Get the preamp value for an
>> equalizer
>> +
>> *****************************************************************************/
>> +float libvlc_audio_equalizer_get_preamp( libvlc_equalizer_t *p_equalizer
>> )
>> +{
>> + if ( !p_equalizer )
>> + return 0.f;
>> +
>> + return p_equalizer->f_preamp;
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_set_amp_at_index : Set the amplification value
>> for an equalizer band
>> +
>> *****************************************************************************/
>> +int libvlc_audio_equalizer_set_amp_at_index( libvlc_equalizer_t
>> *p_equalizer, float f_amp, unsigned u_band )
>> +{
>> + if ( !p_equalizer )
>> + return -1;
>> +
>> + if ( u_band >= EQZ_BANDS_MAX )
>> + return -1;
>> +
>> + if ( f_amp < -20.0f )
>> + f_amp = -20.0f;
>> + else if ( f_amp > 20.0f )
>> + f_amp = 20.0f;
>> +
>> + p_equalizer->f_amp[ u_band ] = f_amp;
>> + return 0;
>> +}
>> +
>>
>> +/*****************************************************************************
>> + * libvlc_audio_equalizer_get_amp_at_index : Get the amplification value
>> for an equalizer band
>> +
>> *****************************************************************************/
>> +float libvlc_audio_equalizer_get_amp_at_index( libvlc_equalizer_t
>> *p_equalizer, unsigned u_band )
>> +{
>> + if ( !p_equalizer )
>> + return 0.f;
>> +
>> + if ( u_band >= EQZ_BANDS_MAX )
>> + return 0.f;
>> +
>> + return p_equalizer->f_amp[ u_band ];
>> +}
>> diff --git a/lib/libvlc.sym b/lib/libvlc.sym
>> index 974e04f..7a0a116 100644
>> --- a/lib/libvlc.sym
>> +++ b/lib/libvlc.sym
>> @@ -3,6 +3,18 @@ libvlc_clearerr
>> libvlc_printerr
>> libvlc_vprinterr
>> libvlc_add_intf
>> +libvlc_audio_equalizer_get_amp_at_index
>> +libvlc_audio_equalizer_get_band_count
>> +libvlc_audio_equalizer_get_band_frequency
>> +libvlc_audio_equalizer_get_preamp
>> +libvlc_audio_equalizer_get_preset_count
>> +libvlc_audio_equalizer_get_preset_name
>> +libvlc_audio_equalizer_new
>> +libvlc_audio_equalizer_new_from_preset
>> +libvlc_audio_equalizer_release
>> +libvlc_audio_equalizer_retain
>> +libvlc_audio_equalizer_set_amp_at_index
>> +libvlc_audio_equalizer_set_preamp
>> libvlc_audio_output_device_count
>> libvlc_audio_output_device_id
>> libvlc_audio_output_device_longname
>> @@ -122,6 +134,7 @@ libvlc_media_player_get_agl
>> libvlc_media_player_get_chapter
>> libvlc_media_player_get_chapter_count
>> libvlc_media_player_get_chapter_count_for_title
>> +libvlc_media_player_get_equalizer
>> libvlc_media_player_get_fps
>> libvlc_media_player_get_hwnd
>> libvlc_media_player_get_length
>> @@ -148,6 +161,7 @@ libvlc_media_player_release
>> libvlc_media_player_retain
>> libvlc_media_player_set_agl
>> libvlc_media_player_set_chapter
>> +libvlc_media_player_set_equalizer
>> libvlc_media_player_set_hwnd
>> libvlc_media_player_set_media
>> libvlc_media_player_set_nsobject
>> diff --git a/lib/media_player.c b/lib/media_player.c
>> index a41b8c7..ceeb5b2 100644
>> --- a/lib/media_player.c
>> +++ b/lib/media_player.c
>> @@ -34,11 +34,14 @@
>> #include <vlc_input.h>
>> #include <vlc_vout.h>
>> #include <vlc_keys.h>
>> +#include <vlc_aout_intf.h>
>>
>> #include "libvlc_internal.h"
>> #include "media_internal.h" // libvlc_media_set_state()
>> #include "media_player_internal.h"
>>
>> +#include "modules/audio_filter/equalizer_presets.h"
>> +
>> /*
>> * mapping of libvlc_navigate_mode_t to vlc_action_t
>> */
>> @@ -482,6 +485,9 @@ libvlc_media_player_new( libvlc_instance_t *instance )
>> var_Create (mp, "amem-rate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
>> var_Create (mp, "amem-channels", VLC_VAR_INTEGER |
>> VLC_VAR_DOINHERIT);
>>
>> + var_Create (mp, "equalizer-preamp", VLC_VAR_FLOAT );
>> + var_Create (mp, "equalizer-bands", VLC_VAR_STRING );
>> +
>> mp->p_md = NULL;
>> mp->state = libvlc_NothingSpecial;
>> mp->p_libvlc_instance = instance;
>> @@ -579,6 +585,7 @@ static void libvlc_media_player_destroy(
>> libvlc_media_player_t *p_mi )
>>
>> libvlc_event_manager_release( p_mi->p_event_manager );
>> libvlc_media_release( p_mi->p_md );
>> + libvlc_audio_equalizer_release( p_mi->p_equalizer );
>> vlc_mutex_destroy( &p_mi->object_lock );
>>
>> libvlc_instance_t *instance = p_mi->p_libvlc_instance;
>> @@ -1409,3 +1416,62 @@ void libvlc_media_player_next_frame(
>> libvlc_media_player_t *p_mi )
>> vlc_object_release( p_input_thread );
>> }
>> }
>> +
>> +int libvlc_media_player_set_equalizer( libvlc_media_player_t *p_mi,
>> libvlc_equalizer_t *p_equalizer )
>> +{
>> + lock( p_mi );
>> +
>> + libvlc_audio_equalizer_release( p_mi->p_equalizer );
>> +
>> + if ( !p_equalizer )
>> + {
>> + p_mi->p_equalizer = NULL;
>> +
>> + unlock( p_mi );
>> +
>> + aout_EnableFilter( p_mi, "equalizer", false );
>> + return 0;
>> + }
>> +
>> + libvlc_audio_equalizer_retain( p_equalizer );
>> +
>> + p_mi->p_equalizer = p_equalizer;
>> +
>> + unlock( p_mi );
>> +
>> + aout_EnableFilter( p_mi, "equalizer", true );
>> +
>> + var_SetFloat( p_mi, "equalizer-preamp", p_equalizer->f_preamp );
>> +
>> + char *psz_bands = NULL;
>> + for ( int i = 0; i < EQZ_BANDS_MAX; i++ )
>> + {
>> + char *psz;
>> + if ( asprintf( &psz, "%s %.07f", psz_bands ? psz_bands : "",
>> p_equalizer->f_amp[i] ) == -1 )
>> + {
>> + free( psz_bands );
>> + return -1;
>> + }
>> + free( psz_bands );
>> + psz_bands = psz;
>> + }
>> + var_SetString( p_mi, "equalizer-bands", psz_bands );
>> + free( psz_bands );
>> +
>> + return 0;
>> +}
>> +
>> +libvlc_equalizer_t *libvlc_media_player_get_equalizer(
>> libvlc_media_player_t *p_mi )
>> +{
>> + libvlc_equalizer_t *p_equalizer;
>> +
>> + lock( p_mi );
>> +
>> + p_equalizer = p_mi->p_equalizer;
>> + if ( p_equalizer )
>> + libvlc_audio_equalizer_retain( p_equalizer );
>> +
>> + unlock( p_mi );
>> +
>> + return p_equalizer;
>> +}
>> diff --git a/lib/media_player_internal.h b/lib/media_player_internal.h
>> index 185f183..e522d9d 100644
>> --- a/lib/media_player_internal.h
>> +++ b/lib/media_player_internal.h
>> @@ -34,6 +34,8 @@
>> #include <vlc/libvlc_media.h>
>> #include <vlc_input.h>
>>
>> +#include "modules/audio_filter/equalizer_presets.h"
>> +
>> struct libvlc_media_player_t
>> {
>> VLC_COMMON_MEMBERS
>> @@ -52,6 +54,8 @@ struct libvlc_media_player_t
>> libvlc_media_t * p_md; /* current media descriptor */
>> libvlc_event_manager_t * p_event_manager;
>> libvlc_state_t state;
>> +
>> + libvlc_equalizer_t *p_equalizer;
>> };
>>
>> /* Media player - audio, video */
>> @@ -62,4 +66,14 @@ libvlc_track_description_t *
>> libvlc_get_track_description(
>> libvlc_media_player_t *p_mi,
>> const char *psz_variable );
>>
>> +/**
>> + * Internal equalizer structure.
>> + */
>> +struct libvlc_equalizer_t
>> +{
>> + int i_refcount;
>> + float f_preamp;
>> + float f_amp[EQZ_BANDS_MAX];
>> +};
>> +
>> #endif
>> diff --git a/modules/audio_filter/equalizer.c
>> b/modules/audio_filter/equalizer.c
>> index 1f88a15..75c0985 100644
>> --- a/modules/audio_filter/equalizer.c
>> +++ b/modules/audio_filter/equalizer.c
>> @@ -232,17 +232,6 @@ typedef struct
>>
>> } eqz_config_t;
>>
>> -/* The frequency tables */
>> -static const float f_vlc_frequency_table_10b[EQZ_BANDS_MAX] =
>> -{
>> - 60, 170, 310, 600, 1000, 3000, 6000, 12000, 14000, 16000,
>> -};
>> -
>> -static const float f_iso_frequency_table_10b[EQZ_BANDS_MAX] =
>> -{
>> - 31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000,
>> -};
>> -
>> /* Equalizer coefficient calculation function based on equ-xmms */
>> static void EqzCoeffs( int i_rate, float f_octave_percent,
>> bool b_use_vlc_freqs,
>> @@ -413,6 +402,13 @@ static int EqzInit( filter_t *p_filter, int i_rate )
>> var_AddCallback( p_aout, "equalizer-preamp", PreampCallback, p_sys );
>> var_AddCallback( p_aout, "equalizer-2pass", TwoPassCallback, p_sys );
>>
>> + /* Preamp and bands go together, so we only need check for one or
>> the other, not both */
>> + if ( var_Type( p_aout->p_parent, "equalizer-preamp" ) )
>> + {
>> + var_AddCallback( p_aout->p_parent, "equalizer-preamp",
>> PreampCallback, p_sys );
>> + var_AddCallback( p_aout->p_parent, "equalizer-bands",
>> BandsCallback, p_sys );
>> + }
>> +
>> msg_Dbg( p_filter, "equalizer loaded for %d Hz with %d bands %d
>> pass",
>> i_rate, p_sys->i_band, p_sys->b_2eqz ? 2 : 1 );
>> for( i = 0; i < p_sys->i_band; i++ )
>> @@ -498,6 +494,12 @@ static void EqzClean( filter_t *p_filter )
>> filter_sys_t *p_sys = p_filter->p_sys;
>> vlc_object_t *p_aout = p_filter->p_parent;
>>
>> + if ( var_Type( p_aout->p_parent, "equalizer-preamp" ) )
>> + {
>> + var_DelCallback( p_aout->p_parent, "equalizer-preamp",
>> PreampCallback, p_sys );
>> + var_DelCallback( p_aout->p_parent, "equalizer-bands",
>> BandsCallback, p_sys );
>> + }
>> +
>> var_DelCallback( p_aout, "equalizer-bands", BandsCallback, p_sys );
>> var_DelCallback( p_aout, "equalizer-preset", PresetCallback, p_sys );
>> var_DelCallback( p_aout, "equalizer-preamp", PreampCallback, p_sys );
>> diff --git a/modules/audio_filter/equalizer_presets.h
>> b/modules/audio_filter/equalizer_presets.h
>> index 0c0c812..f0830ad 100644
>> --- a/modules/audio_filter/equalizer_presets.h
>> +++ b/modules/audio_filter/equalizer_presets.h
>> @@ -21,6 +21,9 @@
>> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
>> 02110-1301, USA.
>>
>> *****************************************************************************/
>>
>> +#ifndef _EQUALIZER_PRESETS_H
>> +#define _EQUALIZER_PRESETS_H 1
>> +
>>
>> /*****************************************************************************
>> * Equalizer presets
>>
>> *****************************************************************************/
>> @@ -30,6 +33,17 @@
>>
>> #define EQZ_BANDS_MAX 10
>>
>> +/* The frequency tables */
>> +static const float f_vlc_frequency_table_10b[EQZ_BANDS_MAX] =
>> +{
>> + 60, 170, 310, 600, 1000, 3000, 6000, 12000, 14000, 16000,
>> +};
>> +
>> +static const float f_iso_frequency_table_10b[EQZ_BANDS_MAX] =
>> +{
>> + 31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000,
>> +};
>> +
>> #define NB_PRESETS 18
>> static const char *const preset_list[NB_PRESETS] = {
>> "flat", "classical", "club", "dance", "fullbass", "fullbasstreble",
>> @@ -132,3 +146,5 @@ static const eqz_preset_t eqz_preset_10b[NB_PRESETS] =
>> { 8, 5.6, -1.11022e-15, -5.6, -4.8, -1.11022e-15, 8, 9.6, 9.6,
>> 8.8 }
>> },
>> };
>> +
>> +#endif
>> --
>> 1.7.9.5
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120820/0c73645b/attachment.html>
More information about the vlc-devel
mailing list