Collection of tools useful for audio production
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.

121 lines
4.1KB

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