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.

187 lines
7.0KB

  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. This structure is passed into a DSP algorithm's prepare() method, and contains
  24. information about various aspects of the context in which it can expect to be called.
  25. @tags{DSP}
  26. */
  27. struct ProcessSpec
  28. {
  29. /** The sample rate that will be used for the data that is sent to the processor. */
  30. double sampleRate;
  31. /** The maximum number of samples that will be in the blocks sent to process() method. */
  32. uint32 maximumBlockSize;
  33. /** The number of channels that the process() method will be expected to handle. */
  34. uint32 numChannels;
  35. };
  36. constexpr bool operator== (const ProcessSpec& a, const ProcessSpec& b)
  37. {
  38. return a.sampleRate == b.sampleRate
  39. && a.maximumBlockSize == b.maximumBlockSize
  40. && a.numChannels == b.numChannels;
  41. }
  42. constexpr bool operator!= (const ProcessSpec& a, const ProcessSpec& b) { return ! (a == b); }
  43. //==============================================================================
  44. /**
  45. This is a handy base class for the state of a processor (such as parameter values)
  46. which is typically shared among several processors. This is useful for multi-mono
  47. filters which share the same state among several mono processors.
  48. @tags{DSP}
  49. */
  50. struct ProcessorState : public ReferenceCountedObject
  51. {
  52. /** The ProcessorState structure is ref-counted, so this is a handy type that can be used
  53. as a pointer to one.
  54. */
  55. using Ptr = ReferenceCountedObjectPtr<ProcessorState>;
  56. };
  57. //==============================================================================
  58. /**
  59. Contains context information that is passed into an algorithm's process method.
  60. This context is intended for use in situations where a single block is being used
  61. for both the input and output, so it will return the same object for both its
  62. getInputBlock() and getOutputBlock() methods.
  63. @see ProcessContextNonReplacing
  64. @tags{DSP}
  65. */
  66. template <typename ContextSampleType>
  67. struct ProcessContextReplacing
  68. {
  69. public:
  70. /** The type of a single sample (which may be a vector if multichannel). */
  71. using SampleType = ContextSampleType;
  72. /** The type of audio block that this context handles. */
  73. using AudioBlockType = AudioBlock<SampleType>;
  74. using ConstAudioBlockType = AudioBlock<const SampleType>;
  75. /** Creates a ProcessContextReplacing that uses the given audio block.
  76. Note that the caller must not delete the block while it is still in use by this object!
  77. */
  78. ProcessContextReplacing (AudioBlockType& block) noexcept : ioBlock (block) {}
  79. ProcessContextReplacing (const ProcessContextReplacing&) = default;
  80. ProcessContextReplacing (ProcessContextReplacing&&) = default;
  81. /** Returns the audio block to use as the input to a process function. */
  82. const ConstAudioBlockType& getInputBlock() const noexcept { return constBlock; }
  83. /** Returns the audio block to use as the output to a process function. */
  84. AudioBlockType& getOutputBlock() const noexcept { return ioBlock; }
  85. /** All process context classes will define this constant method so that templated
  86. code can determine whether the input and output blocks refer to the same buffer,
  87. or to two different ones.
  88. */
  89. static constexpr bool usesSeparateInputAndOutputBlocks() { return false; }
  90. /** If set to true, then a processor's process() method is expected to do whatever
  91. is appropriate for it to be in a bypassed state.
  92. */
  93. bool isBypassed = false;
  94. private:
  95. AudioBlockType& ioBlock;
  96. ConstAudioBlockType constBlock { ioBlock };
  97. };
  98. //==============================================================================
  99. /**
  100. Contains context information that is passed into an algorithm's process method.
  101. This context is intended for use in situations where two different blocks are being
  102. used the input and output to the process algorithm, so the processor must read from
  103. the block returned by getInputBlock() and write its results to the block returned by
  104. getOutputBlock().
  105. @see ProcessContextReplacing
  106. @tags{DSP}
  107. */
  108. template <typename ContextSampleType>
  109. struct ProcessContextNonReplacing
  110. {
  111. public:
  112. /** The type of a single sample (which may be a vector if multichannel). */
  113. using SampleType = ContextSampleType;
  114. /** The type of audio block that this context handles. */
  115. using AudioBlockType = AudioBlock<SampleType>;
  116. using ConstAudioBlockType = AudioBlock<const SampleType>;
  117. /** Creates a ProcessContextNonReplacing that uses the given input and output blocks.
  118. Note that the caller must not delete these blocks while they are still in use by this object!
  119. */
  120. ProcessContextNonReplacing (const ConstAudioBlockType& input, AudioBlockType& output) noexcept
  121. : inputBlock (input), outputBlock (output)
  122. {
  123. // If the input and output blocks are the same then you should use
  124. // ProcessContextReplacing instead.
  125. jassert (input != output);
  126. }
  127. ProcessContextNonReplacing (const ProcessContextNonReplacing&) = default;
  128. ProcessContextNonReplacing (ProcessContextNonReplacing&&) = default;
  129. /** Returns the audio block to use as the input to a process function. */
  130. const ConstAudioBlockType& getInputBlock() const noexcept { return inputBlock; }
  131. /** Returns the audio block to use as the output to a process function. */
  132. AudioBlockType& getOutputBlock() const noexcept { return outputBlock; }
  133. /** All process context classes will define this constant method so that templated
  134. code can determine whether the input and output blocks refer to the same buffer,
  135. or to two different ones.
  136. */
  137. static constexpr bool usesSeparateInputAndOutputBlocks() { return true; }
  138. /** If set to true, then a processor's process() method is expected to do whatever
  139. is appropriate for it to be in a bypassed state.
  140. */
  141. bool isBypassed = false;
  142. private:
  143. ConstAudioBlockType inputBlock;
  144. AudioBlockType& outputBlock;
  145. };
  146. } // namespace dsp
  147. } // namespace juce