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.

90 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. /**
  18. Interpolator for resampling a stream of floats using Catmull-Rom interpolation.
  19. Note that the resampler is stateful, so when there's a break in the continuity
  20. of the input stream you're feeding it, you should call reset() before feeding
  21. it any new data. And like with any other stateful filter, if you're resampling
  22. multiple channels, make sure each one uses its own CatmullRomInterpolator
  23. object.
  24. @see LagrangeInterpolator
  25. */
  26. class JUCE_API CatmullRomInterpolator
  27. {
  28. public:
  29. CatmullRomInterpolator() noexcept;
  30. ~CatmullRomInterpolator() noexcept;
  31. /** Resets the state of the interpolator.
  32. Call this when there's a break in the continuity of the input data stream.
  33. */
  34. void reset() noexcept;
  35. /** Resamples a stream of samples.
  36. @param speedRatio the number of input samples to use for each output sample
  37. @param inputSamples the source data to read from. This must contain at
  38. least (speedRatio * numOutputSamplesToProduce) samples.
  39. @param outputSamples the buffer to write the results into
  40. @param numOutputSamplesToProduce the number of output samples that should be created
  41. @returns the actual number of input samples that were used
  42. */
  43. int process (double speedRatio,
  44. const float* inputSamples,
  45. float* outputSamples,
  46. int numOutputSamplesToProduce) noexcept;
  47. /** Resamples a stream of samples, adding the results to the output data
  48. with a gain.
  49. @param speedRatio the number of input samples to use for each output sample
  50. @param inputSamples the source data to read from. This must contain at
  51. least (speedRatio * numOutputSamplesToProduce) samples.
  52. @param outputSamples the buffer to write the results to - the result values will be added
  53. to any pre-existing data in this buffer after being multiplied by
  54. the gain factor
  55. @param numOutputSamplesToProduce the number of output samples that should be created
  56. @param gain a gain factor to multiply the resulting samples by before
  57. adding them to the destination buffer
  58. @returns the actual number of input samples that were used
  59. */
  60. int processAdding (double speedRatio,
  61. const float* inputSamples,
  62. float* outputSamples,
  63. int numOutputSamplesToProduce,
  64. float gain) noexcept;
  65. private:
  66. float lastInputSamples[5];
  67. double subSamplePos;
  68. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CatmullRomInterpolator)
  69. };