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.

142 lines
6.6KB

  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. namespace juce
  18. {
  19. /**
  20. Interpolator for resampling a stream of floats using 4-point lagrange interpolation.
  21. Note that the resampler is stateful, so when there's a break in the continuity
  22. of the input stream you're feeding it, you should call reset() before feeding
  23. it any new data. And like with any other stateful filter, if you're resampling
  24. multiple channels, make sure each one uses its own LagrangeInterpolator
  25. object.
  26. @see CatmullRomInterpolator
  27. */
  28. class JUCE_API LagrangeInterpolator
  29. {
  30. public:
  31. LagrangeInterpolator() noexcept;
  32. ~LagrangeInterpolator() noexcept;
  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.
  50. @param speedRatio the number of input samples to use for each output sample
  51. @param inputSamples the source data to read from. This must contain at
  52. least (speedRatio * numOutputSamplesToProduce) samples.
  53. @param outputSamples the buffer to write the results into
  54. @param numOutputSamplesToProduce the number of output samples that should be created
  55. @param available the number of available input samples. If it needs more samples
  56. than available, it either wraps back for wrapAround samples, or
  57. it feeds zeroes
  58. @param wrapAround if the stream exceeds available samples, it wraps back for
  59. wrapAround samples. If wrapAround is set to 0, it will feed zeroes.
  60. @returns the actual number of input samples that were used
  61. */
  62. int process (double speedRatio,
  63. const float* inputSamples,
  64. float* outputSamples,
  65. int numOutputSamplesToProduce,
  66. int available,
  67. int wrapAround) noexcept;
  68. /** Resamples a stream of samples, adding the results to the output data
  69. with a gain.
  70. @param speedRatio the number of input samples to use for each output sample
  71. @param inputSamples the source data to read from. This must contain at
  72. least (speedRatio * numOutputSamplesToProduce) samples.
  73. @param outputSamples the buffer to write the results to - the result values will be added
  74. to any pre-existing data in this buffer after being multiplied by
  75. the gain factor
  76. @param numOutputSamplesToProduce the number of output samples that should be created
  77. @param gain a gain factor to multiply the resulting samples by before
  78. adding them to the destination buffer
  79. @returns the actual number of input samples that were used
  80. */
  81. int processAdding (double speedRatio,
  82. const float* inputSamples,
  83. float* outputSamples,
  84. int numOutputSamplesToProduce,
  85. float gain) noexcept;
  86. /** Resamples a stream of samples, adding the results to the output data
  87. with a gain.
  88. @param speedRatio the number of input samples to use for each output sample
  89. @param inputSamples the source data to read from. This must contain at
  90. least (speedRatio * numOutputSamplesToProduce) samples.
  91. @param outputSamples the buffer to write the results to - the result values will be added
  92. to any pre-existing data in this buffer after being multiplied by
  93. the gain factor
  94. @param numOutputSamplesToProduce the number of output samples that should be created
  95. @param available the number of available input samples. If it needs more samples
  96. than available, it either wraps back for wrapAround samples, or
  97. it feeds zeroes
  98. @param wrapAround if the stream exceeds available samples, it wraps back for
  99. wrapAround samples. If wrapAround is set to 0, it will feed zeroes.
  100. @param gain a gain factor to multiply the resulting samples by before
  101. adding them to the destination buffer
  102. @returns the actual number of input samples that were used
  103. */
  104. int processAdding (double speedRatio,
  105. const float* inputSamples,
  106. float* outputSamples,
  107. int numOutputSamplesToProduce,
  108. int available,
  109. int wrapAround,
  110. float gain) noexcept;
  111. private:
  112. float lastInputSamples[5];
  113. double subSamplePos;
  114. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LagrangeInterpolator)
  115. };
  116. } // namespace juce