1 #include "soundpipe.h"
2 #include "md5.h"
3 #include "tap.h"
4 #include "test.h"
5
6 typedef struct {
7 sp_osc *osc;
8 sp_ftbl *ft;
9 sp_tenv *tenv;
10 sp_metro *met;
11 sp_randi *rand;
12 SPFLOAT freq;
13 } UserData;
14
t_metro(sp_test * tst,sp_data * sp,const char * hash)15 int t_metro(sp_test *tst, sp_data *sp, const char *hash)
16 {
17 uint32_t n;
18 int fail = 0;
19 SPFLOAT osc = 0, trig = 0, tenv = 0;
20
21 UserData ud;
22 SPFLOAT *freqp = &ud.freq;
23 ud.freq = 400;
24
25 sp_srand(sp, 12345);
26
27 sp_randi_create(&ud.rand);
28 sp_metro_create(&ud.met);
29 sp_tenv_create(&ud.tenv);
30 sp_ftbl_create(sp, &ud.ft, 2048);
31 sp_osc_create(&ud.osc);
32
33 sp_randi_init(sp, ud.rand);
34 ud.rand->min = 2.0;
35 ud.rand->max= 15.0;
36 sp_metro_init(sp, ud.met);
37 sp_tenv_init(sp, ud.tenv);
38 ud.tenv->atk = 0.005;
39 ud.tenv->hold = 0.01;
40 ud.tenv->rel = 0.003;
41 sp_gen_sine(sp, ud.ft);
42 sp_osc_init(sp, ud.osc, ud.ft, 0);
43 ud.osc->freq = *freqp;
44
45 for(n = 0; n < tst->size; n++) {
46 osc = 0; trig = 0; tenv = 0;
47 sp_randi_compute(sp, ud.rand, NULL, &ud.met->freq);
48 sp_metro_compute(sp, ud.met, NULL, &trig);
49 sp_tenv_compute(sp, ud.tenv, &trig, &tenv);
50 sp_osc_compute(sp, ud.osc, NULL, &osc);
51 sp_test_add_sample(tst, osc * tenv);
52 }
53
54 sp_randi_destroy(&ud.rand);
55 sp_metro_destroy(&ud.met);
56 sp_ftbl_destroy(&ud.ft);
57 sp_osc_destroy(&ud.osc);
58 sp_tenv_destroy(&ud.tenv);
59
60 fail = sp_test_verify(tst, hash);
61
62 if(fail) return SP_NOT_OK;
63 else return SP_OK;
64 }
65