OpenShot Library | OpenShotAudio 0.2.2
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
27namespace 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{
40public:
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 */
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
80private:
81 //==============================================================================
83 double ratio = 1.0, lastRatio = 1.0;
84 AudioBuffer<float> buffer;
85 int bufferPos = 0, sampsInBuffer = 0;
86 double subSampleOffset = 0.0;
87 double coefficients[6];
88 SpinLock ratioLock;
89 CriticalSection callbackLock;
90 const int numChannels;
91 HeapBlock<float*> destBuffers;
92 HeapBlock<const float*> srcBuffers;
93
94 void setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6);
95 void createLowPass (double proportionalRate);
96
97 struct FilterState
98 {
99 double x1, x2, y1, y2;
100 };
101
102 HeapBlock<FilterState> filterStates;
103 void resetFilters();
104
105 void applyFilter (float* samples, int num, FilterState& fs);
106
107 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResamplingAudioSource)
108};
109
110} // namespace juce
111
112/** @}*/
Base class for objects that can produce a continuous stream of audio.
A re-entrant mutex.
Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope.
A type of AudioSource that takes an input source and changes its sample rate.
double getResamplingRatio() const noexcept
Returns the current resampling ratio.
A simple spin-lock class that can be used as a simple, low-overhead mutex for uncontended situations.
Definition: juce_SpinLock.h:46
#define JUCE_API
This macro is added to all JUCE public class declarations.
Used by AudioSource::getNextAudioBlock().