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.

PluginTest.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. PluginTest.h - CxxTest for embedding zyn
  4. Copyright (C) 2013-2013 Mark McCurry
  5. Authors: Mark McCurry
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include <cxxtest/TestSuite.h>
  18. #include <cmath>
  19. #include <cstdlib>
  20. #include <iostream>
  21. #include <fstream>
  22. #include <string>
  23. #include "../Misc/Master.h"
  24. #include "../Misc/Util.h"
  25. #include "../globals.h"
  26. SYNTH_T *synth;
  27. using namespace std;
  28. char *instance_name=(char*)"";
  29. class PluginTest:public CxxTest::TestSuite
  30. {
  31. public:
  32. void setUp() {
  33. synth = new SYNTH_T;
  34. synth->buffersize = 256;
  35. synth->samplerate = 48000;
  36. synth->alias();
  37. outL = new float[1024];
  38. for(int i = 0; i < synth->buffersize; ++i)
  39. outL[i] = 0.0f;
  40. outR = new float[1024];
  41. for(int i = 0; i < synth->buffersize; ++i)
  42. outR[i] = 0.0f;
  43. //next the bad global variables that for some reason have not been properly placed in some
  44. //initialization routine, but rather exist as cryptic oneliners in main.cpp:
  45. denormalkillbuf = new float[synth->buffersize];
  46. for(int i = 0; i < synth->buffersize; ++i)
  47. denormalkillbuf[i] = 0;
  48. for(int i = 0; i < 16; ++i)
  49. master[i] = new Master();
  50. }
  51. void tearDown() {
  52. for(int i = 0; i < 16; ++i)
  53. delete master[i];
  54. delete[] outL;
  55. delete[] outR;
  56. delete synth;
  57. }
  58. void testInit() {
  59. for(int x=0; x<100; ++x)
  60. for(int i=0; i<16; ++i)
  61. master[i]->GetAudioOutSamples(rand()%1025,
  62. synth->samplerate, outL, outR);
  63. }
  64. void testPanic()
  65. {
  66. master[0]->setController(0, 0x64, 0);
  67. master[0]->noteOn(0,64,64);
  68. master[0]->AudioOut(outL, outR);
  69. float sum = 0.0f;
  70. for(int i = 0; i < synth->buffersize; ++i)
  71. sum += fabs(outL[i]);
  72. TS_ASSERT_LESS_THAN(0.1f, sum);
  73. }
  74. string loadfile(string fname) const
  75. {
  76. std::ifstream t(fname.c_str());
  77. std::string str((std::istreambuf_iterator<char>(t)),
  78. std::istreambuf_iterator<char>());
  79. return str;
  80. }
  81. void testLoadSave(void)
  82. {
  83. const string fname = string(SOURCE_DIR) + "/guitar-adnote.xmz";
  84. const string fdata = string("\n") + loadfile(fname);
  85. char *result = NULL;
  86. master[0]->putalldata((char*)fdata.c_str(), fdata.length());
  87. int res = master[0]->getalldata(&result);
  88. TS_ASSERT_EQUALS(fdata.length()+1, res);
  89. TS_ASSERT(fdata == result);
  90. }
  91. private:
  92. float *outR, *outL;
  93. Master *master[16];
  94. };