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.

SubNoteTest.h 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. AdNoteTest.h - CxxTest for Synth/SUBnote
  4. Copyright (C) 2009-2011 Mark McCurry
  5. Author: Mark McCurry
  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
  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/SUBnote.h"
  26. #include "../Params/Presets.h"
  27. #include "../globals.h"
  28. SYNTH_T *synth;
  29. using namespace std;
  30. class SubNoteTest:public CxxTest::TestSuite
  31. {
  32. public:
  33. SUBnote *note;
  34. Master *master;
  35. Controller *controller;
  36. unsigned char testnote;
  37. float *outR, *outL;
  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. outL = new float[synth->buffersize];
  43. for(int i = 0; i < synth->buffersize; ++i)
  44. *(outL + i) = 0;
  45. outR = new float[synth->buffersize];
  46. for(int i = 0; i < synth->buffersize; ++i)
  47. *(outR + i) = 0;
  48. //next the bad global variables that for some reason have not been properly placed in some
  49. //initialization routine, but rather exist as cryptic oneliners in main.cpp:
  50. denormalkillbuf = new float[synth->buffersize];
  51. for(int i = 0; i < synth->buffersize; ++i)
  52. denormalkillbuf[i] = 0;
  53. //prepare the default settings
  54. SUBnoteParameters *defaultPreset = new SUBnoteParameters();
  55. XMLwrapper *wrap = new XMLwrapper();
  56. wrap->loadXMLfile(string(SOURCE_DIR)
  57. + string("/guitar-adnote.xmz"));
  58. TS_ASSERT(wrap->enterbranch("MASTER"));
  59. TS_ASSERT(wrap->enterbranch("PART", 1));
  60. TS_ASSERT(wrap->enterbranch("INSTRUMENT"));
  61. TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT"));
  62. TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT_ITEM", 0));
  63. TS_ASSERT(wrap->enterbranch("SUB_SYNTH_PARAMETERS"));
  64. defaultPreset->getfromXML(wrap);
  65. controller = new Controller();
  66. //lets go with.... 50! as a nice note
  67. testnote = 50;
  68. float freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
  69. note = new SUBnote(defaultPreset,
  70. controller,
  71. freq,
  72. 120,
  73. 0,
  74. testnote,
  75. false);
  76. delete wrap;
  77. delete defaultPreset;
  78. }
  79. void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh()
  80. {
  81. master = new Master();
  82. }
  83. void tearDown() {
  84. delete controller;
  85. delete note;
  86. delete [] outL;
  87. delete [] outR;
  88. delete [] denormalkillbuf;
  89. clearTmpBuffers();
  90. delete synth;
  91. }
  92. void testDefaults() {
  93. //Note: if these tests fail it is due to the relationship between
  94. //global.h::RND and SUBnote.cpp
  95. int sampleCount = 0;
  96. //#define WRITE_OUTPUT
  97. #ifdef WRITE_OUTPUT
  98. ofstream file("subnoteout", ios::out);
  99. #endif
  100. note->noteout(outL, outR);
  101. #ifdef WRITE_OUTPUT
  102. for(int i = 0; i < synth->buffersize; ++i)
  103. file << outL[i] << std::endl;
  104. #endif
  105. sampleCount += synth->buffersize;
  106. TS_ASSERT_DELTA(outL[255], 0.0000f, 0.0001f);
  107. note->relasekey();
  108. note->noteout(outL, outR);
  109. sampleCount += synth->buffersize;
  110. TS_ASSERT_DELTA(outL[255], 0.0016f, 0.0001f);
  111. note->noteout(outL, outR);
  112. sampleCount += synth->buffersize;
  113. TS_ASSERT_DELTA(outL[255], -0.0000f, 0.0001f);
  114. note->noteout(outL, outR);
  115. sampleCount += synth->buffersize;
  116. TS_ASSERT_DELTA(outL[255], -0.0013f, 0.0001f);
  117. note->noteout(outL, outR);
  118. sampleCount += synth->buffersize;
  119. TS_ASSERT_DELTA(outL[255], -0.0002f, 0.0001f);
  120. while(!note->finished()) {
  121. note->noteout(outL, outR);
  122. #ifdef WRITE_OUTPUT
  123. for(int i = 0; i < synth->buffersize; ++i)
  124. file << outL[i] << std::endl;
  125. #endif
  126. sampleCount += synth->buffersize;
  127. }
  128. #ifdef WRITE_OUTPUT
  129. file.close();
  130. #endif
  131. TS_ASSERT_EQUALS(sampleCount, 2304);
  132. }
  133. #define OUTPUT_PROFILE
  134. #ifdef OUTPUT_PROFILE
  135. void testSpeed() {
  136. const int samps = 15000;
  137. int t_on = clock(); // timer before calling func
  138. for(int i = 0; i < samps; ++i)
  139. note->noteout(outL, outR);
  140. int t_off = clock(); // timer when func returns
  141. printf("SubNoteTest: %f seconds for %d Samples to be generated.\n",
  142. (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
  143. }
  144. #endif
  145. };