equalizer.c 4.85 KB
Newer Older
1 2 3 4 5
/*
 * equalizer.c - libvlc smoke test
 */

#include <string.h>
6
#include <math.h>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

#include "test.h"

static void test_equalizer (const char ** argv, int argc)
{
    libvlc_instance_t *vlc;
    libvlc_media_player_t *mp;
    libvlc_equalizer_t *equalizer;
    unsigned u_presets, u_bands;

    log ("Testing equalizer\n");

    vlc = libvlc_new (argc, argv);
    assert (NULL != vlc);

    mp = libvlc_media_player_new (vlc);
    assert (NULL != mp);

    // presets

    log ("Testing equalizer presets\n");

    u_presets = libvlc_audio_equalizer_get_preset_count();
    assert (u_presets > 0);

    for (unsigned i = 0; i < u_presets; i++)
    {
        assert (NULL != libvlc_audio_equalizer_get_preset_name(i));

        equalizer = libvlc_audio_equalizer_new_from_preset(i);
        assert (equalizer);

        libvlc_audio_equalizer_release(equalizer);
    }

    // preset out of range

    assert (NULL == libvlc_audio_equalizer_get_preset_name(u_presets));
    assert (NULL == libvlc_audio_equalizer_new_from_preset(u_presets));

    // bands

    log ("Testing equalizer bands\n");

    u_bands = libvlc_audio_equalizer_get_band_count();
    assert (u_bands > 0);

    for (unsigned i = 0; i < u_bands; i++)
        assert (-1.0f != libvlc_audio_equalizer_get_band_frequency(i));

    // band out of range

    assert (-1.0f == libvlc_audio_equalizer_get_band_frequency(u_bands));

    // initialisation

    log ("Testing equalizer initialisation\n");

    equalizer = libvlc_audio_equalizer_new();
    assert (equalizer);

    assert (libvlc_audio_equalizer_get_preamp(equalizer) == 0.0f);

    for (unsigned i = 0; i < u_bands; i++)
        assert (libvlc_audio_equalizer_get_amp_at_index(equalizer, i) == 0.0f);

    // preamp (range -20.0 to 20.0)

    log ("Testing equalizer preamp\n");

    assert (0 == libvlc_audio_equalizer_set_preamp (equalizer, 19.9f));
    assert (libvlc_audio_equalizer_get_preamp(equalizer) == 19.9f);

    assert (0 == libvlc_audio_equalizer_set_preamp (equalizer, 20.0f));
    assert (libvlc_audio_equalizer_get_preamp(equalizer) == 20.0f);

    assert (0 == libvlc_audio_equalizer_set_preamp (equalizer, 20.1f));
    assert (libvlc_audio_equalizer_get_preamp(equalizer) == 20.0f);

    assert (0 == libvlc_audio_equalizer_set_preamp (equalizer, -19.9f));
    assert (libvlc_audio_equalizer_get_preamp(equalizer) == -19.9f);

    assert (0 == libvlc_audio_equalizer_set_preamp (equalizer, -20.0f));
    assert (libvlc_audio_equalizer_get_preamp(equalizer) == -20.0f);

    assert (0 == libvlc_audio_equalizer_set_preamp (equalizer, -20.1f));
    assert (libvlc_audio_equalizer_get_preamp(equalizer) == -20.0f);

    // amp at index (range -20.0 to 20.0)

    log ("Testing equalizer amp at index\n");

    for (unsigned i = 0; i < u_bands; i++)
    {
        assert (0 == libvlc_audio_equalizer_set_amp_at_index (equalizer, 19.9f, i));
        assert (libvlc_audio_equalizer_get_amp_at_index (equalizer, i) == 19.9f);

        assert (0 == libvlc_audio_equalizer_set_amp_at_index (equalizer, 20.0f, i));
        assert (libvlc_audio_equalizer_get_amp_at_index (equalizer, i) == 20.0f);

        assert (0 == libvlc_audio_equalizer_set_amp_at_index (equalizer, 20.1f, i));
        assert (libvlc_audio_equalizer_get_amp_at_index (equalizer, i) == 20.0f);

        assert (0 == libvlc_audio_equalizer_set_amp_at_index (equalizer, -19.9f, i));
        assert (libvlc_audio_equalizer_get_amp_at_index (equalizer, i) == -19.9f);

        assert (0 == libvlc_audio_equalizer_set_amp_at_index (equalizer, -20.0f, i));
        assert (libvlc_audio_equalizer_get_amp_at_index (equalizer, i) == -20.0f);

        assert (0 == libvlc_audio_equalizer_set_amp_at_index (equalizer, -20.1f, i));
        assert (libvlc_audio_equalizer_get_amp_at_index (equalizer, i) == -20.0f);
    }

    // amp at index out of range

122
    assert (isnan(libvlc_audio_equalizer_get_amp_at_index (equalizer, u_bands)));
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    assert (-1 == libvlc_audio_equalizer_set_amp_at_index (equalizer, 19.9f, u_bands));

    // no equalizer

    log ("Testing release NULL\n");

    libvlc_audio_equalizer_release (NULL);

    // media player

    log ("Testing set equalizer\n");

    assert (0 == libvlc_media_player_set_equalizer(mp, NULL));
    assert (0 == libvlc_media_player_set_equalizer(mp, equalizer));

    // maximum string length (test string concatenation)

    log ("Testing equalizer-bands string limit\n");

    for (unsigned i = 0; i < u_bands; i++)
143
        assert (0 == libvlc_audio_equalizer_set_amp_at_index (equalizer, -19.1234567f, i));
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

    assert (0 == libvlc_media_player_set_equalizer(mp, equalizer));

    // cleanup

    log ("Testing equalizer cleanup\n");

    libvlc_audio_equalizer_release (equalizer);

    log ("Finished testing equalizer\n");

    libvlc_media_player_release (mp);

    libvlc_release (vlc);
}

int main (void)
{
    test_init();

    test_equalizer (test_defaults_args, test_defaults_nargs);

    return 0;
}