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.

202 lines
6.1KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. AdNoteTest.h - CxxTest for Synth/ADnote
  4. Copyright (C) 2009-2011 Mark McCurry
  5. Copyright (C) 2009 Harald Hvaal
  6. Authors: Mark McCurry, Harald Hvaal
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of version 2 of the GNU General Public License
  9. as published by the Free Software Foundation.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License (version 2 or later) for more details.
  14. You should have received a copy of the GNU General Public License (version 2)
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  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/ADnote.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 AdNoteTest:public CxxTest::TestSuite
  32. {
  33. public:
  34. ADnote *note;
  35. Master *master;
  36. FFTwrapper *fft;
  37. Controller *controller;
  38. unsigned char testnote;
  39. float *outR, *outL;
  40. void setUp() {
  41. //First the sensible settings and variables that have to be set:
  42. synth = new SYNTH_T;
  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. ADnoteParameters *defaultPreset = new ADnoteParameters(fft);
  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", 0));
  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("ADD_SYNTH_PARAMETERS"));
  72. defaultPreset->getfromXML(wrap);
  73. //defaultPreset->defaults();
  74. //verify xml was loaded
  75. TS_ASSERT(defaultPreset->VoicePar[1].Enabled);
  76. controller = new Controller();
  77. //lets go with.... 50! as a nice note
  78. testnote = 50;
  79. float freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
  80. note = new ADnote(defaultPreset,
  81. controller,
  82. freq,
  83. 120,
  84. 0,
  85. testnote,
  86. false);
  87. delete defaultPreset;
  88. delete wrap;
  89. }
  90. void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh()
  91. {
  92. master = new Master();
  93. }
  94. void tearDown() {
  95. delete note;
  96. delete controller;
  97. delete fft;
  98. delete [] outL;
  99. delete [] outR;
  100. delete [] denormalkillbuf;
  101. FFT_cleanup();
  102. delete synth;
  103. }
  104. void testDefaults() {
  105. int sampleCount = 0;
  106. //#define WRITE_OUTPUT
  107. #ifdef WRITE_OUTPUT
  108. ofstream file("adnoteout", ios::out);
  109. #endif
  110. note->noteout(outL, outR);
  111. #ifdef WRITE_OUTPUT
  112. for(int i = 0; i < synth->buffersize; ++i)
  113. file << outL[i] << std::endl;
  114. #endif
  115. sampleCount += synth->buffersize;
  116. TS_ASSERT_DELTA(outL[255], 0.254609f, 0.0001f);
  117. note->relasekey();
  118. note->noteout(outL, outR);
  119. sampleCount += synth->buffersize;
  120. TS_ASSERT_DELTA(outL[255], -0.102197f, 0.0001f);
  121. note->noteout(outL, outR);
  122. sampleCount += synth->buffersize;
  123. TS_ASSERT_DELTA(outL[255], -0.111422f, 0.0001f);
  124. note->noteout(outL, outR);
  125. sampleCount += synth->buffersize;
  126. TS_ASSERT_DELTA(outL[255], -0.021375f, 0.0001f);
  127. note->noteout(outL, outR);
  128. sampleCount += synth->buffersize;
  129. TS_ASSERT_DELTA(outL[255], 0.149882f, 0.0001f);
  130. while(!note->finished()) {
  131. note->noteout(outL, outR);
  132. #ifdef WRITE_OUTPUT
  133. for(int i = 0; i < synth->buffersize; ++i)
  134. file << outL[i] << std::endl;
  135. #endif
  136. sampleCount += synth->buffersize;
  137. }
  138. #ifdef WRITE_OUTPUT
  139. file.close();
  140. #endif
  141. TS_ASSERT_EQUALS(sampleCount, 9472);
  142. }
  143. #define OUTPUT_PROFILE
  144. #ifdef OUTPUT_PROFILE
  145. void testSpeed() {
  146. const int samps = 15000;
  147. int t_on = clock(); // timer before calling func
  148. for(int i = 0; i < samps; ++i)
  149. note->noteout(outL, outR);
  150. int t_off = clock(); // timer when func returns
  151. printf("AdNoteTest: %f seconds for %d Samples to be generated.\n",
  152. (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
  153. }
  154. #endif
  155. };