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.

127 lines
4.3KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. EchoTest.h - CxxTest for Effect/Echo
  4. Copyright (C) 2009-2011 Mark McCurry
  5. Copyright (C) 2009 Harald Hvaal
  6. Authors: Mark McCurry, Harald Hvaal
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of version 2 of the GNU General Public License
  9. as published by the Free Software Foundation.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License (version 2 or later) for more details.
  14. You should have received a copy of the GNU General Public License (version 2)
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <cxxtest/TestSuite.h>
  19. #include <cmath>
  20. #include <cstdlib>
  21. #include <iostream>
  22. #include "../Effects/Echo.h"
  23. #include "../globals.h"
  24. SYNTH_T *synth;
  25. using namespace std;
  26. class EchoTest:public CxxTest::TestSuite
  27. {
  28. public:
  29. void setUp() {
  30. synth = new SYNTH_T;
  31. outL = new float[synth->buffersize];
  32. for(int i = 0; i < synth->buffersize; ++i)
  33. outL[i] = 0.0f;
  34. outR = new float[synth->buffersize];
  35. for(int i = 0; i < synth->buffersize; ++i)
  36. outR[i] = 0.0f;
  37. input = new Stereo<float *>(new float[synth->buffersize],
  38. new float[synth->buffersize]);
  39. for(int i = 0; i < synth->buffersize; ++i)
  40. input->l[i] = input->r[i] = 0.0f;
  41. testFX = new Echo(true, outL, outR);
  42. }
  43. void tearDown() {
  44. delete[] input->r;
  45. delete[] input->l;
  46. delete input;
  47. delete[] outL;
  48. delete[] outR;
  49. delete testFX;
  50. delete synth;
  51. }
  52. void testInit() {
  53. //Make sure that the output will be zero at start
  54. //(given a zero input)
  55. testFX->out(*input);
  56. for(int i = 0; i < synth->buffersize; ++i) {
  57. TS_ASSERT_DELTA(outL[i], 0.0f, 0.0001f);
  58. TS_ASSERT_DELTA(outR[i], 0.0f, 0.0001f);
  59. }
  60. }
  61. void testClear() {
  62. char DELAY = 2;
  63. testFX->changepar(DELAY, 127);
  64. //flood with high input
  65. for(int i = 0; i < synth->buffersize; ++i)
  66. input->r[i] = input->l[i] = 1.0f;
  67. for(int i = 0; i < 500; ++i)
  68. testFX->out(*input);
  69. for(int i = 0; i < synth->buffersize; ++i) {
  70. TS_ASSERT_DIFFERS(outL[i], 0.0f);
  71. TS_ASSERT_DIFFERS(outR[i], 0.0f)
  72. }
  73. //After making sure the internal buffer has a nonzero value
  74. //cleanup
  75. //Then get the next output, which should be zereoed out if DELAY
  76. //is large enough
  77. testFX->cleanup();
  78. testFX->out(*input);
  79. for(int i = 0; i < synth->buffersize; ++i) {
  80. TS_ASSERT_DELTA(outL[i], 0.0f, 0.0001f);
  81. TS_ASSERT_DELTA(outR[i], 0.0f, 0.0001f);
  82. }
  83. }
  84. //Insures that the proper decay occurs with high feedback
  85. void testDecaywFb() {
  86. //flood with high input
  87. for(int i = 0; i < synth->buffersize; ++i)
  88. input->r[i] = input->l[i] = 1.0f;
  89. char FEEDBACK = 5;
  90. testFX->changepar(FEEDBACK, 127);
  91. for(int i = 0; i < 100; ++i)
  92. testFX->out(*input);
  93. for(int i = 0; i < synth->buffersize; ++i) {
  94. TS_ASSERT_DIFFERS(outL[i], 0.0f);
  95. TS_ASSERT_DIFFERS(outR[i], 0.0f)
  96. }
  97. float amp = abs(outL[0] + outR[0]) / 2;
  98. //reset input to zero
  99. for(int i = 0; i < synth->buffersize; ++i)
  100. input->r[i] = input->l[i] = 0.0f;
  101. //give the echo time to fade based upon zero input and high feedback
  102. for(int i = 0; i < 50; ++i)
  103. testFX->out(*input);
  104. TS_ASSERT_LESS_THAN_EQUALS(abs(outL[0] + outR[0]) / 2, amp);
  105. }
  106. private:
  107. Stereo<float *> *input;
  108. float *outR, *outL;
  109. Echo *testFX;
  110. };