Pārlūkot izejas kodu

VLCMediaPlayer: add Equalizer API (refs #9032)

Felix Paul Kühne 11 gadi atpakaļ
vecāks
revīzija
881decac5e
3 mainītis faili ar 151 papildinājumiem un 6 dzēšanām
  1. 55 2
      Headers/Public/VLCMediaPlayer.h
  2. 4 2
      NEWS
  3. 92 2
      Sources/VLCMediaPlayer.m

+ 55 - 2
Headers/Public/VLCMediaPlayer.h

@@ -2,8 +2,8 @@
  * VLCMediaPlayer.h: VLCKit.framework VLCMediaPlayer header
  *****************************************************************************
  * Copyright (C) 2007-2009 Pierre d'Herbemont
- * Copyright (C) 2007-2009 VLC authors and VideoLAN
- * Copyright (C) 2009-2013 Felix Paul Kühne
+ * Copyright (C) 2007-2014 VLC authors and VideoLAN
+ * Copyright (C) 2009-2014 Felix Paul Kühne
  * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
@@ -406,6 +406,59 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
 @property (readwrite) NSInteger currentAudioPlaybackDelay;
 
 #pragma mark -
+#pragma mark equalizer
+
+/**
+ * Get a list of available equalizer profiles
+ * \Note Current versions do not allow the addition of further profiles
+ *       so you need to handle this in your app.
+ *
+ * \return array of equalizer profiles
+ */
+@property (readonly) NSArray *equalizerProfiles;
+
+/**
+ * Re-set the equalizer to a profile retrieved from the list
+ * \Note This doesn't enable the Equalizer automagically
+ */
+- (void)resetEqualizerFromProfile:(unsigned)profile;
+
+/**
+ * Toggle equalizer state
+ * \param bool value to enable/disable the equalizer
+ * \return current state */
+@property (readwrite) BOOL equalizerEnabled;
+
+/**
+ * Set amplification level
+ * \param The supplied amplification value will be clamped to the -20.0 to +20.0 range.
+ * \note this will create and enabled an Equalizer instance if not present
+ * \return current amplification level */
+@property (readwrite) CGFloat preAmplification;
+
+/**
+ * Number of equalizer bands
+ * \return the number of equalizer bands available in the current release */
+@property (readonly) unsigned numberOfBands;
+
+/**
+ * frequency of equalizer band
+ * \return frequency of the requested equalizer band */
+- (CGFloat)frequencyOfBandAtIndex:(unsigned)index;
+
+/**
+ * set amplification for band
+ * \param amplification value (clamped to the -20.0 to +20.0 range)
+ * \param index of the respective band */
+- (void)setAmplification:(CGFloat)amplification forBand:(unsigned)index;
+
+/**
+ * amplification of band
+ * \param index of the band
+ * \return current amplification value (clamped to the -20.0 to +20.0 range) */
+- (CGFloat)amplificationOfBand:(unsigned)index;
+
+#pragma mark -
 #pragma mark media handling
 
 /* Media Options */

+ 4 - 2
NEWS

@@ -1,5 +1,5 @@
-Version 2.2.0-pre1:
--------------------
+Version 2.2.0:
+--------------
 
 Cross-platform:
 - Fixed deinterlacing if requested
@@ -28,6 +28,8 @@ New APIs:
   - added previous, next and playItemAtIndex selectors
 - VLCMedia:
   - added delegate method mediaMetaDataDidChange
+- VLCMediaPlayer:
+  - added equalizer
 
 Modified API behavior:
 - VLCMediaPlayer:

+ 92 - 2
Sources/VLCMediaPlayer.m

@@ -2,8 +2,8 @@
  * VLCMediaPlayer.m: VLCKit.framework VLCMediaPlayer implementation
  *****************************************************************************
  * Copyright (C) 2007-2009 Pierre d'Herbemont
- * Copyright (C) 2007-2013 VLC authors and VideoLAN
- * Partial Copyright (C) 2009-2013 Felix Paul Kühne
+ * Copyright (C) 2007-2014 VLC authors and VideoLAN
+ * Partial Copyright (C) 2009-2014 Felix Paul Kühne
  * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
@@ -159,6 +159,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     float _position;                     //< The position of the media being played
     id _drawable;                        //< The drawable associated to this media player
     VLCAudio *_audio;
+    libvlc_equalizer_t *_equalizerInstance;
 }
 @end
 
