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