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
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_LAGRANGEINTERPOLATOR_H_INCLUDED
  18. #define JUCE_LAGRANGEINTERPOLATOR_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Interpolator for resampling a stream of floats using 4-point lagrange interpolation.
  22. Note that the resampler is stateful, so when there's a break in the continuity
  23. of the input stream you're feeding it, you should call reset() before feeding
  24. it any new data. And like with any other stateful filter, if you're resampling
  25. multiple channels, make sure each one uses its own LagrangeInterpolator
  26. object.
  27. */
  28. class JUCE_API LagrangeInterpolator
  29. {
  30. public:
  31. LagrangeInterpolator();
  32. ~LagrangeInterpolator();
  33. /** Resets the state of the interpolator.
  34. Call this when there's a break in the continuity of the input data stream.
  35. */
  36. void reset() noexcept;
  37. /** Resamples a stream of samples.
  38. @param speedRatio the number of input samples to use for each output sample
  39. @param inputSamples the source data to read from. This must contain at
  40. least (speedRatio * numOutputSamplesToProduce) samples.
  41. @param outputSamples the buffer to write the results into
  42. @param numOutputSamplesToProduce the number of output samples that should be created
  43. @returns the actual number of input samples that were used
  44. */
  45. int process (double speedRatio,
  46. const float* inputSamples,
  47. float* outputSamples,
  48. int numOutputSamplesToProduce) noexcept;
  49. /** Resamples a stream of samples, adding the results to the output data
  50. with a gain.
  51. @param speedRatio the number of input samples to use for each output sample
  52. @param inputSamples the source data to read from. This must contain at
  53. least (speedRatio * numOutputSamplesToProduce) samples.
  54. @param outputSamples the buffer to write the results to - the result values will be added
  55. to any pre-existing data in this buffer after being multiplied by
  56. the gain factor
  57. @param numOutputSamplesToProduce the number of output samples that should be created
  58. @param gain a gain factor to multiply the resulting samples by before
  59. adding them to the destination buffer
  60. @returns the actual number of input samples that were used
  61. */
  62. int processAdding (double speedRatio,
  63. const float* inputSamples,
  64. float* outputSamples,
  65. int numOutputSamplesToProduce,
  66. float gain) noexcept;
  67. private:
  68. float lastInputSamples[5];
  69. double subSamplePos;
  70. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LagrangeInterpolator)
  71. };
  72. #endif // JUCE_LAGRANGEINTERPOLATOR_H_INCLUDED