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.

113 lines
3.4KB

  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. enum class PannerRule
  18. {
  19. linear,
  20. balanced,
  21. sin3dB,
  22. sin4p5dB,
  23. sin6dB,
  24. squareRoot3dB,
  25. squareRoot4p5dB
  26. };
  27. /**
  28. A processor to perform panning operations on stereo buffers.
  29. @tags{DSP}
  30. */
  31. template <typename SampleType>
  32. class Panner
  33. {
  34. public:
  35. //==============================================================================
  36. using Rule = PannerRule;
  37. //==============================================================================
  38. /** Constructor. */
  39. Panner();
  40. //==============================================================================
  41. /** Sets the panning rule. */
  42. void setRule (Rule newRule);
  43. /** Sets the current panning value, between -1 (full left) and 1 (full right). */
  44. void setPan (SampleType newPan);
  45. //==============================================================================
  46. /** Initialises the processor. */
  47. void prepare (const ProcessSpec& spec);
  48. /** Resets the internal state variables of the processor. */
  49. void reset();
  50. //==============================================================================
  51. /** Processes the input and output samples supplied in the processing context. */
  52. template <typename ProcessContext>
  53. void process (const ProcessContext& context) noexcept
  54. {
  55. const auto& inputBlock = context.getInputBlock();
  56. auto& outputBlock = context.getOutputBlock();
  57. const auto numInputChannels = inputBlock.getNumChannels();
  58. const auto numOutputChannels = outputBlock.getNumChannels();
  59. const auto numSamples = outputBlock.getNumSamples();
  60. jassert (inputBlock.getNumSamples() == numSamples);
  61. ignoreUnused (numSamples);
  62. if (numOutputChannels != 2 || numInputChannels == 0 || numInputChannels > 2)
  63. return;
  64. if (numInputChannels == 2)
  65. {
  66. outputBlock.copyFrom (inputBlock);
  67. }
  68. else
  69. {
  70. outputBlock.getSingleChannelBlock (0).copyFrom (inputBlock);
  71. outputBlock.getSingleChannelBlock (1).copyFrom (inputBlock);
  72. }
  73. if (context.isBypassed)
  74. return;
  75. outputBlock.getSingleChannelBlock (0).multiplyBy (leftVolume);
  76. outputBlock.getSingleChannelBlock (1).multiplyBy (rightVolume);
  77. }
  78. private:
  79. //==============================================================================
  80. void update();
  81. //==============================================================================
  82. Rule currentRule = Rule::balanced;
  83. SampleType pan = 0.0;
  84. SmoothedValue<SampleType> leftVolume, rightVolume;
  85. double sampleRate = 44100.0;
  86. };
  87. } // namespace dsp
  88. } // namespace juce