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.

171 lines
6.5KB

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