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