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.

177 lines
5.3KB

  1. #include <cxxtest/TestSuite.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <ctime>
  5. #include <string>
  6. #include "../Misc/Master.h"
  7. #include "../Misc/Util.h"
  8. #include "../Synth/ADnote.h"
  9. #include "../Params/Presets.h"
  10. #include "../DSP/FFTwrapper.h"
  11. #include "../globals.h"
  12. using namespace std;
  13. SYNTH_T *synth;
  14. class AdNoteTest:public CxxTest::TestSuite
  15. {
  16. public:
  17. ADnote *note;
  18. Master *master;
  19. FFTwrapper *fft;
  20. Controller *controller;
  21. unsigned char testnote;
  22. float *outR, *outL;
  23. void setUp() {
  24. //First the sensible settings and variables that have to be set:
  25. synth = new SYNTH_T;
  26. synth->buffersize = 256;
  27. outL = new float[synth->buffersize];
  28. for(int i = 0; i < synth->buffersize; ++i)
  29. *(outL + i) = 0;
  30. outR = new float[synth->buffersize];
  31. for(int i = 0; i < synth->buffersize; ++i)
  32. *(outR + i) = 0;
  33. //next the bad global variables that for some reason have not been properly placed in some
  34. //initialization routine, but rather exist as cryptic oneliners in main.cpp:
  35. denormalkillbuf = new float[synth->buffersize];
  36. for(int i = 0; i < synth->buffersize; ++i)
  37. denormalkillbuf[i] = 0;
  38. //phew, glad to get thouse out of my way. took me a lot of sweat and gdb to get this far...
  39. fft = new FFTwrapper(synth->oscilsize);
  40. //prepare the default settings
  41. ADnoteParameters *defaultPreset = new ADnoteParameters(fft);
  42. //Assert defaults
  43. TS_ASSERT(!defaultPreset->VoicePar[1].Enabled);
  44. XMLwrapper *wrap = new XMLwrapper();
  45. cout << string(SOURCE_DIR) + string("/guitar-adnote.xmz")
  46. << endl;
  47. wrap->loadXMLfile(string(SOURCE_DIR)
  48. + string("/guitar-adnote.xmz"));
  49. TS_ASSERT(wrap->enterbranch("MASTER"));
  50. TS_ASSERT(wrap->enterbranch("PART", 0));
  51. TS_ASSERT(wrap->enterbranch("INSTRUMENT"));
  52. TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT"));
  53. TS_ASSERT(wrap->enterbranch("INSTRUMENT_KIT_ITEM", 0));
  54. TS_ASSERT(wrap->enterbranch("ADD_SYNTH_PARAMETERS"));
  55. defaultPreset->getfromXML(wrap);
  56. //defaultPreset->defaults();
  57. //verify xml was loaded
  58. TS_ASSERT(defaultPreset->VoicePar[1].Enabled);
  59. controller = new Controller();
  60. //lets go with.... 50! as a nice note
  61. testnote = 50;
  62. float freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f);
  63. note = new ADnote(defaultPreset,
  64. controller,
  65. freq,
  66. 120,
  67. 0,
  68. testnote,
  69. false);
  70. delete defaultPreset;
  71. delete wrap;
  72. }
  73. void willNoteBeRunButIsHereForLinkingReasonsHowsThisForCamelCaseEh()
  74. {
  75. master = new Master();
  76. }
  77. void tearDown() {
  78. delete note;
  79. delete controller;
  80. delete fft;
  81. delete [] outL;
  82. delete [] outR;
  83. delete [] denormalkillbuf;
  84. FFT_cleanup();
  85. delete synth;
  86. }
  87. void testDefaults() {
  88. int sampleCount = 0;
  89. //#define WRITE_OUTPUT
  90. #ifdef WRITE_OUTPUT
  91. ofstream file("adnoteout", ios::out);
  92. #endif
  93. note->noteout(outL, outR);
  94. #ifdef WRITE_OUTPUT
  95. for(int i = 0; i < synth->buffersize; ++i)
  96. file << outL[i] << std::endl;
  97. #endif
  98. sampleCount += synth->buffersize;
  99. TS_ASSERT_DELTA(outL[255], 0.254609f, 0.0001f);
  100. note->relasekey();
  101. note->noteout(outL, outR);
  102. sampleCount += synth->buffersize;
  103. TS_ASSERT_DELTA(outL[255], -0.102197f, 0.0001f);
  104. note->noteout(outL, outR);
  105. sampleCount += synth->buffersize;
  106. TS_ASSERT_DELTA(outL[255], -0.111422f, 0.0001f);
  107. note->noteout(outL, outR);
  108. sampleCount += synth->buffersize;
  109. TS_ASSERT_DELTA(outL[255], -0.021375f, 0.0001f);
  110. note->noteout(outL, outR);
  111. sampleCount += synth->buffersize;
  112. TS_ASSERT_DELTA(outL[255], 0.149882f, 0.0001f);
  113. while(!note->finished()) {
  114. note->noteout(outL, outR);
  115. #ifdef WRITE_OUTPUT
  116. for(int i = 0; i < synth->buffersize; ++i)
  117. file << outL[i] << std::endl;
  118. #endif
  119. sampleCount += synth->buffersize;
  120. }
  121. #ifdef WRITE_OUTPUT
  122. file.close();
  123. #endif
  124. TS_ASSERT_EQUALS(sampleCount, 9472);
  125. }
  126. #define OUTPUT_PROFILE
  127. #ifdef OUTPUT_PROFILE
  128. void testSpeed() {
  129. const int samps = 15000;
  130. int t_on = clock(); // timer before calling func
  131. for(int i = 0; i < samps; ++i)
  132. note->noteout(outL, outR);
  133. int t_off = clock(); // timer when func returns
  134. printf("AdNoteTest: %f seconds for %d Samples to be generated.\n",
  135. (static_cast<float>(t_off - t_on)) / CLOCKS_PER_SEC, samps);
  136. }
  137. #endif
  138. };