PortamentoTest.cpp (3162B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 PortamentoTest.h - Test For Portamento 5 Copyright (C) 2016 Mark McCurry 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; either version 2 10 of the License, or (at your option) any later version. 11 */ 12 #include "test-suite.h" 13 #include <cmath> 14 #include <cstring> 15 #include <cstdlib> 16 #include <iostream> 17 #include "../Misc/Time.h" 18 #include "../Misc/Allocator.h" 19 #define private public 20 #define protected public 21 #include "../Synth/SynthNote.h" 22 #include "../Synth/Portamento.h" 23 #include "../globals.h" 24 25 using namespace std; 26 using namespace zyn; 27 28 #define MAX_PORTAMENTO_LOOPS 1000 29 30 SYNTH_T *synth; 31 int dummy=0; 32 33 class PortamentoTest 34 { 35 private: 36 AbsTime *time; 37 SYNTH_T *synth; 38 Controller *ctl; 39 public: 40 PortamentoTest() {} 41 void setUp() { 42 synth = new SYNTH_T; 43 time = new AbsTime(*synth); 44 ctl = new Controller(*synth, time); 45 } 46 47 void testPortamentoRange() { 48 //Initialize portamento 49 ctl->setportamento(127); 50 ctl->portamento.time = 127; 51 ctl->portamento.automode = 0; 52 Portamento portamento(*ctl, *synth, false, log2f(40.0f), log2f(40.0f), log2f(400.0f)); 53 TS_ASSERT(portamento.active); 54 //Bounds Check 55 //We put a bound on number of loops executed, or we could be here 56 //a very long time if the exit condition is never fulfilled. 57 int loopcount = 0; 58 while(portamento.active && ++loopcount < MAX_PORTAMENTO_LOOPS) { 59 TS_ASSERT((0.0f <= portamento.x) 60 && (portamento.x <= 1.0f)); 61 TS_ASSERT((log2f(0.1f) <= portamento.freqdelta_log2) 62 && (portamento.freqdelta_log2 <= log2f(1.0f))); 63 portamento.update(); 64 } 65 TS_ASSERT(loopcount < MAX_PORTAMENTO_LOOPS); 66 TS_ASSERT((0.0f <= portamento.x) 67 && (portamento.x <= 1.0f)); 68 TS_ASSERT((log2f(0.1f) <= portamento.freqdelta_log2) 69 && (portamento.freqdelta_log2 <= log2f(1.0f))); 70 } 71 72 void testPortamentoValue() { 73 ctl->setportamento(127); 74 ctl->portamento.time = 127; 75 ctl->portamento.automode = 0; 76 Portamento portamento(*ctl, *synth, false, log2f(40.0f), log2f(40.0f), log2f(400.0f)); 77 TS_ASSERT(portamento.active); 78 int i; 79 for(i = 0; i < 10; ++i) 80 portamento.update(); 81 //Assert that the numbers are the same as they were at release 82 TS_ASSERT_DELTA(portamento.x, 0.0290249f, 0.000001f); 83 TS_ASSERT_DELTA(portamento.freqdelta_log2, -3.2255092, 0.000001f); 84 } 85 86 void tearDown() { 87 delete ctl; 88 delete time; 89 delete synth; 90 } 91 }; 92 93 int main() 94 { 95 PortamentoTest test; 96 RUN_TEST(testPortamentoRange); 97 RUN_TEST(testPortamentoValue); 98 return test_summary(); 99 }