1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 14 сент. 2018 г.
7  *
8  * lsp-plugins 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-plugins 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-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include <dsp/dsp.h>
23 #include <test/ptest.h>
24 #include <core/util/Convolver.h>
25 
26 #define MIN_RANK        8
27 #define MAX_RANK        16
28 #define STEP_SIZE       128
29 
30 #define MIN_LENGTH      (1 << MIN_RANK)
31 #define LEN_STEPS       3
32 #define LEN_SHIFT       4
33 #define MAX_LENGTH      (MIN_LENGTH << (LEN_STEPS * LEN_SHIFT))
34 
35 using namespace dsp;
36 using namespace lsp;
37 
38 //-----------------------------------------------------------------------------
39 // Performance test for equalizer module
40 PTEST_BEGIN("core.util", convolver, 10, 500)
41 
call(float * out,const float * in,const float * conv,size_t count,size_t rank)42     void call(float *out, const float *in, const float *conv, size_t count, size_t rank)
43     {
44         char buf[80];
45         sprintf(buf, "length=%d, rank=%d", int(count), int(rank));
46         printf("Testing convolver %s ...\n", buf);
47 
48         Convolver c;
49         c.init(conv,  count, rank, 0.0f);
50 
51         PTEST_LOOP(buf,
52                 c.process(out, in, STEP_SIZE);
53         );
54 
55         c.destroy();
56     }
57 
58     PTEST_MAIN
59     {
60         uint8_t *data   = NULL;
61         float *in       = alloc_aligned<float>(data, MAX_LENGTH + STEP_SIZE*4, 64);
62         float *out      = &in[STEP_SIZE];
63         float *backup   = &out[STEP_SIZE];
64         float *conv     = &backup[STEP_SIZE*2];
65 
66         for (size_t i=0; i < (MAX_LENGTH + STEP_SIZE*4); ++i)
67             in[i]           = float(rand()) / RAND_MAX;
68 
69         #define CALL(...)  { \
70             dsp::copy(in, backup, STEP_SIZE*2); \
71             call(__VA_ARGS__); \
72         }
73 
74         for (size_t i=0, len=MIN_LENGTH; i<=LEN_STEPS; i++, len <<= LEN_SHIFT)
75         {
76             for (size_t rank=MIN_RANK; rank <= MAX_RANK; ++rank)
77                 CALL(out, in, conv, len, rank);
78 
79             PTEST_SEPARATOR;
80         }
81 
82         free_aligned(data);
83     }
84 PTEST_END
85 
86 
87 
88