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.

117 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. namespace dsp
  22. {
  23. /**
  24. Processor wrapper around juce::Reverb for easy integration into ProcessorChain.
  25. @tags{DSP}
  26. */
  27. class Reverb
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates an uninitialised Reverb processor. Call prepare() before first use. */
  32. Reverb() = default;
  33. //==============================================================================
  34. using Parameters = juce::Reverb::Parameters;
  35. /** Returns the reverb's current parameters. */
  36. const Parameters& getParameters() const noexcept { return reverb.getParameters(); }
  37. /** Applies a new set of parameters to the reverb.
  38. Note that this doesn't attempt to lock the reverb, so if you call this in parallel with
  39. the process method, you may get artifacts.
  40. */
  41. void setParameters (const Parameters& newParams) { reverb.setParameters (newParams); }
  42. /** Returns true if the reverb is enabled. */
  43. bool isEnabled() const noexcept { return enabled; }
  44. /** Enables/disables the reverb. */
  45. void setEnabled (bool newValue) noexcept { enabled = newValue; }
  46. //==============================================================================
  47. /** Initialises the reverb. */
  48. void prepare (const juce::dsp::ProcessSpec& spec)
  49. {
  50. reverb.setSampleRate (spec.sampleRate);
  51. }
  52. /** Resets the reverb's internal state. */
  53. void reset() noexcept
  54. {
  55. reverb.reset();
  56. }
  57. //==============================================================================
  58. /** Applies the reverb to a mono or stereo buffer. */
  59. template <typename ProcessContext>
  60. void process (const ProcessContext& context) noexcept
  61. {
  62. const auto& inputBlock = context.getInputBlock();
  63. auto& outputBlock = context.getOutputBlock();
  64. const auto numInChannels = inputBlock.getNumChannels();
  65. const auto numOutChannels = outputBlock.getNumChannels();
  66. const auto numSamples = outputBlock.getNumSamples();
  67. jassert (inputBlock.getNumSamples() == numSamples);
  68. outputBlock.copy (inputBlock);
  69. if (! enabled || context.isBypassed)
  70. return;
  71. if (numInChannels == 1 && numOutChannels == 1)
  72. {
  73. reverb.processMono (outputBlock.getChannelPointer (0), (int) numSamples);
  74. }
  75. else if (numInChannels == 2 && numOutChannels == 2)
  76. {
  77. reverb.processStereo (outputBlock.getChannelPointer (0),
  78. outputBlock.getChannelPointer (1),
  79. (int) numSamples);
  80. }
  81. else
  82. {
  83. jassertfalse; // invalid channel configuration
  84. }
  85. }
  86. private:
  87. //==============================================================================
  88. juce::Reverb reverb;
  89. bool enabled = true;
  90. };
  91. } // namespace dsp
  92. } // namespace juce