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.

109 lines
4.1KB

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