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.

178 lines
6.7KB

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