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.

95 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. /**
  24. Interpolator for resampling a stream of floats using Catmull-Rom interpolation.
  25. Note that the resampler is stateful, so when there's a break in the continuity
  26. of the input stream you're feeding it, you should call reset() before feeding
  27. it any new data. And like with any other stateful filter, if you're resampling
  28. multiple channels, make sure each one uses its own CatmullRomInterpolator
  29. object.
  30. @see LagrangeInterpolator
  31. */
  32. class JUCE_API CatmullRomInterpolator
  33. {
  34. public:
  35. CatmullRomInterpolator() noexcept;
  36. ~CatmullRomInterpolator() noexcept;
  37. /** Resets the state of the interpolator.
  38. Call this when there's a break in the continuity of the input data stream.
  39. */
  40. void reset() noexcept;
  41. /** Resamples a stream of samples.
  42. @param speedRatio the number of input samples to use for each output sample
  43. @param inputSamples the source data to read from. This must contain at
  44. least (speedRatio * numOutputSamplesToProduce) samples.
  45. @param outputSamples the buffer to write the results into
  46. @param numOutputSamplesToProduce the number of output samples that should be created
  47. @returns the actual number of input samples that were used
  48. */
  49. int process (double speedRatio,
  50. const float* inputSamples,
  51. float* outputSamples,
  52. int numOutputSamplesToProduce) noexcept;
  53. /** Resamples a stream of samples, adding the results to the output data
  54. with a gain.
  55. @param speedRatio the number of input samples to use for each output sample
  56. @param inputSamples the source data to read from. This must contain at
  57. least (speedRatio * numOutputSamplesToProduce) samples.
  58. @param outputSamples the buffer to write the results to - the result values will be added
  59. to any pre-existing data in this buffer after being multiplied by
  60. the gain factor
  61. @param numOutputSamplesToProduce the number of output samples that should be created
  62. @param gain a gain factor to multiply the resulting samples by before
  63. adding them to the destination buffer
  64. @returns the actual number of input samples that were used
  65. */
  66. int processAdding (double speedRatio,
  67. const float* inputSamples,
  68. float* outputSamples,
  69. int numOutputSamplesToProduce,
  70. float gain) noexcept;
  71. private:
  72. float lastInputSamples[5];
  73. double subSamplePos;
  74. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CatmullRomInterpolator)
  75. };