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