comparison tests/Test_BTrack.cpp @ 117:ca2d83d29814 tip master

Merge branch 'release/1.0.5'
author Adam Stark <adamstark.uk@gmail.com>
date Fri, 18 Aug 2023 20:07:33 +0200
parents 33be76921da9
children
comparison
equal deleted inserted replaced
96:c58f01834337 117:ca2d83d29814
1 #include "doctest.h"
2 #include <BTrack.h>
3
4 //======================================================================
5 //==================== CHECKING INITIALISATION =========================
6 //======================================================================
7 TEST_SUITE ("checkingInitialisation")
8 {
9 //======================================================================
10 TEST_CASE ("constructorWithNoArguments")
11 {
12 BTrack b;
13
14 CHECK_EQ (b.getHopSize(), 512);
15 }
16
17 //======================================================================
18 TEST_CASE("constructorWithHopSize")
19 {
20 BTrack b(1024);
21
22 CHECK_EQ (b.getHopSize(), 1024);
23 }
24
25 //======================================================================
26 TEST_CASE("constructorWithHopSizeAndFrameSize")
27 {
28 BTrack b(256,512);
29
30 CHECK_EQ (b.getHopSize(), 256);
31 }
32
33 }
34
35 //======================================================================
36 //=================== PROCESSING SIMPLE VALUES =========================
37 //======================================================================
38
39 TEST_SUITE("processingSimpleValues")
40 {
41 //======================================================================
42 TEST_CASE ("processZeroValuedOnsetDetectionFunctionSamples")
43 {
44 BTrack b(512);
45
46 long numSamples = 20000;
47
48 std::vector<double> odfSamples;
49
50 int maxInterval = 0;
51 int currentInterval = 0;
52 int numBeats = 0;
53
54 for (int i = 0;i < numSamples;i++)
55 {
56 b.processOnsetDetectionFunctionSample(0.0);
57
58 currentInterval++;
59
60 if (b.beatDueInCurrentFrame())
61 {
62 numBeats++;
63
64 if (currentInterval > maxInterval)
65 {
66 maxInterval = currentInterval;
67 }
68
69 currentInterval = 0;
70 }
71 }
72
73 // check that the maximum interval between beats does not
74 // exceed 100 onset detection function samples (~ 1.3 seconds)
75 CHECK (maxInterval < 100);
76
77 // check that we have at least a beat for every 100 samples
78 CHECK (numBeats > (numSamples/100));
79
80 }
81
82 //======================================================================
83 TEST_CASE ("processRandomOnsetDetectionFunctionSamples")
84 {
85 BTrack b(512);
86
87 long numSamples = 20000;
88
89 std::vector<double> odfSamples;
90
91 int maxInterval = 0;
92 int currentInterval = 0;
93 int numBeats = 0;
94
95 for (int i = 0;i < numSamples;i++)
96 {
97 odfSamples.push_back(random() % 1000);
98 }
99
100 for (int i = 0;i < numSamples;i++)
101 {
102 b.processOnsetDetectionFunctionSample(odfSamples[i]);
103
104 currentInterval++;
105
106 if (b.beatDueInCurrentFrame())
107 {
108 numBeats++;
109
110 if (currentInterval > maxInterval)
111 {
112 maxInterval = currentInterval;
113 }
114
115 currentInterval = 0;
116 }
117 }
118
119 // check that the maximum interval between beats does not
120 // exceed 100 onset detection function samples (~ 1.3 seconds)
121 CHECK(maxInterval < 100);
122
123 // check that we have at least a beat for every 100 samples
124 CHECK(numBeats > (numSamples/100));
125
126 }
127
128 //======================================================================
129 TEST_CASE ("processNegativeOnsetDetectionFunctionSamples")
130 {
131 BTrack b(512);
132
133 long numSamples = 20000;
134
135 std::vector<double> odfSamples;
136
137 int maxInterval = 0;
138 int currentInterval = 0;
139 int numBeats = 0;
140
141 for (int i = 0;i < numSamples;i++)
142 {
143 odfSamples.push_back(-1.0*(random() % 1000));
144 }
145
146 for (int i = 0;i < numSamples;i++)
147 {
148 b.processOnsetDetectionFunctionSample(odfSamples[i]);
149
150 currentInterval++;
151
152 if (b.beatDueInCurrentFrame())
153 {
154 numBeats++;
155
156 if (currentInterval > maxInterval)
157 {
158 maxInterval = currentInterval;
159 }
160
161 currentInterval = 0;
162 }
163 }
164
165 // check that the maximum interval between beats does not
166 // exceed 100 onset detection function samples (~ 1.3 seconds)
167 CHECK (maxInterval < 100);
168
169 // check that we have at least a beat for every 100 samples
170 CHECK (numBeats > (numSamples/100));
171
172 }
173
174 //======================================================================
175 TEST_CASE ("processSeriesOfDeltaFunctions")
176 {
177 BTrack b(512);
178
179 long numSamples = 20000;
180 int beatPeriod = 43;
181
182 std::vector<double> odfSamples;
183
184 int maxInterval = 0;
185 int currentInterval = 0;
186 int numBeats = 0;
187 int correct = 0;
188
189 for (int i = 0;i < numSamples;i++)
190 {
191 if (i % beatPeriod == 0)
192 {
193 odfSamples.push_back(1000);
194 }
195 else
196 {
197 odfSamples.push_back(0.0);
198 }
199 }
200
201 for (int i = 0;i < numSamples;i++)
202 {
203 b.processOnsetDetectionFunctionSample(odfSamples[i]);
204
205 currentInterval++;
206
207 if (b.beatDueInCurrentFrame())
208 {
209 numBeats++;
210
211 if (currentInterval > maxInterval)
212 {
213 maxInterval = currentInterval;
214 }
215
216 if (currentInterval == beatPeriod)
217 {
218 correct++;
219 }
220
221 currentInterval = 0;
222 }
223 }
224
225 // check that the maximum interval between beats does not
226 // exceed 100 onset detection function samples (~ 1.3 seconds)
227 CHECK (maxInterval < 100);
228
229 // check that we have at least a beat for every 100 samples
230 CHECK (numBeats > (numSamples/100));
231
232 // check that the number of correct beats is larger than 99%
233 // of the total number of beats
234 CHECK (((double)correct) > (((double)numBeats)*0.99));
235 }
236 }