The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

135 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. namespace dsp
  16. {
  17. class ProcessorChainTest : public UnitTest
  18. {
  19. template <int AddValue>
  20. struct MockProcessor
  21. {
  22. void prepare (const ProcessSpec&) noexcept { isPrepared = true; }
  23. void reset() noexcept { isReset = true; }
  24. template <typename Context>
  25. void process (const Context& context) noexcept
  26. {
  27. bufferWasClear = context.getInputBlock().getSample (0, 0) == 0;
  28. if (! context.isBypassed)
  29. context.getOutputBlock().add (AddValue);
  30. }
  31. bool isPrepared = false;
  32. bool isReset = false;
  33. bool bufferWasClear = false;
  34. };
  35. public:
  36. ProcessorChainTest()
  37. : UnitTest ("ProcessorChain", UnitTestCategories::dsp) {}
  38. void runTest() override
  39. {
  40. beginTest ("After calling setBypass, processor is bypassed");
  41. {
  42. ProcessorChain<MockProcessor<1>, MockProcessor<2>> chain;
  43. setBypassed<0> (chain, true);
  44. expect (isBypassed<0> (chain));
  45. setBypassed<0> (chain, false);
  46. expect (! isBypassed<0> (chain));
  47. setBypassed<1> (chain, true);
  48. expect (isBypassed<1> (chain));
  49. setBypassed<1> (chain, false);
  50. expect (! isBypassed<1> (chain));
  51. }
  52. beginTest ("After calling prepare, all processors are prepared");
  53. {
  54. ProcessorChain<MockProcessor<1>, MockProcessor<2>> chain;
  55. expect (! get<0> (chain).isPrepared);
  56. expect (! get<1> (chain).isPrepared);
  57. chain.prepare (ProcessSpec{});
  58. expect (get<0> (chain).isPrepared);
  59. expect (get<1> (chain).isPrepared);
  60. }
  61. beginTest ("After calling reset, all processors are reset");
  62. {
  63. ProcessorChain<MockProcessor<1>, MockProcessor<2>> chain;
  64. expect (! get<0> (chain).isReset);
  65. expect (! get<1> (chain).isReset);
  66. chain.reset();
  67. expect (get<0> (chain).isReset);
  68. expect (get<1> (chain).isReset);
  69. }
  70. beginTest ("After calling process, all processors contribute to processing");
  71. {
  72. ProcessorChain<MockProcessor<1>, MockProcessor<2>> chain;
  73. AudioBuffer<float> buffer (1, 1);
  74. AudioBlock<float> block (buffer);
  75. ProcessContextReplacing<float> context (block);
  76. block.clear();
  77. chain.process (context);
  78. expectEquals (buffer.getSample (0, 0), 3.0f);
  79. expect (get<0> (chain).bufferWasClear);
  80. expect (! get<1> (chain).bufferWasClear);
  81. setBypassed<0> (chain, true);
  82. block.clear();
  83. chain.process (context);
  84. expectEquals (buffer.getSample (0, 0), 2.0f);
  85. expect (get<0> (chain).bufferWasClear);
  86. expect (get<1> (chain).bufferWasClear);
  87. setBypassed<1> (chain, true);
  88. block.clear();
  89. chain.process (context);
  90. expectEquals (buffer.getSample (0, 0), 0.0f);
  91. expect (get<0> (chain).bufferWasClear);
  92. expect (get<1> (chain).bufferWasClear);
  93. setBypassed<0> (chain, false);
  94. block.clear();
  95. chain.process (context);
  96. expectEquals (buffer.getSample (0, 0), 1.0f);
  97. expect (get<0> (chain).bufferWasClear);
  98. expect (! get<1> (chain).bufferWasClear);
  99. }
  100. }
  101. };
  102. static ProcessorChainTest processorChainUnitTest;
  103. } // namespace dsp
  104. } // namespace juce