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.

116 lines
3.8KB

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