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.

OscilGenTest.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. AdNoteTest.h - CxxTest for Synth/OscilGen
  4. Copyright (C) 20011-2012 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. #include <cxxtest/TestSuite.h>
  18. #include <string>
  19. #include "../Synth/OscilGen.h"
  20. #include "../globals.h"
  21. SYNTH_T *synth;
  22. using namespace std;
  23. class OscilGenTest:public CxxTest::TestSuite
  24. {
  25. public:
  26. float freq;
  27. float *outR, *outL;
  28. FFTwrapper *fft;
  29. OscilGen *oscil;
  30. void setUp() {
  31. synth = new SYNTH_T;
  32. //First the sensible settings and variables that have to be set:
  33. synth->buffersize = 256;
  34. synth->oscilsize = 1024;
  35. outL = new float[synth->oscilsize];
  36. outR = new float[synth->oscilsize];
  37. memset(outL, 0, sizeof(float) * synth->oscilsize);
  38. memset(outR, 0, sizeof(float) * synth->oscilsize);
  39. //next the bad global variables that for some reason have not been properly placed in some
  40. //initialization routine, but rather exist as cryptic oneliners in main.cpp:
  41. denormalkillbuf = new float[synth->buffersize];
  42. for(int i = 0; i < synth->buffersize; ++i)
  43. denormalkillbuf[i] = 0;
  44. //prepare the default settings
  45. fft = new FFTwrapper(synth->oscilsize);
  46. oscil = new OscilGen(fft, NULL);
  47. //Assert defaults [TODO]
  48. XMLwrapper *wrap = new XMLwrapper();
  49. wrap->loadXMLfile(string(SOURCE_DIR)
  50. + string("/guitar-adnote.xmz"));
  51. TS_ASSERT(wrap->enterbranch("MASTER"));
  52. TS_ASSERT(wrap->enterbranch("PART", 0));
  53. TS_ASSERT(wrap->enterbranch("INSTRUMENT"));
  54. TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT"));
  55. TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT_ITEM", 0));
  56. TS_ASSERT(wrap->enterbranch("ADD_SYNTH_PARAMETERS"));
  57. TS_ASSERT(wrap->enterbranch("VOICE", 0));
  58. TS_ASSERT(wrap->enterbranch("OSCIL"));
  59. oscil->getfromXML(wrap);
  60. delete wrap;
  61. //verify xml was loaded [TODO]
  62. //lets go with.... 50! as a nice note
  63. const char testnote = 50;
  64. freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
  65. }
  66. void tearDown() {
  67. delete oscil;
  68. delete fft;
  69. delete[] outL;
  70. delete[] outR;
  71. delete[] denormalkillbuf;
  72. FFT_cleanup();
  73. delete synth;
  74. }
  75. //verifies that initialization occurs
  76. void testInit(void)
  77. {
  78. oscil->get(outL, freq);
  79. }
  80. void testOutput(void)
  81. {
  82. oscil->get(outL, freq);
  83. TS_ASSERT_DELTA(outL[23], -0.044547f, 0.0001f);
  84. TS_ASSERT_DELTA(outL[129], -0.018169f, 0.0001f);
  85. TS_ASSERT_DELTA(outL[586], 0.045647f, 0.0001f);
  86. TS_ASSERT_DELTA(outL[1023], -0.038334f, 0.0001f);
  87. }
  88. void testSpectrum(void)
  89. {
  90. oscil->getspectrum(synth->oscilsize / 2, outR, 1);
  91. TS_ASSERT_DELTA(outR[0], 350.698059f, 0.0001f);
  92. TS_ASSERT_DELTA(outR[1], 228.889267f, 0.0001f);
  93. TS_ASSERT_DELTA(outR[2], 62.187931f, 0.0001f);
  94. TS_ASSERT_DELTA(outR[3], 22.295225f, 0.0001f);
  95. TS_ASSERT_DELTA(outR[4], 6.942001f, 0.0001f);
  96. TS_ASSERT_DELTA(outR[26], 0.015110f, 0.0001f);
  97. TS_ASSERT_DELTA(outR[47], 0.003425f, 0.0001f);
  98. TS_ASSERT_DELTA(outR[65], 0.001293f, 0.0001f);
  99. }
  100. //performance testing
  101. void testSpeed() {
  102. const int samps = 15000;
  103. int t_on = clock(); // timer before calling func
  104. for(int i = 0; i < samps; ++i)
  105. oscil->prepare();
  106. int t_off = clock(); // timer when func returns
  107. printf("OscilGenTest: %f seconds for %d prepares.\n",
  108. (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
  109. t_on = clock(); // timer before calling func
  110. for(int i = 0; i < samps; ++i)
  111. oscil->get(outL, freq);
  112. t_off = clock(); // timer when func returns
  113. printf("OscilGenTest: %f seconds for %d gets.\n",
  114. (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
  115. }
  116. };