LMMS
Loading...
Searching...
No Matches
UnisonTest.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/Util.h"
31#include "../Synth/ADnote.h"
32#include "../Synth/OscilGen.h"
33#include "../Params/Presets.h"
34#include "../DSP/FFTwrapper.h"
35#include "../globals.h"
37
38using namespace std;
39
40
41#define BUF 256
42class AdNoteTest:public CxxTest::TestSuite
43{
44 public:
45
46 ADnote *note;
49 unsigned char testnote;
51 float freq;
52
53
54 float outR[BUF], outL[BUF];
55
56 void setUp() {
57 //First the sensible settings and variables that have to be set:
58 synth = new SYNTH_T;
59 synth->buffersize = BUF;
60
61 memset(outL,0,sizeof(outL));
62 memset(outR,0,sizeof(outR));
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[BUF];
67 memset(denormalkillbuf, 0, sizeof(float)*BUF);
68
69 fft = new FFTwrapper(BUF);
70 //prepare the default settings
72
73 //sawtooth to make things a bit more interesting
74 params->VoicePar[0].OscilSmp->Pcurrentbasefunc = 3;
75
76 controller = new Controller();
77
78 //lets go with.... 50! as a nice note
79 testnote = 50;
80 freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
81
82 }
83
84 void tearDown() {
85 delete note;
86 delete controller;
87 delete fft;
88 delete [] denormalkillbuf;
90 delete synth;
91 delete params;
92 }
93
94 void run_test(int a, int b, int c, int d, int e, int f, float values[4])
95 {
96 sprng(0);
97 params->set_unison_size_index(0,a);
98 params->VoicePar[0].Unison_frequency_spread = b;
99 params->VoicePar[0].Unison_stereo_spread = c;
100 params->VoicePar[0].Unison_vibratto = d;
101 params->VoicePar[0].Unison_vibratto_speed = e;
102 params->VoicePar[0].Unison_invert_phase = f;
103
104 note = new ADnote(params, controller, freq, 120, 0, testnote, false);
105 note->noteout(outL, outR);
106 TS_ASSERT_DELTA(outL[80], values[0], 1e-5);
107 //printf("{%f,", outL[80]);
108 note->noteout(outL, outR);
109 TS_ASSERT_DELTA(outR[90], values[1], 1e-5);
110 //printf("%f,", outR[90]);
111 note->noteout(outL, outR);
112 TS_ASSERT_DELTA(outL[20], values[2], 1e-5);
113 //printf("%f,", outL[20]);
114 note->noteout(outL, outR);
115 TS_ASSERT_DELTA(outR[200], values[3], 1e-5);
116 //printf("%f},\n", outR[200]);
117 }
118
119 void testUnison() {
120 sprng(0xbeef);
121
122 float data[][4] = {
123 {-0.034547,0.034349,-0.000000,0.138284},
124 {0.023612,-0.093842,0.000000,-0.040384},
125 {-0.015980,0.001871,-0.014463,-0.000726},
126 {-0.040970,-0.000275,0.000000,-0.121016},
127 {0.019250,-0.045252,0.000270,0.105372},
128 {-0.086575,0.001130,-0.018921,0.001329},
129 {0.009203,-0.006176,0.017344,-0.003316},
130 {0.029411,-0.000248,-0.112797,-0.012883},
131 {0.043657,-0.014062,-0.003374,-0.071821},
132 {0.007973,0.068019,-0.038900,0.047639},
133 {-0.002055,0.011170,-0.058152,-0.043493},
134 {-0.005298,0.000605,-0.070932,-0.005678},
135 {0.025028,-0.027742,0.020985,-0.015417},
136 {0.074349,0.000640,0.080613,0.066636},
137 {-0.045721,0.000279,0.009819,0.032202},
138 };
139
140 int freq_spread[15];
141 int stereo_spread[15];
142 int vibrato[15];
143 int vibrato_speed[15];
144 int inv_phase[15];
145 for(int i=0; i<15; ++i)
146 {
147 freq_spread[i] = prng()%0x7f;
148 stereo_spread[i] = prng()%0x7f;
149 vibrato[i] = prng()%0x7f;
150 vibrato_speed[i] = prng()%0x7f;
151 inv_phase[i] = prng()%5;
152 }
153
154 for(int i=0; i<15; ++i)
155 {
156 run_test(i, freq_spread[i], stereo_spread[i],
157 vibrato[i], vibrato_speed[i], inv_phase[i], data[i]);
158 }
159#if 0
160 int sampleCount = 0;
161
162 sampleCount += synth->buffersize;
163
164 TS_ASSERT_DELTA(outL[255], 0.254609f, 0.0001f);
165
166 note->noteout(outL, outR);
167 sampleCount += synth->buffersize;
168 TS_ASSERT_DELTA(outL[255], -0.102197f, 0.0001f);
169
170 note->noteout(outL, outR);
171 sampleCount += synth->buffersize;
172 TS_ASSERT_DELTA(outL[255], -0.111422f, 0.0001f);
173
174 note->noteout(outL, outR);
175 sampleCount += synth->buffersize;
176 TS_ASSERT_DELTA(outL[255], -0.021375f, 0.0001f);
177
178 note->noteout(outL, outR);
179 sampleCount += synth->buffersize;
180 TS_ASSERT_DELTA(outL[255], 0.149882f, 0.0001f);
181#endif
182 }
183};
Controller controller
Definition main.C:5
SYNTH_T * synth
Definition LocalZynAddSubFx.cpp:47
uint8_t a
Definition Spc_Cpu.h:141
#define BUF
Definition UnisonTest.h:41
SYNTH_T * synth
Definition UnisonTest.h:36
void FFT_cleanup()
Definition FFTwrapper.cpp:82
float * denormalkillbuf
Definition Util.cpp:46
void sprng(prng_t p)
Definition Util.h:99
prng_t prng(void)
Definition Util.h:94
Definition ADnote.h:41
Definition ADnoteParameters.h:292
Definition AdNoteTest.h:42
ADnoteParameters * params
Definition UnisonTest.h:50
ADnote * note
Definition AdNoteTest.h:45
void testUnison()
Definition UnisonTest.h:119
Controller * controller
Definition AdNoteTest.h:48
float freq
Definition UnisonTest.h:51
void tearDown()
Definition UnisonTest.h:84
unsigned char testnote
Definition AdNoteTest.h:49
void run_test(int a, int b, int c, int d, int e, int f, float values[4])
Definition UnisonTest.h:94
void setUp()
Definition UnisonTest.h:56
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
* e
Definition inflate.c:1404
unsigned d
Definition inflate.c:940
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
JSAMPIMAGE data
Definition jpeglib.h:945
Definition juce_Uuid.h:141
Definition globals.h:204
return c
Definition crypt.c:175
b
Definition crypt.c:628