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.

87 lines
3.7KB

  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. /**
  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. };