@@ -236,6 +237,11 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     // the media player must be stopped.
     libvlc_media_player_set_nsobject(_playerInstance, nil);
 
+    if (_equalizerInstance) {
+        libvlc_media_player_set_equalizer(_playerInstance, NULL);
+        libvlc_audio_equalizer_release(_equalizerInstance);
+    }
+
     libvlc_media_player_release(_playerInstance);
     if (_privateLibrary != [VLCLibrary sharedLibrary])
         libvlc_release(_privateLibrary.instance);
@@ -773,6 +779,90 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
 }
 
 #pragma mark -
+#pragma mark equalizer
+
+- (void)setEqualizerEnabled:(BOOL)equalizerEnabled
+{
+    if (!equalizerEnabled) {
+        libvlc_media_player_set_equalizer(_playerInstance, NULL);
+
+        if (_equalizerInstance)
+            libvlc_audio_equalizer_release(_equalizerInstance);
+        return;
+    }
+
+    if (!_equalizerInstance)
+        _equalizerInstance = libvlc_audio_equalizer_new();
+    libvlc_media_player_set_equalizer(_playerInstance, _equalizerInstance);
+}
+
+- (NSArray *)equalizerProfiles
+{
+    unsigned count = libvlc_audio_equalizer_get_preset_count();
+    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:count];
+    for (unsigned x = 0; x < count; x++)
+        [array addObject:[NSString stringWithUTF8String:libvlc_audio_equalizer_get_preset_name(x)]];
+
+    return [NSArray arrayWithArray:array];
+}
+
+- (void)resetEqualizerFromProfile:(unsigned)profile
+{
+    BOOL wasactive = NO;
+    if (_equalizerInstance) {
+        libvlc_media_player_set_equalizer(_playerInstance, NULL);
+        libvlc_audio_equalizer_release(_equalizerInstance);
+        wasactive = YES;
+    }
+
+    _equalizerInstance = libvlc_audio_equalizer_new_from_preset(profile);
+    if (wasactive)
+        libvlc_media_player_set_equalizer(_playerInstance, _equalizerInstance);
+}
+
+- (CGFloat)preAmplification
+{
+    if (!_equalizerInstance)
+        return 0.;
+
+    return libvlc_audio_equalizer_get_preamp(_equalizerInstance);
+}
+
+- (void)setPreAmplification:(CGFloat)preAmplification
+{
+    if (!_equalizerInstance)
+        _equalizerInstance = libvlc_audio_equalizer_new();
+
+    libvlc_audio_equalizer_set_preamp(_equalizerInstance, preAmplification);
+}
+
+- (unsigned)numberOfBands
+{
+    return libvlc_audio_equalizer_get_band_count();
+}
+
+- (CGFloat)frequencyOfBandAtIndex:(unsigned int)index
+{
+    return libvlc_audio_equalizer_get_band_frequency(index);
+}
+
+- (void)setAmplification:(CGFloat)amplification forBand:(unsigned int)index
+{
+    if (!_equalizerInstance)
+        _equalizerInstance = libvlc_audio_equalizer_new();
+
+    libvlc_audio_equalizer_set_amp_at_index(_equalizerInstance, amplification, index);
+}
+
+- (CGFloat)amplificationOfBand:(unsigned int)index
+{
+    if (!_equalizerInstance)
+        return 0.;
+
+    return libvlc_audio_equalizer_get_amp_at_index(_equalizerInstance, index);
+}
+
+#pragma mark -
 #pragma mark set/get media
 
 - (void)setMedia:(VLCMedia *)value