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.

147 lines
6.8KB

  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. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. /**
  20. Interpolator for resampling a stream of floats using 4-point lagrange interpolation.
  21. Note that the resampler is stateful, so when there's a break in the continuity
  22. of the input stream you're feeding it, you should call reset() before feeding
  23. it any new data. And like with any other stateful filter, if you're resampling
  24. multiple channels, make sure each one uses its own LagrangeInterpolator
  25. object.
  26. @see CatmullRomInterpolator
  27. @tags{Audio}
  28. */
  29. class JUCE_API LagrangeInterpolator
  30. {
  31. public:
  32. LagrangeInterpolator() noexcept;
  33. ~LagrangeInterpolator() noexcept;
  34. LagrangeInterpolator (LagrangeInterpolator&&) noexcept = default;
  35. LagrangeInterpolator& operator= (LagrangeInterpolator&&) noexcept = default;
  36. /** Resets the state of the interpolator.
  37. Call this when there's a break in the continuity of the input data stream.
  38. */
  39. void reset() noexcept;
  40. /** Resamples a stream of samples.
  41. @param speedRatio the number of input samples to use for each output sample
  42. @param inputSamples the source data to read from. This must contain at
  43. least (speedRatio * numOutputSamplesToProduce) samples.
  44. @param outputSamples the buffer to write the results into
  45. @param numOutputSamplesToProduce the number of output samples that should be created
  46. @returns the actual number of input samples that were used
  47. */
  48. int process (double speedRatio,
  49. const float* inputSamples,
  50. float* outputSamples,
  51. int numOutputSamplesToProduce) noexcept;
  52. /** Resamples a stream of samples.
  53. @param speedRatio the number of input samples to use for each output sample
  54. @param inputSamples the source data to read from. This must contain at
  55. least (speedRatio * numOutputSamplesToProduce) samples.
  56. @param outputSamples the buffer to write the results into
  57. @param numOutputSamplesToProduce the number of output samples that should be created
  58. @param available the number of available input samples. If it needs more samples
  59. than available, it either wraps back for wrapAround samples, or
  60. it feeds zeroes
  61. @param wrapAround if the stream exceeds available samples, it wraps back for
  62. wrapAround samples. If wrapAround is set to 0, it will feed zeroes.
  63. @returns the actual number of input samples that were used
  64. */
  65. int process (double speedRatio,
  66. const float* inputSamples,
  67. float* outputSamples,
  68. int numOutputSamplesToProduce,
  69. int available,
  70. int wrapAround) noexcept;
  71. /** Resamples a stream of samples, adding the results to the output data
  72. with a gain.
  73. @param speedRatio the number of input samples to use for each output sample
  74. @param inputSamples the source data to read from. This must contain at
  75. least (speedRatio * numOutputSamplesToProduce) samples.
  76. @param outputSamples the buffer to write the results to - the result values will be added
  77. to any pre-existing data in this buffer after being multiplied by
  78. the gain factor
  79. @param numOutputSamplesToProduce the number of output samples that should be created
  80. @param gain a gain factor to multiply the resulting samples by before
  81. adding them to the destination buffer
  82. @returns the actual number of input samples that were used
  83. */
  84. int processAdding (double speedRatio,
  85. const float* inputSamples,
  86. float* outputSamples,
  87. int numOutputSamplesToProduce,
  88. float gain) noexcept;
  89. /** Resamples a stream of samples, adding the results to the output data
  90. with a gain.
  91. @param speedRatio the number of input samples to use for each output sample
  92. @param inputSamples the source data to read from. This must contain at
  93. least (speedRatio * numOutputSamplesToProduce) samples.
  94. @param outputSamples the buffer to write the results to - the result values will be added
  95. to any pre-existing data in this buffer after being multiplied by
  96. the gain factor
  97. @param numOutputSamplesToProduce the number of output samples that should be created
  98. @param available the number of available input samples. If it needs more samples
  99. than available, it either wraps back for wrapAround samples, or
  100. it feeds zeroes
  101. @param wrapAround if the stream exceeds available samples, it wraps back for
  102. wrapAround samples. If wrapAround is set to 0, it will feed zeroes.
  103. @param gain a gain factor to multiply the resulting samples by before
  104. adding them to the destination buffer
  105. @returns the actual number of input samples that were used
  106. */
  107. int processAdding (double speedRatio,
  108. const float* inputSamples,
  109. float* outputSamples,
  110. int numOutputSamplesToProduce,
  111. int available,
  112. int wrapAround,
  113. float gain) noexcept;
  114. private:
  115. float lastInputSamples[5];
  116. double subSamplePos;
  117. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LagrangeInterpolator)
  118. };
  119. } // namespace juce