[vlc-devel] [PATCH 2/2] Add simple test for the libvlc equalizer API.

Mark Lee mark.lee at capricasoftware.co.uk
Sun Aug 12 10:30:46 CEST 2012


---
 doc/libvlc/equalizer.c |  196 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 196 insertions(+)
 create mode 100644 doc/libvlc/equalizer.c

diff --git a/doc/libvlc/equalizer.c b/doc/libvlc/equalizer.c
new file mode 100644
index 0000000..5823b6f
--- /dev/null
+++ b/doc/libvlc/equalizer.c
@@ -0,0 +1,196 @@
+/**
+ * A simple program to test the audio equalizer API in libvlc.
+ *
+ * An example build command:
+ *
+ * gcc -std=c99 -I/home/linux/vlc/vlc/include -o equalizer equalizer.c `pkg-config --cflags --libs libvlc`
+ *
+ * You may use this example code freely for any purpose without restriction.
+ *
+ * When running this test, you must pass via the command-line two separate audio filenames
+ * to be played during the test - for example:
+ *
+ * ./equalizer /home/music/1.mp3 /home/music/2.mp3
+ *
+ * (C)2012 Mark Lee <mark.lee at capricasoftware.co.uk>
+ */
+
+#include <unistd.h>
+#include <vlc/vlc.h>
+#include <vlc/libvlc.h>
+
+int main(int argc, char *argv[]) {
+
+    if(argc != 3) {
+        printf("Specify two audio file names\n");
+        return -1;
+    }
+
+    char *psz_file1 = argv[1];
+    char *psz_file2 = argv[2];
+
+    libvlc_instance_t *p_instance = libvlc_new(0, NULL);
+
+    printf("Equalizer Tests\n\n");
+
+    // Dump out the individual frequency bands
+    printf("Bands...\n");
+    unsigned u_bands = libvlc_audio_equalizer_get_band_count();
+    for(int i = 0; i < u_bands; i++) {
+        printf(" Band %2d -> %.1fHz\n", i, libvlc_audio_equalizer_get_band_frequency(i));
+    }
+    printf("\n");
+
+    // Dump out each preset name
+    printf("Presets...\n");
+    unsigned u_presets = libvlc_audio_equalizer_get_preset_count();
+    for(int i = 0; i < u_presets; i++) {
+        printf(" Preset %2d -> %s\n", i, libvlc_audio_equalizer_get_preset_name(i));
+    }
+    printf("\n");
+
+    // Dump out the settings for each preset
+    for(int i = 0; i < u_presets; i++) {
+        const char* psz_name = libvlc_audio_equalizer_get_preset_name(i);
+        printf("%d %s\n", i, psz_name);
+        libvlc_equalizer_t *p_equalizer = libvlc_audio_equalizer_new_from_preset(i);
+        printf(" Preamp: %18.2fdB\n", libvlc_audio_equalizer_get_preamp(p_equalizer));
+        for(int j = 0; j < u_bands; j++) {
+            printf("   Band: %7.1fHz -> %5.2fdB\n", libvlc_audio_equalizer_get_band_frequency(j), libvlc_audio_equalizer_get_amp_at_index(p_equalizer, j));
+        }
+        libvlc_audio_equalizer_release(p_equalizer);
+        printf("\n");
+    }
+
+    // Now some tests with the equalizer and a media player...
+
+    libvlc_media_player_t *p_media_player = libvlc_media_player_new(p_instance);
+
+    libvlc_media_t *p_media = libvlc_media_new_path(p_instance, psz_file1);
+    libvlc_media_player_set_media(p_media_player, p_media);
+    libvlc_media_release(p_media);
+
+    // sleep(i_delay) is used just because it is convenient for this test, of course you wouldn't do that normally
+    int i_delay = 5; // seconds
+
+    // Presets...
+
+    libvlc_equalizer_t *p_equalizer_full_treble = libvlc_audio_equalizer_new_from_preset(6);
+    libvlc_equalizer_t *p_equalizer_full_bass   = libvlc_audio_equalizer_new_from_preset(4);
+
+    // It is possible to set an equalizer before playing media
+    printf("Set full treble\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer_full_treble);
+
+    // Now play...
+    printf("Play\n");
+    libvlc_media_player_play(p_media_player);
+    sleep(i_delay);
+
+    // Change equalizer while playing
+    printf("Set full bass\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer_full_bass);
+    sleep(i_delay);
+
+    printf("Set full treble\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer_full_treble);
+    sleep(i_delay);
+
+    // Stop playback
+    printf("Stop\n");
+    libvlc_media_player_stop(p_media_player);
+    sleep(1);
+
+    // Start playback, settings should be remembered
+    printf("Play\n");
+    libvlc_media_player_play(p_media_player);
+    sleep(i_delay);
+
+    // Change equalizer while playing
+    printf("Set full bass\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer_full_bass);
+    sleep(i_delay);
+
+    printf("Set full treble\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer_full_treble);
+    sleep(i_delay);
+
+    // Change media
+    printf("Change media\n");
+    p_media = libvlc_media_new_path(p_instance, psz_file2);
+    libvlc_media_player_set_media(p_media_player, p_media);
+    libvlc_media_release(p_media);
+
+    // Play new media, settings should be remembered
+    libvlc_media_player_play(p_media_player);
+
+    sleep(i_delay);
+
+    // Change equalizer while playing
+    printf("Set full bass\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer_full_bass);
+    sleep(i_delay);
+
+    printf("Set full treble\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer_full_treble);
+    sleep(i_delay);
+
+    printf("Disable equalizer\n");
+    libvlc_media_player_set_equalizer(p_media_player, NULL);
+    sleep(i_delay);
+
+    printf("Set full treble\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer_full_treble);
+    sleep(i_delay);
+
+    printf("Disable equalizer\n");
+    libvlc_media_player_set_equalizer(p_media_player, NULL);
+    sleep(i_delay);
+
+    // We're finished with the presets, they are no longer associated with any
+    // media player, so release them
+    libvlc_audio_equalizer_release(p_equalizer_full_bass);
+    libvlc_audio_equalizer_release(p_equalizer_full_treble);
+
+    libvlc_media_player_stop(p_media_player);
+
+    // Custom...
+
+    libvlc_equalizer_t *p_equalizer = libvlc_audio_equalizer_new();
+    libvlc_audio_equalizer_set_preamp(p_equalizer, 6.5f);
+    libvlc_audio_equalizer_set_amp_at_index(p_equalizer, 20.0f, 1);
+    libvlc_audio_equalizer_set_amp_at_index(p_equalizer, 15.3f, 7);
+    libvlc_audio_equalizer_set_amp_at_index(p_equalizer, 16.2f, 8);
+    libvlc_audio_equalizer_set_amp_at_index(p_equalizer, 17.1f, 9);
+
+    // Set a new custom equalizer before playback starts
+    printf("Set custom\n");
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer);
+
+    printf("Play\n");
+    libvlc_media_player_play(p_media_player);
+    sleep(i_delay);
+
+    // Change the custom equalizer while playing
+    printf("Change custom\n");
+    libvlc_audio_equalizer_set_preamp(p_equalizer, 8.75f);
+    libvlc_audio_equalizer_set_amp_at_index(p_equalizer, 20.0f, 4);
+    libvlc_audio_equalizer_set_amp_at_index(p_equalizer, 20.0f, 5);
+    libvlc_media_player_set_equalizer(p_media_player, p_equalizer);
+    sleep(i_delay);
+
+    printf("Disable equalizer\n");
+    libvlc_media_player_set_equalizer(p_media_player, NULL);
+    sleep(i_delay);
+
+    printf("End of test\n");
+
+    libvlc_audio_equalizer_release(p_equalizer);
+
+    libvlc_media_player_stop(p_media_player);
+
+    libvlc_media_player_release(p_media_player);
+
+    libvlc_release(p_instance);
+    return 0;
+}
-- 
1.7.9.5




More information about the vlc-devel mailing list