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.

162 lines
4.9KB

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