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.

129 lines
3.8KB

  1. #include "standalone_helpers.hpp"
  2. #include "../src/Glissinator.hpp"
  3. #include <iostream>
  4. int main( int argch, char **argv )
  5. {
  6. std::cout << "Test Glissinator\n";
  7. typedef Glissinator< StandaloneModule > G;
  8. for( int io = 0; io <= 1; ++io )
  9. {
  10. G g;
  11. g.params[ G::GLISS_TIME ].value = 0.1;
  12. g.inputs[ G::SOURCE_INPUT ].value = 1.00 + io;
  13. g.inputs[ G::SOURCE_INPUT ].active = true;
  14. g.outputs[ G::SLID_OUTPUT ].active = true;
  15. G::results_t ov;
  16. g.multiStep( 100, ov );
  17. g.inputs[ G::SOURCE_INPUT ].value = 2.00 - io;
  18. g.multiStep( engineGetSampleRate() * 0.15, ov );
  19. // So this should be monotonically increasing.
  20. auto hd = ov.begin() + 1, pv = ov.begin();
  21. while( hd != ov.end() )
  22. {
  23. if( io == 0 )
  24. assert( (*hd)[ G::SLID_OUTPUT ].value >= (*pv)[ G::SLID_OUTPUT ].value );
  25. else
  26. assert( (*hd)[ G::SLID_OUTPUT ].value <= (*pv)[ G::SLID_OUTPUT ].value );
  27. assert( (*hd)[ G::SLID_OUTPUT ].value >= 1 );
  28. assert( (*hd)[ G::SLID_OUTPUT ].value <= 2 );
  29. ++hd;
  30. ++pv;
  31. }
  32. std::cout << "PASSED: Simple case is monotonic " << 1 + io << " -> " << 2 - io << "\n";
  33. }
  34. // The turnadound-half-way-through test
  35. for( int io = 0; io <= 1; ++io )
  36. {
  37. G g;
  38. g.params[ G::GLISS_TIME ].value = 0.1;
  39. g.inputs[ G::SOURCE_INPUT ].value = 1.00 + io;
  40. g.inputs[ G::SOURCE_INPUT ].active = true;
  41. g.outputs[ G::SLID_OUTPUT ].active = true;
  42. G::results_t ov;
  43. g.multiStep( 100, ov );
  44. g.inputs[ G::SOURCE_INPUT ].value = 2.00 - io;
  45. g.multiStep( engineGetSampleRate() * 0.07, ov );
  46. float maxO = g.outputs[ G::SLID_OUTPUT ].value;
  47. g.inputs[ G::SOURCE_INPUT ].value = 1.00 + io;
  48. g.multiStep( engineGetSampleRate() * 0.07, ov );
  49. // So this should no longer be monotonic strictly but should monotone up to max
  50. // and then down from
  51. bool goingUp = (io == 0)?true:false;
  52. bool hitMax = false;
  53. auto hd = ov.begin() + 1, pv = ov.begin();
  54. while( hd != ov.end() )
  55. {
  56. if( goingUp )
  57. assert( (*hd)[ G::SLID_OUTPUT ].value >= (*pv)[ G::SLID_OUTPUT ].value );
  58. else
  59. assert( (*hd)[ G::SLID_OUTPUT ].value <= (*pv)[ G::SLID_OUTPUT ].value );
  60. if( io == 0 )
  61. {
  62. assert( (*hd)[ G::SLID_OUTPUT ].value >= 1 );
  63. assert( (*hd)[ G::SLID_OUTPUT ].value <= maxO );
  64. }
  65. else
  66. {
  67. assert( (*hd)[ G::SLID_OUTPUT ].value <= 2 );
  68. assert( (*hd)[ G::SLID_OUTPUT ].value >= maxO );
  69. }
  70. if( (*hd)[G::SLID_OUTPUT].value == maxO && ! hitMax ) { goingUp = ! goingUp; hitMax = true; } // max can repeat
  71. ++hd;
  72. ++pv;
  73. }
  74. std::cout << "PASSED: Turnaround case is bi-monotonic " << 1 + io << " -> " << 2 - io << "\n";
  75. }
  76. {
  77. G g;
  78. // OK so now lets test that gliss time bug. If we reset the gliss time most of the way through
  79. // a gliss, the 0.6.1 version runs away.
  80. g.params[ G::GLISS_TIME ].value = 0.1;
  81. g.inputs[ G::SOURCE_INPUT ].value = 1.00;
  82. g.inputs[ G::SOURCE_INPUT ].active = true;
  83. g.outputs[ G::SLID_OUTPUT ].active = true;
  84. G::results_t ov;
  85. g.multiStep( 100, ov );
  86. g.inputs[ G::SOURCE_INPUT ].value = 2.00 ;
  87. g.multiStep( engineGetSampleRate() * 0.07, ov );
  88. g.params[ G::GLISS_TIME ].value = 0;
  89. g.multiStep( 1, ov );
  90. auto hd = ov.begin() + 1, pv = ov.begin();
  91. while( hd != ov.end() )
  92. {
  93. assert( (*hd)[ G::SLID_OUTPUT ].value >= (*pv)[ G::SLID_OUTPUT ].value );
  94. assert( (*hd)[ G::SLID_OUTPUT ].value >= 1 );
  95. assert( (*hd)[ G::SLID_OUTPUT ].value <= 2 );
  96. ++hd;
  97. ++pv;
  98. }
  99. std::cout << "PASSED: Jump case is still monotonic and bounded\n";
  100. }
  101. }