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_ResamplingAudioSource.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_RESAMPLINGAUDIOSOURCE_H_INCLUDED
  18. #define JUCE_RESAMPLINGAUDIOSOURCE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A type of AudioSource that takes an input source and changes its sample rate.
  22. @see AudioSource
  23. */
  24. class JUCE_API ResamplingAudioSource : public AudioSource
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a ResamplingAudioSource for a given input source.
  29. @param inputSource the input source to read from
  30. @param deleteInputWhenDeleted if true, the input source will be deleted when
  31. this object is deleted
  32. @param numChannels the number of channels to process
  33. */
  34. ResamplingAudioSource (AudioSource* inputSource,
  35. bool deleteInputWhenDeleted,
  36. int numChannels = 2);
  37. /** Destructor. */
  38. ~ResamplingAudioSource();
  39. /** Changes the resampling ratio.
  40. (This value can be changed at any time, even while the source is running).
  41. @param samplesInPerOutputSample if set to 1.0, the input is passed through; higher
  42. values will speed it up; lower values will slow it
  43. down. The ratio must be greater than 0
  44. */
  45. void setResamplingRatio (double samplesInPerOutputSample);
  46. /** Returns the current resampling ratio.
  47. This is the value that was set by setResamplingRatio().
  48. */
  49. double getResamplingRatio() const noexcept { return ratio; }
  50. //==============================================================================
  51. void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
  52. void releaseResources() override;
  53. void getNextAudioBlock (const AudioSourceChannelInfo&) override;
  54. private:
  55. //==============================================================================
  56. OptionalScopedPointer<AudioSource> input;
  57. double ratio, lastRatio;
  58. AudioSampleBuffer buffer;
  59. int bufferPos, sampsInBuffer;
  60. double subSampleOffset;
  61. double coefficients[6];
  62. SpinLock ratioLock;
  63. const int numChannels;
  64. HeapBlock<float*> destBuffers, srcBuffers;
  65. void setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6);
  66. void createLowPass (double proportionalRate);
  67. struct FilterState
  68. {
  69. double x1, x2, y1, y2;
  70. };
  71. HeapBlock<FilterState> filterStates;
  72. void resetFilters();
  73. void applyFilter (float* samples, int num, FilterState& fs);
  74. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResamplingAudioSource)
  75. };
  76. #endif // JUCE_RESAMPLINGAUDIOSOURCE_H_INCLUDED