LMMS
Loading...
Searching...
No Matches
AdNoteTest.h
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 AdNoteTest.h - CxxTest for Synth/ADnote
5 Copyright (C) 2009-2011 Mark McCurry
6 Copyright (C) 2009 Harald Hvaal
7 Authors: Mark McCurry, Harald Hvaal
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of version 2 of the GNU General Public License
11 as published by the Free Software Foundation.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License (version 2 or later) for more details.
17
18 You should have received a copy of the GNU General Public License (version 2)
19 along with this program; if not, write to the Free Software Foundation,
20 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22*/
23
24
25#include <cxxtest/TestSuite.h>
26#include <iostream>
27#include <fstream>
28#include <ctime>
29#include <string>
30#include "../Misc/Master.h"
31#include "../Misc/Util.h"
32#include "../Synth/ADnote.h"
33#include "../Params/Presets.h"
34#include "../DSP/FFTwrapper.h"
35#include "../globals.h"
37
38using namespace std;
39
40
41class AdNoteTest:public CxxTest::TestSuite
42{
43 public:
44
49 unsigned char testnote;
50
51
52 float *outR, *outL;
53
54 void setUp() {
55 //First the sensible settings and variables that have to be set:
56 synth = new SYNTH_T;
57 synth->buffersize = 256;
58
59 outL = new float[synth->buffersize];
60 for(int i = 0; i < synth->buffersize; ++i)
61 *(outL + i) = 0;
62 outR = new float[synth->buffersize];
63 for(int i = 0; i < synth->buffersize; ++i)
64 *(outR + i) = 0;
65
66 //next the bad global variables that for some reason have not been properly placed in some
67 //initialization routine, but rather exist as cryptic oneliners in main.cpp:
68 denormalkillbuf = new float[synth->buffersize];
69 for(int i = 0; i < synth->buffersize; ++i)
70 denormalkillbuf[i] = 0;
71
72 //phew, glad to get thouse out of my way. took me a lot of sweat and gdb to get this far...
73
74 fft = new FFTwrapper(synth->oscilsize);
75 //prepare the default settings
76 ADnoteParameters *defaultPreset = new ADnoteParameters(fft);
77
78 //Assert defaults
79 TS_ASSERT(!defaultPreset->VoicePar[1].Enabled);
80
81 XMLwrapper *wrap = new XMLwrapper();
82 cout << string(SOURCE_DIR) + string("/guitar-adnote.xmz")
83 << endl;
84 wrap->loadXMLfile(string(SOURCE_DIR)
85 + string("/guitar-adnote.xmz"));
86 TS_ASSERT(wrap->enterbranch("MASTER"));
87 TS_ASSERT(wrap->enterbranch("PART", 0));
88 TS_ASSERT(wrap->enterbranch("INSTRUMENT"));
89 TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT"));
90 TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT_ITEM", 0));
91 TS_ASSERT(wrap->enterbranch("ADD_SYNTH_PARAMETERS"));
92 defaultPreset->getfromXML(wrap);
93 //defaultPreset->defaults();
94
95 //verify xml was loaded
96 TS_ASSERT(defaultPreset->VoicePar[1].Enabled);
97
98
99
100 controller = new Controller();
101
102 //lets go with.... 50! as a nice note
103 testnote = 50;
104 float freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
105
106 note = new ADnote(defaultPreset,
108 freq,
109 120,
110 0,
111 testnote,
112 false);
113
114 delete defaultPreset;
115 delete wrap;
116 }
117
122
123 void tearDown() {
124 delete note;
125 delete controller;
126 delete fft;
127 delete [] outL;
128 delete [] outR;
129 delete [] denormalkillbuf;
130 FFT_cleanup();
131 delete synth;
132 }
133
135 int sampleCount = 0;
136
137//#define WRITE_OUTPUT
138
139#ifdef WRITE_OUTPUT
140 ofstream file("adnoteout", ios::out);
141#endif
142 note->noteout(outL, outR);
143#ifdef WRITE_OUTPUT
144 for(int i = 0; i < synth->buffersize; ++i)
145 file << outL[i] << std::endl;
146
147#endif
148 sampleCount += synth->buffersize;
149
150 TS_ASSERT_DELTA(outL[255], 0.254609f, 0.0001f);
151
152 note->relasekey();
153
154
155 note->noteout(outL, outR);
156 sampleCount += synth->buffersize;
157 TS_ASSERT_DELTA(outL[255], -0.102197f, 0.0001f);
158
159 note->noteout(outL, outR);
160 sampleCount += synth->buffersize;
161 TS_ASSERT_DELTA(outL[255], -0.111261f, 0.0001f);
162
163 note->noteout(outL, outR);
164 sampleCount += synth->buffersize;
165 TS_ASSERT_DELTA(outL[255], -0.021375f, 0.0001f);
166
167 note->noteout(outL, outR);
168 sampleCount += synth->buffersize;
169 TS_ASSERT_DELTA(outL[255], 0.149149f, 0.0001f);
170
171 while(!note->finished()) {
172 note->noteout(outL, outR);
173#ifdef WRITE_OUTPUT
174 for(int i = 0; i < synth->buffersize; ++i)
175 file << outL[i] << std::endl;
176
177#endif
178 sampleCount += synth->buffersize;
179 }
180#ifdef WRITE_OUTPUT
181 file.close();
182#endif
183
184 TS_ASSERT_EQUALS(sampleCount, 9472);
185 }
186
187#define OUTPUT_PROFILE
188#ifdef OUTPUT_PROFILE
189 void testSpeed() {
190 const int samps = 15000;
191
192 int t_on = clock(); // timer before calling func
193 for(int i = 0; i < samps; ++i)
194 note->noteout(outL, outR);
195 int t_off = clock(); // timer when func returns
196
197 printf("AdNoteTest: %f seconds for %d Samples to be generated.\n",
198 (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
199 }
200#endif
201};
SYNTH_T * synth
Definition LocalZynAddSubFx.cpp:47
SYNTH_T * synth
Definition UnisonTest.h:36
void FFT_cleanup()
Definition FFTwrapper.cpp:82
float * denormalkillbuf
Definition Util.cpp:46
Definition ADnote.h:41
Definition ADnoteParameters.h:292
ADnoteVoiceParam VoicePar[NUM_VOICES]
Definition ADnoteParameters.h:298
void getfromXML(XMLwrapper *xml)
Definition ADnoteParameters.cpp:633
Definition AdNoteTest.h:42
void testSpeed()
Definition AdNoteTest.h:189
Master * master
Definition AdNoteTest.h:46
ADnote * note
Definition AdNoteTest.h:45
Controller * controller
Definition AdNoteTest.h:48
void testDefaults()
Definition AdNoteTest.h:134
float freq
Definition UnisonTest.h:51
void tearDown()
Definition AdNoteTest.h:123
unsigned char testnote
Definition AdNoteTest.h:49
void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh()
Definition AdNoteTest.h:118
void setUp()
Definition AdNoteTest.h:54
FFTwrapper * fft
Definition AdNoteTest.h:47
float * outR
Definition AdNoteTest.h:52
float * outL
Definition AdNoteTest.h:52
Definition Controller.h:9
Definition FFTwrapper.h:32
Definition Master.h:55
register unsigned i
Definition inflate.c:1575
Definition juce_Uuid.h:141
unsigned char Enabled
Definition ADnoteParameters.h:128
Definition globals.h:204
struct zdirent * file
Definition win32.c:1500
#define SOURCE_DIR
Definition zynaddsubfx-src.cpp:21