LMMS
Loading...
Searching...
No Matches
SubNoteTest.h
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 AdNoteTest.h - CxxTest for Synth/SUBnote
5 Copyright (C) 2009-2011 Mark McCurry
6 Author: Mark McCurry
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//Based Upon AdNoteTest.h
24#include <cxxtest/TestSuite.h>
25#include <iostream>
26#include <fstream>
27#include <ctime>
28#include <string>
29#include "../Misc/Master.h"
30#include "../Misc/Util.h"
31#include "../Synth/SUBnote.h"
32#include "../Params/Presets.h"
33#include "../globals.h"
35
36using namespace std;
37
38class SubNoteTest:public CxxTest::TestSuite
39{
40 public:
41
45 unsigned char testnote;
46
47
48 float *outR, *outL;
49
50 void setUp() {
51 synth = new SYNTH_T;
52 //First the sensible settings and variables that have to be set:
53 synth->buffersize = 256;
54
55 outL = new float[synth->buffersize];
56 for(int i = 0; i < synth->buffersize; ++i)
57 *(outL + i) = 0;
58 outR = new float[synth->buffersize];
59 for(int i = 0; i < synth->buffersize; ++i)
60 *(outR + i) = 0;
61
62 //next the bad global variables that for some reason have not been properly placed in some
63 //initialization routine, but rather exist as cryptic oneliners in main.cpp:
64 denormalkillbuf = new float[synth->buffersize];
65 for(int i = 0; i < synth->buffersize; ++i)
66 denormalkillbuf[i] = 0;
67
68 //prepare the default settings
69 SUBnoteParameters *defaultPreset = new SUBnoteParameters();
70 XMLwrapper *wrap = new XMLwrapper();
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);
80
81 controller = new Controller();
82
83 //lets go with.... 50! as a nice note
84 testnote = 50;
85 float freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
86
87 note = new SUBnote(defaultPreset,
89 freq,
90 120,
91 0,
93 false);
94 delete wrap;
95 delete defaultPreset;
96 }
97
102
103 void tearDown() {
104 delete controller;
105 delete note;
106 delete [] outL;
107 delete [] outR;
108 delete [] denormalkillbuf;
109 delete synth;
110 }
111
113 //Note: if these tests fail it is due to the relationship between
114 //global.h::RND and SUBnote.cpp
115
116 int sampleCount = 0;
117
118//#define WRITE_OUTPUT
119
120#ifdef WRITE_OUTPUT
121 ofstream file("subnoteout", ios::out);
122#endif
123 note->noteout(outL, outR);
124#ifdef WRITE_OUTPUT
125 for(int i = 0; i < synth->buffersize; ++i)
126 file << outL[i] << std::endl;
127
128#endif
129 sampleCount += synth->buffersize;
130
131 TS_ASSERT_DELTA(outL[255], 0.0000f, 0.0001f);
132
133 note->relasekey();
134
135
136 note->noteout(outL, outR);
137 sampleCount += synth->buffersize;
138 TS_ASSERT_DELTA(outL[255], 0.0016f, 0.0001f);
139
140 note->noteout(outL, outR);
141 sampleCount += synth->buffersize;
142 TS_ASSERT_DELTA(outL[255], -0.0000f, 0.0001f);
143
144 note->noteout(outL, outR);
145 sampleCount += synth->buffersize;
146 TS_ASSERT_DELTA(outL[255], -0.0013f, 0.0001f);
147
148 note->noteout(outL, outR);
149 sampleCount += synth->buffersize;
150 TS_ASSERT_DELTA(outL[255], -0.0002f, 0.0001f);
151
152 while(!note->finished()) {
153 note->noteout(outL, outR);
154#ifdef WRITE_OUTPUT
155 for(int i = 0; i < synth->buffersize; ++i)
156 file << outL[i] << std::endl;
157
158#endif
159 sampleCount += synth->buffersize;
160 }
161#ifdef WRITE_OUTPUT
162 file.close();
163#endif
164
165 TS_ASSERT_EQUALS(sampleCount, 2304);
166 }
167
168#define OUTPUT_PROFILE
169#ifdef OUTPUT_PROFILE
170 void testSpeed() {
171 const int samps = 15000;
172
173 int t_on = clock(); // timer before calling func
174 for(int i = 0; i < samps; ++i)
175 note->noteout(outL, outR);
176 int t_off = clock(); // timer when func returns
177
178 printf("SubNoteTest: %f seconds for %d Samples to be generated.\n",
179 (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
180 }
181#endif
182};
SYNTH_T * synth
Definition LocalZynAddSubFx.cpp:47
SYNTH_T * synth
Definition SubNoteTest.h:34
float * denormalkillbuf
Definition Util.cpp:46
Definition Controller.h:9
Definition Master.h:55
Definition SUBnote.h:34
Definition SUBnoteParameters.h:33
void getfromXML(XMLwrapper *xml)
Definition SUBnoteParameters.cpp:240
Definition SubNoteTest.h:39
unsigned char testnote
Definition SubNoteTest.h:45
Controller * controller
Definition SubNoteTest.h:44
Master * master
Definition SubNoteTest.h:43
void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh()
Definition SubNoteTest.h:98
float * outL
Definition SubNoteTest.h:48
float * outR
Definition SubNoteTest.h:48
SUBnote * note
Definition SubNoteTest.h:42
void setUp()
Definition SubNoteTest.h:50
void tearDown()
Definition SubNoteTest.h:103
void testSpeed()
Definition SubNoteTest.h:170
void testDefaults()
Definition SubNoteTest.h:112
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