OpenShot Library | libopenshot-audio  0.1.9
juce_ResamplingAudioSource.h
1 
2 /** @weakgroup juce_audio_basics-sources
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  A type of AudioSource that takes an input source and changes its sample rate.
33 
34  @see AudioSource, LagrangeInterpolator, CatmullRomInterpolator
35 
36  @tags{Audio}
37 */
39 {
40 public:
41  //==============================================================================
42  /** Creates a ResamplingAudioSource for a given input source.
43 
44  @param inputSource the input source to read from
45  @param deleteInputWhenDeleted if true, the input source will be deleted when
46  this object is deleted
47  @param numChannels the number of channels to process
48  */
49  ResamplingAudioSource (AudioSource* inputSource,
50  bool deleteInputWhenDeleted,
51  int numChannels = 2);
52 
53  /** Destructor. */
54  ~ResamplingAudioSource() override;
55 
56  /** Changes the resampling ratio.
57 
58  (This value can be changed at any time, even while the source is running).
59 
60  @param samplesInPerOutputSample if set to 1.0, the input is passed through; higher
61  values will speed it up; lower values will slow it
62  down. The ratio must be greater than 0
63  */
64  void setResamplingRatio (double samplesInPerOutputSample);
65 
66  /** Returns the current resampling ratio.
67 
68  This is the value that was set by setResamplingRatio().
69  */
70  double getResamplingRatio() const noexcept { return ratio; }
71 
72  /** Clears any buffers and filters that the resampler is using. */
73  void flushBuffers();
74 
75  //==============================================================================
76  void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
77  void releaseResources() override;
78  void getNextAudioBlock (const AudioSourceChannelInfo&) override;
79 
80 private:
81  //==============================================================================
83  double ratio, lastRatio;
84  AudioBuffer<float> buffer;
85  int bufferPos, sampsInBuffer;
86  double subSampleOffset;
87  double coefficients[6];
88  SpinLock ratioLock;
89  const int numChannels;
90  HeapBlock<float*> destBuffers;
91  HeapBlock<const float*> srcBuffers;
92 
93  void setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6);
94  void createLowPass (double proportionalRate);
95 
96  struct FilterState
97  {
98  double x1, x2, y1, y2;
99  };
100 
101  HeapBlock<FilterState> filterStates;
102  void resetFilters();
103 
104  void applyFilter (float* samples, int num, FilterState& fs);
105 
106  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResamplingAudioSource)
107 };
108 
109 } // namespace juce
110 
111 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
Very simple container class to hold a pointer to some data on the heap.
double getResamplingRatio() const noexcept
Returns the current resampling ratio.
A type of AudioSource that takes an input source and changes its sample rate.
Base class for objects that can produce a continuous stream of audio.
A simple spin-lock class that can be used as a simple, low-overhead mutex for uncontended situations...
Definition: juce_SpinLock.h:45
Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope...
Used by AudioSource::getNextAudioBlock().