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.

114 lines
4.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_RESAMPLINGAUDIOSOURCE_H_INCLUDED
  24. #define JUCE_RESAMPLINGAUDIOSOURCE_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. A type of AudioSource that takes an input source and changes its sample rate.
  28. @see AudioSource, LagrangeInterpolator, CatmullRomInterpolator
  29. */
  30. class JUCE_API ResamplingAudioSource : public AudioSource
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates a ResamplingAudioSource for a given input source.
  35. @param inputSource the input source to read from
  36. @param deleteInputWhenDeleted if true, the input source will be deleted when
  37. this object is deleted
  38. @param numChannels the number of channels to process
  39. */
  40. ResamplingAudioSource (AudioSource* inputSource,
  41. bool deleteInputWhenDeleted,
  42. int numChannels = 2);
  43. /** Destructor. */
  44. ~ResamplingAudioSource();
  45. /** Changes the resampling ratio.
  46. (This value can be changed at any time, even while the source is running).
  47. @param samplesInPerOutputSample if set to 1.0, the input is passed through; higher
  48. values will speed it up; lower values will slow it
  49. down. The ratio must be greater than 0
  50. */
  51. void setResamplingRatio (double samplesInPerOutputSample);
  52. /** Returns the current resampling ratio.
  53. This is the value that was set by setResamplingRatio().
  54. */
  55. double getResamplingRatio() const noexcept { return ratio; }
  56. /** Clears any buffers and filters that the resampler is using. */
  57. void flushBuffers();
  58. //==============================================================================
  59. void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
  60. void releaseResources() override;
  61. void getNextAudioBlock (const AudioSourceChannelInfo&) override;
  62. private:
  63. //==============================================================================
  64. OptionalScopedPointer<AudioSource> input;
  65. double ratio, lastRatio;
  66. AudioSampleBuffer buffer;
  67. int bufferPos, sampsInBuffer;
  68. double subSampleOffset;
  69. double coefficients[6];
  70. SpinLock ratioLock;
  71. const int numChannels;
  72. HeapBlock<float*> destBuffers;
  73. HeapBlock<const float*> srcBuffers;
  74. void setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6);
  75. void createLowPass (double proportionalRate);
  76. struct FilterState
  77. {
  78. double x1, x2, y1, y2;
  79. };
  80. HeapBlock<FilterState> filterStates;
  81. void resetFilters();
  82. void applyFilter (float* samples, int num, FilterState& fs);
  83. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResamplingAudioSource)
  84. };
  85. #endif // JUCE_RESAMPLINGAUDIOSOURCE_H_INCLUDED