Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PadNoteTest.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. PadNoteTest.h - CxxTest for Synth/PADnote
  4. Copyright (C) 20012 zco
  5. Author: zco
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. //Based Upon AdNoteTest.h and SubNoteTest.h
  18. #include <cxxtest/TestSuite.h>
  19. #include <iostream>
  20. #include <fstream>
  21. #include <ctime>
  22. #include <string>
  23. #include "../Misc/Master.h"
  24. #include "../Misc/Util.h"
  25. #include "../Synth/PADnote.h"
  26. #include "../Params/Presets.h"
  27. #include "../DSP/FFTwrapper.h"
  28. #include "../globals.h"
  29. SYNTH_T *synth;
  30. using namespace std;
  31. class PadNoteTest:public CxxTest::TestSuite
  32. {
  33. public:
  34. PADnote *note;
  35. Master *master;
  36. FFTwrapper *fft;
  37. Controller *controller;
  38. unsigned char testnote;
  39. float *outR, *outL;
  40. void setUp() {
  41. synth = new SYNTH_T;
  42. //First the sensible settings and variables that have to be set:
  43. synth->buffersize = 256;
  44. outL = new float[synth->buffersize];
  45. for(int i = 0; i < synth->buffersize; ++i)
  46. *(outL + i) = 0;
  47. outR = new float[synth->buffersize];
  48. for(int i = 0; i < synth->buffersize; ++i)
  49. *(outR + i) = 0;
  50. //next the bad global variables that for some reason have not been properly placed in some
  51. //initialization routine, but rather exist as cryptic oneliners in main.cpp:
  52. denormalkillbuf = new float[synth->buffersize];
  53. for(int i = 0; i < synth->buffersize; ++i)
  54. denormalkillbuf[i] = 0;
  55. //phew, glad to get thouse out of my way. took me a lot of sweat and gdb to get this far...
  56. fft = new FFTwrapper(synth->oscilsize);
  57. //prepare the default settings
  58. PADnoteParameters *defaultPreset = new PADnoteParameters(fft,NULL);
  59. //Assert defaults
  60. ///TS_ASSERT(!defaultPreset->VoicePar[1].Enabled);
  61. XMLwrapper *wrap = new XMLwrapper();
  62. cout << string(SOURCE_DIR) + string("/guitar-adnote.xmz")
  63. << endl;
  64. wrap->loadXMLfile(string(SOURCE_DIR)
  65. + string("/guitar-adnote.xmz"));
  66. TS_ASSERT(wrap->enterbranch("MASTER"));
  67. TS_ASSERT(wrap->enterbranch("PART", 2));
  68. TS_ASSERT(wrap->enterbranch("INSTRUMENT"));
  69. TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT"));
  70. TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT_ITEM", 0));
  71. TS_ASSERT(wrap->enterbranch("PAD_SYNTH_PARAMETERS"));
  72. defaultPreset->getfromXML(wrap);
  73. //defaultPreset->defaults();
  74. defaultPreset->applyparameters(false);
  75. //verify xml was loaded
  76. ///TS_ASSERT(defaultPreset->VoicePar[1].Enabled);
  77. controller = new Controller();
  78. //lets go with.... 50! as a nice note
  79. testnote = 50;
  80. float freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
  81. note = new PADnote(defaultPreset,
  82. controller,
  83. freq,
  84. 120,
  85. 0,
  86. testnote,
  87. false);
  88. //delete defaultPreset;
  89. delete wrap;
  90. }
  91. void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh()
  92. {
  93. master = new Master();
  94. }
  95. void tearDown() {
  96. delete note;
  97. delete controller;
  98. delete fft;
  99. delete [] outL;
  100. delete [] outR;
  101. delete [] denormalkillbuf;
  102. FFT_cleanup();
  103. delete synth;
  104. }
  105. void testDefaults() {
  106. int sampleCount = 0;
  107. //#define WRITE_OUTPUT
  108. #ifdef WRITE_OUTPUT
  109. ofstream file("padnoteout", ios::out);
  110. #endif
  111. note->noteout(outL, outR);
  112. #ifdef WRITE_OUTPUT
  113. for(int i = 0; i < synth->buffersize; ++i)
  114. file << outL[i] << std::endl;
  115. #endif
  116. sampleCount += synth->buffersize;
  117. TS_ASSERT_DELTA(outL[255], 0.0660f, 0.0001f);
  118. note->relasekey();
  119. note->noteout(outL, outR);
  120. sampleCount += synth->buffersize;
  121. TS_ASSERT_DELTA(outL[255], -0.0729f, 0.0001f);
  122. note->noteout(outL, outR);
  123. sampleCount += synth->buffersize;
  124. TS_ASSERT_DELTA(outL[255], 0.0613f, 0.0001f);
  125. note->noteout(outL, outR);
  126. sampleCount += synth->buffersize;
  127. TS_ASSERT_DELTA(outL[255], 0.0378f, 0.0005f);
  128. note->noteout(outL, outR);
  129. sampleCount += synth->buffersize;
  130. TS_ASSERT_DELTA(outL[255], -0.0070f, 0.0001f);
  131. while(!note->finished()) {
  132. note->noteout(outL, outR);
  133. #ifdef WRITE_OUTPUT
  134. for(int i = 0; i < synth->buffersize; ++i)
  135. file << outL[i] << std::endl;
  136. #endif
  137. sampleCount += synth->buffersize;
  138. }
  139. #ifdef WRITE_OUTPUT
  140. file.close();
  141. #endif
  142. TS_ASSERT_EQUALS(sampleCount, 2304);
  143. }
  144. #define OUTPUT_PROFILE
  145. #ifdef OUTPUT_PROFILE
  146. void testSpeed() {
  147. const int samps = 15000;
  148. int t_on = clock(); // timer before calling func
  149. for(int i = 0; i < samps; ++i)
  150. note->noteout(outL, outR);
  151. int t_off = clock(); // timer when func returns
  152. printf("PadNoteTest: %f seconds for %d Samples to be generated.\n",
  153. (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
  154. }
  155. #endif
  156. };