2 ZynAddSubFX - a software synthesizer
4 AdNoteTest.h - CxxTest for Synth/SUBnote
5 Copyright (C) 2009-2011 Mark McCurry
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
14 //Based Upon AdNoteTest.h
15 #include <cxxtest/TestSuite.h>
20 #include "../Misc/Master.h"
21 #include "../Misc/Allocator.h"
22 #include "../Misc/Util.h"
23 #include "../Misc/XMLwrapper.h"
24 #include "../Synth/SUBnote.h"
25 #include "../Params/SUBnoteParameters.h"
26 #include "../Params/Presets.h"
27 #include "../globals.h"
28 #include <rtosc/thread-link.h>
35 class SubNoteTest
:public CxxTest::TestSuite
39 SUBnoteParameters
*pars
;
43 Controller
*controller
;
46 rtosc::ThreadLink
*tr
;
54 //First the sensible settings and variables that have to be set:
55 synth
->buffersize
= 256;
56 time
= new AbsTime(*synth
);
58 outL
= new float[synth
->buffersize
];
59 for(int i
= 0; i
< synth
->buffersize
; ++i
)
61 outR
= new float[synth
->buffersize
];
62 for(int i
= 0; i
< synth
->buffersize
; ++i
)
65 tr
= new rtosc::ThreadLink(1024,3);
66 w
= new WatchManager(tr
);
68 //prepare the default settings
69 SUBnoteParameters
*defaultPreset
= new SUBnoteParameters(time
);
71 wrap
.loadXMLfile(string(SOURCE_DIR
)
72 + string("/guitar-adnote.xmz"));
73 TS_ASSERT(wrap
.enterbranch("MASTER"));
74 TS_ASSERT(wrap
.enterbranch("PART", 1));
75 TS_ASSERT(wrap
.enterbranch("INSTRUMENT"));
76 TS_ASSERT(wrap
.enterbranch("INSTRUMENT_KIT"));
77 TS_ASSERT(wrap
.enterbranch("INSTRUMENT_KIT_ITEM", 0));
78 TS_ASSERT(wrap
.enterbranch("SUB_SYNTH_PARAMETERS"));
79 defaultPreset
->getfromXML(wrap
);
81 controller
= new Controller(*synth
, time
);
83 //lets go with.... 50! as a nice note
84 test_freq_log2
= log2f(440.0f
) + (50.0 - 69.0f
) / 12.0f
;
86 SynthParams pars
{memory
, *controller
, *synth
, *time
, 120, 0, test_freq_log2
, false, prng()};
87 note
= new SUBnote(defaultPreset
, pars
, w
);
88 this->pars
= defaultPreset
;
101 void testDefaults() {
102 //Note: if these tests fail it is due to the relationship between
103 //global.h::RND and SUBnote.cpp
107 //#define WRITE_OUTPUT
110 ofstream
file("subnoteout", ios::out
);
112 note
->noteout(outL
, outR
);
114 for(int i
= 0; i
< synth
->buffersize
; ++i
)
115 file
<< outL
[i
] << std::endl
;
118 sampleCount
+= synth
->buffersize
;
120 TS_ASSERT_DELTA(outL
[255], 0.0010f
, 0.0001f
);
124 TS_ASSERT(!tr
->hasNext());
125 w
->add_watch("noteout/filter");
127 note
->noteout(outL
, outR
);
128 sampleCount
+= synth
->buffersize
;
129 TS_ASSERT_DELTA(outL
[255], 0.0114f
, 0.0001f
);
132 note
->noteout(outL
, outR
);
133 sampleCount
+= synth
->buffersize
;
134 TS_ASSERT_DELTA(outL
[255], -0.0014f
, 0.0001f
);
137 TS_ASSERT(tr
->hasNext());
138 TS_ASSERT_EQUALS(string("noteout/filter"), tr
->read());
139 TS_ASSERT(!tr
->hasNext());
141 w
->add_watch("noteout/amp_int");
142 note
->noteout(outL
, outR
);
143 sampleCount
+= synth
->buffersize
;
144 TS_ASSERT_DELTA(outL
[255], -0.0031f
, 0.0001f
);
147 note
->noteout(outL
, outR
);
148 sampleCount
+= synth
->buffersize
;
149 TS_ASSERT_DELTA(outL
[255], -0.0013f
, 0.0001f
);
151 TS_ASSERT(tr
->hasNext());
152 TS_ASSERT_EQUALS(string("noteout/amp_int"), tr
->read());
153 TS_ASSERT(!tr
->hasNext());
155 while(!note
->finished()) {
156 note
->noteout(outL
, outR
);
158 for(int i
= 0; i
< synth
->buffersize
; ++i
)
159 file
<< outL
[i
] << std::endl
;
162 sampleCount
+= synth
->buffersize
;
168 TS_ASSERT_EQUALS(sampleCount
, 5888);
171 #define OUTPUT_PROFILE
172 #ifdef OUTPUT_PROFILE
174 const int samps
= 15000;
176 int t_on
= clock(); // timer before calling func
177 for(int i
= 0; i
< samps
; ++i
)
178 note
->noteout(outL
, outR
);
179 int t_off
= clock(); // timer when func returns
181 printf("SubNoteTest: %f seconds for %d Samples to be generated.\n",
182 (static_cast<float>(t_off
- t_on
)) / CLOCKS_PER_SEC
, samps
);