1 #include "soundpipe.h"
2 #include "md5.h"
3 #include "tap.h"
4 #include "test.h"
5 
6 typedef struct {
7     sp_adsr *adsr;
8     sp_osc *osc;
9     sp_ftbl *ft;
10 } UserData;
11 
t_adsr(sp_test * tst,sp_data * sp,const char * hash)12 int t_adsr(sp_test *tst, sp_data *sp, const char *hash)
13 {
14     sp_srand(sp, 12345);
15     uint32_t n;
16     int fail = 0;
17     UserData ud;
18     sp_adsr_create(&ud.adsr);
19     sp_osc_create(&ud.osc);
20     sp_ftbl_create(sp, &ud.ft, 8192);
21     SPFLOAT osc = 0, adsr = 0, gate = 0;
22 
23 
24     sp_adsr_init(sp, ud.adsr);
25     sp_gen_sine(sp, ud.ft);
26     sp_osc_init(sp, ud.osc, ud.ft, 0);
27     ud.osc->amp = 0.5;
28 
29 
30     /* allocate / initialize modules here */
31 
32     for(n = 0; n < tst->size; n++) {
33         if(n < tst->size * 0.5) {
34             gate = 1;
35         } else {
36             gate = 0;
37         }
38         sp_adsr_compute(sp, ud.adsr, &gate, &adsr);
39         sp_osc_compute(sp, ud.osc, NULL, &osc);
40         sp_test_add_sample(tst, adsr * osc);
41     }
42 
43     fail = sp_test_verify(tst, hash);
44 
45     /* destroy functions here */
46 
47     sp_adsr_destroy(&ud.adsr);
48     sp_ftbl_destroy(&ud.ft);
49     sp_osc_destroy(&ud.osc);
50 
51     if(fail) return SP_NOT_OK;
52     /* fail by default */
53     else return SP_OK;
54 
55 }
56