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.

juce_LagrangeInterpolator.h 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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, 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. } // namespace juce