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.

109 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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. /**
  18. Processor wrapper around juce::Reverb for easy integration into ProcessorChain.
  19. @tags{DSP}
  20. */
  21. class Reverb
  22. {
  23. public:
  24. //==============================================================================
  25. /** Creates an uninitialised Reverb processor. Call prepare() before first use. */
  26. Reverb() = default;
  27. //==============================================================================
  28. using Parameters = juce::Reverb::Parameters;
  29. /** Returns the reverb's current parameters. */
  30. const Parameters& getParameters() const noexcept { return reverb.getParameters(); }
  31. /** Applies a new set of parameters to the reverb.
  32. Note that this doesn't attempt to lock the reverb, so if you call this in parallel with
  33. the process method, you may get artifacts.
  34. */
  35. void setParameters (const Parameters& newParams) { reverb.setParameters (newParams); }
  36. /** Returns true if the reverb is enabled. */
  37. bool isEnabled() const noexcept { return enabled; }
  38. /** Enables/disables the reverb. */
  39. void setEnabled (bool newValue) noexcept { enabled = newValue; }
  40. //==============================================================================
  41. /** Initialises the reverb. */
  42. void prepare (const ProcessSpec& spec)
  43. {
  44. reverb.setSampleRate (spec.sampleRate);
  45. }
  46. /** Resets the reverb's internal state. */
  47. void reset() noexcept
  48. {
  49. reverb.reset();
  50. }
  51. //==============================================================================
  52. /** Applies the reverb to a mono or stereo buffer. */
  53. template <typename ProcessContext>
  54. void process (const ProcessContext& context) noexcept
  55. {
  56. const auto& inputBlock = context.getInputBlock();
  57. auto& outputBlock = context.getOutputBlock();
  58. const auto numInChannels = inputBlock.getNumChannels();
  59. const auto numOutChannels = outputBlock.getNumChannels();
  60. const auto numSamples = outputBlock.getNumSamples();
  61. jassert (inputBlock.getNumSamples() == numSamples);
  62. outputBlock.copyFrom (inputBlock);
  63. if (! enabled || context.isBypassed)
  64. return;
  65. if (numInChannels == 1 && numOutChannels == 1)
  66. {
  67. reverb.processMono (outputBlock.getChannelPointer (0), (int) numSamples);
  68. }
  69. else if (numInChannels == 2 && numOutChannels == 2)
  70. {
  71. reverb.processStereo (outputBlock.getChannelPointer (0),
  72. outputBlock.getChannelPointer (1),
  73. (int) numSamples);
  74. }
  75. else
  76. {
  77. jassertfalse; // invalid channel configuration
  78. }
  79. }
  80. private:
  81. //==============================================================================
  82. juce::Reverb reverb;
  83. bool enabled = true;
  84. };
  85. } // namespace dsp
  86. } // namespace juce