[vlc-commits] Add an Equalizer API
Hugo Beauzée-Luyssen
git at videolan.org
Fri May 15 14:38:38 CEST 2015
libvlcpp | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri May 15 14:36:34 2015 +0200| [5b0bf8bc604a139dfc2695c9b737ff49a687754b] | committer: Hugo Beauzée-Luyssen
Add an Equalizer API
> http://git.videolan.org/gitweb.cgi/libvlcpp.git/?a=commit;h=5b0bf8bc604a139dfc2695c9b737ff49a687754b
---
vlcpp/Equalizer.hpp | 186 +++++++++++++++++++++++++++++++++++++++++++++++++
vlcpp/MediaPlayer.hpp | 22 ++++--
vlcpp/vlc.hpp | 1 +
3 files changed, 203 insertions(+), 6 deletions(-)
diff --git a/vlcpp/Equalizer.hpp b/vlcpp/Equalizer.hpp
new file mode 100644
index 0000000..c5b2c15
--- /dev/null
+++ b/vlcpp/Equalizer.hpp
@@ -0,0 +1,186 @@
+/*****************************************************************************
+ * Equalizer.hpp: Equalizer API
+ *****************************************************************************
+ * Copyright © 2015 libvlcpp authors & VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
+ *
+ * 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 EQUALIZER_HPP
+#define EQUALIZER_HPP
+
+#include "common.hpp"
+#include "Internal.hpp"
+
+namespace VLC
+{
+
+class Equalizer : public Internal<libvlc_equalizer_t>
+{
+public:
+ /**
+ * Create a new default equalizer, with all frequency values zeroed.
+ *
+ * The new equalizer can subsequently be applied to a media player by invoking
+ * libvlc_media_player_set_equalizer().
+ *
+ * \throw std::runtime_error when equalizer creation fails
+ *
+ * \version LibVLC 2.2.0 or later
+ */
+ Equalizer()
+ : Internal{ libvlc_audio_equalizer_new(), libvlc_audio_equalizer_release }
+ {
+ if ( isValid() == false )
+ throw std::runtime_error( "Failed to create audio equalizer" );
+ }
+
+ /**
+ * Create a new equalizer, with initial frequency values copied from an existing
+ * preset.
+ *
+ * The new equalizer can subsequently be applied to a media player by invoking
+ * libvlc_media_player_set_equalizer().
+ *
+ * \param index index of the preset, counting from zero
+ *
+ * \throw std::runtime_error when equalizer creation fails
+ *
+ * \version LibVLC 2.2.0 or later
+ */
+ Equalizer( unsigned int index )
+ : Internal{ libvlc_audio_equalizer_new_from_preset( index ), libvlc_audio_equalizer_release }
+ {
+ if ( isValid() == false )
+ throw std::runtime_error( "Failed to create audio equalizer" );
+ }
+
+ /**
+ * Set a new pre-amplification value for an equalizer.
+ *
+ * The new equalizer settings are subsequently applied to a media player by invoking
+ * MediaPlayer::setEqualizer().
+ *
+ * The supplied amplification value will be clamped to the -20.0 to +20.0 range.
+ *
+ * \param preamp preamp value (-20.0 to 20.0 Hz)
+ * \return zero on success, -1 on error
+ * \version LibVLC 2.2.0 or later
+ */
+ int setPreamp( float preamp )
+ {
+ return libvlc_audio_equalizer_set_preamp( *this, preamp );
+ }
+
+ /**
+ * Get the current pre-amplification value from an equalizer.
+ *
+ * \return preamp value (Hz)
+ * \version LibVLC 2.2.0 or later
+ */
+ float preamp()
+ {
+ return libvlc_audio_equalizer_get_preamp( *this );
+ }
+
+ /**
+ * Set a new amplification value for a particular equalizer frequency band.
+ *
+ * The new equalizer settings are subsequently applied to a media player by invoking
+ * MediaPlayer::setEqualizer().
+ *
+ * The supplied amplification value will be clamped to the -20.0 to +20.0 range.
+ *
+ * \param amp amplification value (-20.0 to 20.0 Hz)
+ * \param band index, counting from zero, of the frequency band to set
+ * \return zero on success, -1 on error
+ * \version LibVLC 2.2.0 or later
+ */
+ int setAmp( float amp, unsigned int band )
+ {
+ return libvlc_audio_equalizer_set_amp_at_index( *this, amp, band );
+ }
+
+ /**
+ * Get the amplification value for a particular equalizer frequency band.
+ *
+ * \param u_band index, counting from zero, of the frequency band to get
+ * \return amplification value (Hz); NaN if there is no such frequency band
+ * \version LibVLC 2.2.0 or later
+ */
+ float amp( unsigned int band )
+ {
+ return libvlc_audio_equalizer_get_amp_at_index( *this, band );
+ }
+
+ /**
+ * Get the number of equalizer presets.
+ *
+ * \return number of presets
+ * \version LibVLC 2.2.0 or later
+ */
+ static unsigned int presetCount()
+ {
+ return libvlc_audio_equalizer_get_preset_count();
+ }
+
+ /**
+ * 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 index index of the preset, counting from zero
+ * \return preset name, or empty string if there is no such preset
+ * \version LibVLC 2.2.0 or later
+ */
+ static std::string presetName( unsigned index )
+ {
+ return libvlc_audio_equalizer_get_preset_name( index );
+ }
+
+ /**
+ * Get the number of distinct frequency bands for an equalizer.
+ *
+ * \return number of frequency bands
+ * \version LibVLC 2.2.0 or later
+ */
+ static unsigned int bandCount()
+ {
+ return libvlc_audio_equalizer_get_band_count();
+ }
+
+ /**
+ * Get a particular equalizer band frequency.
+ *
+ * This value can be used, for example, to create a label for an equalizer band control
+ * in a user interface.
+ *
+ * \param index index of the band, counting from zero
+ * \return equalizer band frequency (Hz), or -1 if there is no such band
+ * \version LibVLC 2.2.0 or later
+ */
+ static float bandFrequency( unsigned int index )
+ {
+ return libvlc_audio_equalizer_get_band_frequency( index );
+ }
+};
+
+}
+
+#endif // EQUALIZER_HPP
+
diff --git a/vlcpp/MediaPlayer.hpp b/vlcpp/MediaPlayer.hpp
index ba8ea88..3e90f70 100644
--- a/vlcpp/MediaPlayer.hpp
+++ b/vlcpp/MediaPlayer.hpp
@@ -35,10 +35,11 @@ namespace VLC
{
class AudioOutputDeviceDescription;
-class TrackDescription;
+class Equalizer;
class Instance;
class Media;
class MediaPlayerEventManager;
+class TrackDescription;
///
/// \brief The MediaPlayer class exposes libvlc_media_player_t functionnalities
@@ -657,16 +658,25 @@ public:
* so it is safe for an application to release the equalizer reference
* any time after this method returns.
*
- * \param p_equalizer opaque equalizer handle, or NULL to disable the
- * equalizer for this media player
+ * \param equalizer The equalizer to be used by this media player
*
- * \return zero on success, -1 on error
+ * \return true on success, false otherwise
*
* \version LibVLC 2.2.0 or later
*/
- int setEqualizer(libvlc_equalizer_t * p_equalizer)
+ bool setEqualizer(Equalizer& equalizer)
+ {
+ return libvlc_media_player_set_equalizer( *this, equalizer ) == 0;
+ }
+
+ ///
+ /// \brief unsetEqualizer disable equalizer for this media player
+ ///
+ /// \return true on success, false otherwise.
+ ///
+ bool unsetEqualizer()
{
- return libvlc_media_player_set_equalizer(*this, p_equalizer);
+ return libvlc_media_player_set_equalizer( *this, nullptr );
}
/**
diff --git a/vlcpp/vlc.hpp b/vlcpp/vlc.hpp
index 2cf9a7a..b9f3700 100644
--- a/vlcpp/vlc.hpp
+++ b/vlcpp/vlc.hpp
@@ -25,6 +25,7 @@
#define LIBVLC_CXX_VLC_H
#include "Instance.hpp"
+#include "Equalizer.hpp"
#include "MediaListPlayer.hpp"
#include "MediaDiscoverer.hpp"
#include "Media.hpp"
More information about the vlc-commits
mailing list