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.

95 lines
4.1KB

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