~aleteoryx/muditaos

ref: b00548440b4d37ee2806f0760a949b23b7e14aa8 muditaos/module-audio/Audio/test/unittest_config_utils.cpp -rw-r--r-- 2.6 KiB
b0054844 — Lefucjusz [BH-2020] Fix double-free in DecoderMP3 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"

#include <Audio/Profiles/ProfileConfigUtils.hpp>
#include <purefs/filesystem_paths.hpp>

TEST_CASE("QFilterCoefficients - overloaded operator test")
{
    audio::equalizer::QFilterCoefficients coeffs1{1, 1, 1, 1, 1}, coeffs2{1, 1, 1, 1, 1};

    SECTION("Equals")
    {
        REQUIRE(coeffs1 == coeffs2);
    }

    SECTION("Differs 1/5")
    {
        coeffs1.b0 = 2;
        REQUIRE(coeffs1 != coeffs2);
    }

    SECTION("Differs 2/5")
    {
        coeffs2.b1 = 2;
        REQUIRE(coeffs1 != coeffs2);
    }

    SECTION("Differs 3/5")
    {
        coeffs1.a1 = 2;
        REQUIRE(coeffs1 != coeffs2);
    }

    SECTION("Differs 4/5")
    {
        coeffs2.a2 = 2;
        REQUIRE(coeffs1 != coeffs2);
    }

    SECTION("Differs 5/5")
    {
        coeffs2.b2 = 2;
        REQUIRE(coeffs1 != coeffs2);
    }
}

TEST_CASE("Audio profile config utils")
{
    SECTION("Loading config from json file")
    {
        auto config = audio::loadConfigurationFromFile("testfiles/testProfile.json");

        REQUIRE(config.sampleRate_Hz == 44100);
        REQUIRE(config.bitWidth == 8);
        REQUIRE(config.flags == 1);
        REQUIRE(config.inputGain == 2.0);
        REQUIRE(config.outputVolume == 1.0);
        REQUIRE(config.inputPath == audio::codec::InputPath::None);
        REQUIRE(config.outputPath == audio::codec::OutputPath::None);
        REQUIRE(config.playbackPathGain == 2);
        REQUIRE(config.playbackPathAtten == 3);

        audio::equalizer::Equalizer filterCoefficients = {
            qfilter_CalculateCoeffs(audio::equalizer::FilterType::None, 1000.2f, 44100, 0.7f, 10),
            qfilter_CalculateCoeffs(audio::equalizer::FilterType::HighPass, 2000.0f, 8000, 1.7f, -10),
            qfilter_CalculateCoeffs(audio::equalizer::FilterType::LowPass, 10000.0f, 44100, 0.75f, 2.5),
            qfilter_CalculateCoeffs(audio::equalizer::FilterType::Notch, 2500.0f, 44100, 4.4f, 5.3),
            qfilter_CalculateCoeffs(audio::equalizer::FilterType::BandPass, 1000, 44100, 0.7f, 10)};

        for (size_t i = 0; i < audio::equalizer::bands; i++) {
            REQUIRE(config.filterCoefficients.at(i) == filterCoefficients.at(i));
        }
    }

    SECTION("Checking if fallback values are loaded when playback path parameters are out of range")
    {
        auto config = audio::loadConfigurationFromFile("testfiles/testProfileFallback.json");

        REQUIRE(config.playbackPathGain == 0);
        REQUIRE(config.playbackPathAtten == 5);
    }
}