LMMS
Loading...
Searching...
No Matches
OscilGenTest.h
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 AdNoteTest.h - CxxTest for Synth/OscilGen
5 Copyright (C) 20011-2012 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#include <cxxtest/TestSuite.h>
23#include <string>
24#include "../Synth/OscilGen.h"
25#include "../globals.h"
27
28using namespace std;
29
30class OscilGenTest:public CxxTest::TestSuite
31{
32 public:
33 float freq;
34 float *outR, *outL;
37
38 void setUp() {
39 synth = new SYNTH_T;
40 //First the sensible settings and variables that have to be set:
41 synth->buffersize = 256;
42 synth->oscilsize = 1024;
43
44 outL = new float[synth->oscilsize];
45 outR = new float[synth->oscilsize];
46 memset(outL, 0, sizeof(float) * synth->oscilsize);
47 memset(outR, 0, sizeof(float) * synth->oscilsize);
48
49 //next the bad global variables that for some reason have not been properly placed in some
50 //initialization routine, but rather exist as cryptic oneliners in main.cpp:
51 denormalkillbuf = new float[synth->buffersize];
52 for(int i = 0; i < synth->buffersize; ++i)
53 denormalkillbuf[i] = 0;
54
55 //prepare the default settings
56 fft = new FFTwrapper(synth->oscilsize);
57 oscil = new OscilGen(fft, NULL);
58
59 //Assert defaults [TODO]
60
61
62 XMLwrapper *wrap = new XMLwrapper();
63 wrap->loadXMLfile(string(SOURCE_DIR)
64 + string("/guitar-adnote.xmz"));
65 TS_ASSERT(wrap->enterbranch("MASTER"));
66 TS_ASSERT(wrap->enterbranch("PART", 0));
67 TS_ASSERT(wrap->enterbranch("INSTRUMENT"));
68 TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT"));
69 TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT_ITEM", 0));
70 TS_ASSERT(wrap->enterbranch("ADD_SYNTH_PARAMETERS"));
71 TS_ASSERT(wrap->enterbranch("VOICE", 0));
72 TS_ASSERT(wrap->enterbranch("OSCIL"));
73 oscil->getfromXML(wrap);
74 delete wrap;
75
76 //verify xml was loaded [TODO]
77
78 //lets go with.... 50! as a nice note
79 const char testnote = 50;
80 freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
81 }
82
83 void tearDown() {
84 delete oscil;
85 delete fft;
86 delete[] outL;
87 delete[] outR;
88 delete[] denormalkillbuf;
90 delete synth;
91 }
92
93 //verifies that initialization occurs
94 void testInit(void)
95 {
96 oscil->get(outL, freq);
97 }
98
99 void testOutput(void)
100 {
101 oscil->get(outL, freq);
102 TS_ASSERT_DELTA(outL[23], -0.044547f, 0.0001f);
103 TS_ASSERT_DELTA(outL[129], -0.018169f, 0.0001f);
104 TS_ASSERT_DELTA(outL[586], 0.045647f, 0.0001f);
105 TS_ASSERT_DELTA(outL[1023], -0.038334f, 0.0001f);
106 }
107
108 void testSpectrum(void)
109 {
110 oscil->getspectrum(synth->oscilsize / 2, outR, 1);
111 TS_ASSERT_DELTA(outR[0], 350.698059f, 0.0001f);
112 TS_ASSERT_DELTA(outR[1], 228.889267f, 0.0001f);
113 TS_ASSERT_DELTA(outR[2], 62.187931f, 0.0001f);
114 TS_ASSERT_DELTA(outR[3], 22.295225f, 0.0001f);
115 TS_ASSERT_DELTA(outR[4], 6.942001f, 0.0001f);
116 TS_ASSERT_DELTA(outR[26], 0.015110f, 0.0001f);
117 TS_ASSERT_DELTA(outR[47], 0.003425f, 0.0001f);
118 TS_ASSERT_DELTA(outR[65], 0.001293f, 0.0001f);
119 }
120
121 //performance testing
122 void testSpeed() {
123 const int samps = 15000;
124
125 int t_on = clock(); // timer before calling func
126 for(int i = 0; i < samps; ++i)
127 oscil->prepare();
128 int t_off = clock(); // timer when func returns
129
130 printf("OscilGenTest: %f seconds for %d prepares.\n",
131 (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
132
133 t_on = clock(); // timer before calling func
134 for(int i = 0; i < samps; ++i)
135 oscil->get(outL, freq);
136 t_off = clock(); // timer when func returns
137
138 printf("OscilGenTest: %f seconds for %d gets.\n",
139 (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
140 }
141};
#define NULL
Definition CarlaBridgeFormat.cpp:30
SYNTH_T * synth
Definition LocalZynAddSubFx.cpp:47
SYNTH_T * synth
Definition OscilGenTest.h:26
void FFT_cleanup()
Definition FFTwrapper.cpp:82
float * denormalkillbuf
Definition Util.cpp:46
Definition FFTwrapper.h:32
Definition OscilGen.h:33
Definition OscilGenTest.h:31
void testSpectrum(void)
Definition OscilGenTest.h:108
float freq
Definition OscilGenTest.h:33
float * outL
Definition OscilGenTest.h:34
FFTwrapper * fft
Definition OscilGenTest.h:35
OscilGen * oscil
Definition OscilGenTest.h:36
void tearDown()
Definition OscilGenTest.h:83
void testInit(void)
Definition OscilGenTest.h:94
float * outR
Definition OscilGenTest.h:34
void testOutput(void)
Definition OscilGenTest.h:99
void setUp()
Definition OscilGenTest.h:38
void testSpeed()
Definition OscilGenTest.h:122
register unsigned i
Definition inflate.c:1575
Definition juce_Uuid.h:141
Definition globals.h:204
#define SOURCE_DIR
Definition zynaddsubfx-src.cpp:21