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.

144 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. @tags{Audio}
  28. */
  29. class JUCE_API LagrangeInterpolator
  30. {
  31. public:
  32. LagrangeInterpolator() noexcept;
  33. ~LagrangeInterpolator() noexcept;
  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.
  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 into
  55. @param numOutputSamplesToProduce the number of output samples that should be created
  56. @param available the number of available input samples. If it needs more samples
  57. than available, it either wraps back for wrapAround samples, or
  58. it feeds zeroes
  59. @param wrapAround if the stream exceeds available samples, it wraps back for
  60. wrapAround samples. If wrapAround is set to 0, it will feed zeroes.
  61. @returns the actual number of input samples that were used
  62. */
  63. int process (double speedRatio,
  64. const float* inputSamples,
  65. float* outputSamples,
  66. int numOutputSamplesToProduce,
  67. int available,
  68. int wrapAround) noexcept;
  69. /** Resamples a stream of samples, adding the results to the output data
  70. with a gain.
  71. @param speedRatio the number of input samples to use for each output sample
  72. @param inputSamples the source data to read from. This must contain at
  73. least (speedRatio * numOutputSamplesToProduce) samples.
  74. @param outputSamples the buffer to write the results to - the result values will be added
  75. to any pre-existing data in this buffer after being multiplied by
  76. the gain factor
  77. @param numOutputSamplesToProduce the number of output samples that should be created
  78. @param gain a gain factor to multiply the resulting samples by before
  79. adding them to the destination buffer
  80. @returns the actual number of input samples that were used
  81. */
  82. int processAdding (double speedRatio,
  83. const float* inputSamples,
  84. float* outputSamples,
  85. int numOutputSamplesToProduce,
  86. float gain) noexcept;
  87. /** Resamples a stream of samples, adding the results to the output data
  88. with a gain.
  89. @param speedRatio the number of input samples to use for each output sample
  90. @param inputSamples the source data to read from. This must contain at
  91. least (speedRatio * numOutputSamplesToProduce) samples.
  92. @param outputSamples the buffer to write the results to - the result values will be added
  93. to any pre-existing data in this buffer after being multiplied by
  94. the gain factor
  95. @param numOutputSamplesToProduce the number of output samples that should be created
  96. @param available the number of available input samples. If it needs more samples
  97. than available, it either wraps back for wrapAround samples, or
  98. it feeds zeroes
  99. @param wrapAround if the stream exceeds available samples, it wraps back for
  100. wrapAround samples. If wrapAround is set to 0, it will feed zeroes.
  101. @param gain a gain factor to multiply the resulting samples by before
  102. adding them to the destination buffer
  103. @returns the actual number of input samples that were used
  104. */
  105. int processAdding (double speedRatio,
  106. const float* inputSamples,
  107. float* outputSamples,
  108. int numOutputSamplesToProduce,
  109. int available,
  110. int wrapAround,
  111. float gain) noexcept;
  112. private:
  113. float lastInputSamples[5];
  114. double subSamplePos;
  115. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LagrangeInterpolator)
  116. };
  117. } // namespace juce