| 1 |
/* |
| 2 |
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2026 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 7 сент. 2019 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <lsp-plug.in/test-fw/utest.h> |
| 23 |
#include <lsp-plug.in/test-fw/helpers.h> |
| 24 |
#include <lsp-plug.in/fmt/RoomEQWizard.h> |
| 25 |
|
| 26 |
using namespace lsp; |
| 27 |
|
| 28 |
UTEST_BEGIN("runtime.fmt", roomeqwizard) |
| 29 |
|
| 30 |
void check_filter(const room_ew::filter_t *f, |
| 31 |
bool enabled, room_ew::filter_type_t type, |
| 32 |
double fc, double gain, double Q |
| 33 |
) |
| 34 |
{ |
| 35 |
printf( |
| 36 |
"Filter %s [%d] Fc %.0f Hz Gain %.1f dB Q %.7f\n", |
| 37 |
(f->enabled) ? "ON" : "OFF", f->filterType, |
| 38 |
double(f->fc), double(f->gain), double(f->Q) |
| 39 |
); |
| 40 |
UTEST_ASSERT(f->enabled == enabled); |
| 41 |
UTEST_ASSERT(f->filterType == type); |
| 42 |
UTEST_ASSERT(float_equals_absolute(f->fc, fc)); |
| 43 |
UTEST_ASSERT(float_equals_absolute(f->gain, gain)); |
| 44 |
if (Q >= 0.0) |
| 45 |
UTEST_ASSERT(float_equals_adaptive(f->Q, Q, 0.5e-3f)); |
| 46 |
} |
| 47 |
|
| 48 |
void read_file(const char *fname) |
| 49 |
{ |
| 50 |
room_ew::config_t *cfg = NULL; |
| 51 |
|
| 52 |
// Load the equalizer settings |
| 53 |
io::Path path; |
| 54 |
UTEST_ASSERT(path.set(resources()) == STATUS_OK); |
| 55 |
UTEST_ASSERT(path.append_child(fname) == STATUS_OK); |
| 56 |
UTEST_ASSERT(room_ew::load(&path, &cfg) == STATUS_OK); |
| 57 |
|
| 58 |
// Check configuration |
| 59 |
UTEST_ASSERT(cfg != NULL); |
| 60 |
UTEST_ASSERT(::strcmp(cfg->sNotes, "test notes") == 0); |
| 61 |
UTEST_ASSERT(::strcmp(cfg->sEqType, "Generic") == 0); |
| 62 |
UTEST_ASSERT(cfg->nVerMaj == 5); |
| 63 |
UTEST_ASSERT(cfg->nVerMin == 19); |
| 64 |
UTEST_ASSERT(cfg->nFilters == 20); |
| 65 |
UTEST_ASSERT(cfg->vFilters != NULL); |
| 66 |
|
| 67 |
room_ew::filter_t *vf = cfg->vFilters; |
| 68 |
size_t idx = 0; |
| 69 |
|
| 70 |
check_filter(&vf[idx++], true, room_ew::PK, 100.00, 10.00, 0.7100000); |
| 71 |
check_filter(&vf[idx++], true, room_ew::LS, 1000.00, 10.00, -1); |
| 72 |
check_filter(&vf[idx++], true, room_ew::HS, 1000.00, -10.00, -1); |
| 73 |
check_filter(&vf[idx++], true, room_ew::PK, 10000.00, -10.00, 0.7100000); |
| 74 |
check_filter(&vf[idx++], true, room_ew::HS, 321.00, 0.00, -1); |
| 75 |
check_filter(&vf[idx++], true, room_ew::NONE, 100.00, 0.00, -1); |
| 76 |
check_filter(&vf[idx++], true, room_ew::PK, 100.00, 0.00, 10.0000000); |
| 77 |
check_filter(&vf[idx++], true, room_ew::MODAL, 100.00, 0.00, 13.643000); |
| 78 |
check_filter(&vf[idx++], true, room_ew::LP, 100.00, 0.00, 0.7071068); |
| 79 |
check_filter(&vf[idx++], true, room_ew::HP, 100.00, 0.00, 0.7071068); |
| 80 |
check_filter(&vf[idx++], true, room_ew::LPQ, 100.00, 0.00, 0.7070000); |
| 81 |
check_filter(&vf[idx++], true, room_ew::HPQ, 100.00, 0.00, 0.7070000); |
| 82 |
check_filter(&vf[idx++], true, room_ew::LS, 100.00, 0.00, -1); |
| 83 |
check_filter(&vf[idx++], true, room_ew::HS, 100.00, 0.00, -1); |
| 84 |
check_filter(&vf[idx++], true, room_ew::LS6, 100.00, 0.00, -1); |
| 85 |
check_filter(&vf[idx++], true, room_ew::HS6, 100.00, 0.00, -1); |
| 86 |
check_filter(&vf[idx++], true, room_ew::LS12, 100.00, 0.00, -1); |
| 87 |
check_filter(&vf[idx++], true, room_ew::HS12, 100.00, 0.00, -1); |
| 88 |
check_filter(&vf[idx++], false, room_ew::NO, 100.00, 0.00, -1); |
| 89 |
check_filter(&vf[idx++], true, room_ew::AP, 100.00, 0.00, 0.7070000); |
| 90 |
|
| 91 |
::free(cfg); |
| 92 |
} |
| 93 |
|
| 94 |
void read_file2(const char *fname) |
| 95 |
{ |
| 96 |
room_ew::config_t *cfg = NULL; |
| 97 |
|
| 98 |
// Load the equalizer settings |
| 99 |
io::Path path; |
| 100 |
UTEST_ASSERT(path.set(resources()) == STATUS_OK); |
| 101 |
UTEST_ASSERT(path.append_child(fname) == STATUS_OK); |
| 102 |
UTEST_ASSERT(room_ew::load(&path, &cfg) == STATUS_OK); |
| 103 |
|
| 104 |
// Check configuration |
| 105 |
UTEST_ASSERT(cfg != NULL); |
| 106 |
UTEST_ASSERT(::strcmp(cfg->sNotes, "This file demonstrates all filter types the Generic equalizer supports") == 0); |
| 107 |
UTEST_ASSERT(::strcmp(cfg->sEqType, "Generic") == 0); |
| 108 |
UTEST_ASSERT(cfg->nVerMaj == 5); |
| 109 |
UTEST_ASSERT(cfg->nVerMin == 1); |
| 110 |
UTEST_ASSERT(cfg->nFilters == 20); |
| 111 |
UTEST_ASSERT(cfg->vFilters != NULL); |
| 112 |
|
| 113 |
room_ew::filter_t *vf = cfg->vFilters; |
| 114 |
size_t idx = 0; |
| 115 |
|
| 116 |
check_filter(&vf[idx++], true, room_ew::PK, 50.00, -10.00, 2.50); |
| 117 |
check_filter(&vf[idx++], true, room_ew::MODAL, 100.00, 3.0, 5.41); |
| 118 |
check_filter(&vf[idx++], true, room_ew::LP, 8.0, 0.0, -1); |
| 119 |
check_filter(&vf[idx++], true, room_ew::HP, 30.00, 0.0, -1); |
| 120 |
check_filter(&vf[idx++], true, room_ew::LPQ, 10.00, 0.0, 0.4); |
| 121 |
check_filter(&vf[idx++], true, room_ew::HPQ, 20.00, 0.0, 0.5); |
| 122 |
check_filter(&vf[idx++], true, room_ew::LS, 300.00, 5.0, -1); |
| 123 |
check_filter(&vf[idx++], true, room_ew::HS, 1.00, -3.0, -1); |
| 124 |
check_filter(&vf[idx++], true, room_ew::LS12, 2.00, -5.0, -1); |
| 125 |
check_filter(&vf[idx++], true, room_ew::HS12, 500.0, 5.0, -1); |
| 126 |
check_filter(&vf[idx++], true, room_ew::LS6, 50.0, 7.2, -1); |
| 127 |
check_filter(&vf[idx++], true, room_ew::HS6, 12.0, 10.0, -1); |
| 128 |
check_filter(&vf[idx++], true, room_ew::NO, 800.00, 0.00, -1); |
| 129 |
check_filter(&vf[idx++], true, room_ew::AP, 900.00, 0.00, 0.707); |
| 130 |
|
| 131 |
::free(cfg); |
| 132 |
} |
| 133 |
|
| 134 |
void read_file3(const char *fname) |
| 135 |
{ |
| 136 |
room_ew::config_t *cfg = NULL; |
| 137 |
|
| 138 |
// Load the equalizer settings |
| 139 |
io::Path path; |
| 140 |
UTEST_ASSERT(path.set(resources()) == STATUS_OK); |
| 141 |
UTEST_ASSERT(path.append_child(fname) == STATUS_OK); |
| 142 |
UTEST_ASSERT(room_ew::load(&path, &cfg) == STATUS_OK); |
| 143 |
|
| 144 |
// Check configuration |
| 145 |
UTEST_ASSERT(cfg != NULL); |
| 146 |
UTEST_ASSERT(::strcmp(cfg->sNotes, "") == 0); |
| 147 |
UTEST_ASSERT(::strcmp(cfg->sEqType, "") == 0); |
| 148 |
UTEST_ASSERT(cfg->nVerMaj == 0); |
| 149 |
UTEST_ASSERT(cfg->nVerMin == 0); |
| 150 |
UTEST_ASSERT(float_equals_adaptive(cfg->fPreamp, -6.9)); |
| 151 |
UTEST_ASSERT(cfg->nFilters == 10); |
| 152 |
UTEST_ASSERT(cfg->vFilters != NULL); |
| 153 |
|
| 154 |
room_ew::filter_t *vf = cfg->vFilters; |
| 155 |
size_t idx = 0; |
| 156 |
|
| 157 |
check_filter(&vf[idx++], true, room_ew::PK, 91.0, -1.7, 1.525); |
| 158 |
check_filter(&vf[idx++], true, room_ew::LSC, 112.0, 2.1, 1.387); |
| 159 |
check_filter(&vf[idx++], true, room_ew::PK, 539.0, 5.4, 0.585); |
| 160 |
check_filter(&vf[idx++], true, room_ew::PK, 1918.0, -4.1, 2.221); |
| 161 |
check_filter(&vf[idx++], true, room_ew::PK, 3103.0, 7.8, 1.502); |
| 162 |
check_filter(&vf[idx++], true, room_ew::PK, 4493.0, -6.6, 3.300); |
| 163 |
check_filter(&vf[idx++], true, room_ew::PK, 6100.0, 4.4, 1.900); |
| 164 |
check_filter(&vf[idx++], true, room_ew::HSC, 8600.0, 2.0, 2.537); |
| 165 |
check_filter(&vf[idx++], true, room_ew::PK, 11200.0, -7.0, 3.001); |
| 166 |
check_filter(&vf[idx++], true, room_ew::PK, 14886.0, 4.2, 2.100); |
| 167 |
|
| 168 |
::free(cfg); |
| 169 |
} |
| 170 |
|
| 171 |
UTEST_MAIN |
| 172 |
{ |
| 173 |
printf("Testing binary file...\n"); |
| 174 |
read_file("fmt/rew/Test11.req"); |
| 175 |
|
| 176 |
printf("Testing text file...\n"); |
| 177 |
read_file("fmt/rew/Test11.txt"); |
| 178 |
|
| 179 |
printf("Testing another file...\n"); |
| 180 |
read_file2("fmt/apo/demo.txt"); |
| 181 |
|
| 182 |
printf("Testing another file...\n"); |
| 183 |
read_file3("fmt/apo/effects.apo.txt"); |
| 184 |
} |
| 185 |
|
| 186 |
UTEST_END |
| 187 |
|
| 188 |
|