OpenShot Library | OpenShotAudio  0.2.1
juce_LagrangeInterpolator.h
1 
2 /** @weakgroup juce_audio_basics-utilities
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  Interpolator for resampling a stream of floats using 4-point lagrange interpolation.
32 
33  Note that the resampler is stateful, so when there's a break in the continuity
34  of the input stream you're feeding it, you should call reset() before feeding
35  it any new data. And like with any other stateful filter, if you're resampling
36  multiple channels, make sure each one uses its own LagrangeInterpolator
37  object.
38 
39  @see CatmullRomInterpolator
40 
41  @tags{Audio}
42 */
44 {
45 public:
46  LagrangeInterpolator() noexcept;
47  ~LagrangeInterpolator() noexcept;
48 
49  LagrangeInterpolator (LagrangeInterpolator&&) noexcept = default;
50  LagrangeInterpolator& operator= (LagrangeInterpolator&&) noexcept = default;
51 
52  /** Resets the state of the interpolator.
53  Call this when there's a break in the continuity of the input data stream.
54  */
55  void reset() noexcept;
56 
57  /** Resamples a stream of samples.
58 
59  @param speedRatio the number of input samples to use for each output sample
60  @param inputSamples the source data to read from. This must contain at
61  least (speedRatio * numOutputSamplesToProduce) samples.
62  @param outputSamples the buffer to write the results into
63  @param numOutputSamplesToProduce the number of output samples that should be created
64 
65  @returns the actual number of input samples that were used
66  */
67  int process (double speedRatio,
68  const float* inputSamples,
69  float* outputSamples,
70  int numOutputSamplesToProduce) noexcept;
71 
72  /** Resamples a stream of samples.
73 
74  @param speedRatio the number of input samples to use for each output sample
75  @param inputSamples the source data to read from. This must contain at
76  least (speedRatio * numOutputSamplesToProduce) samples.
77  @param outputSamples the buffer to write the results into
78  @param numOutputSamplesToProduce the number of output samples that should be created
79  @param available the number of available input samples. If it needs more samples
80  than available, it either wraps back for wrapAround samples, or
81  it feeds zeroes
82  @param wrapAround if the stream exceeds available samples, it wraps back for
83  wrapAround samples. If wrapAround is set to 0, it will feed zeroes.
84 
85  @returns the actual number of input samples that were used
86  */
87  int process (double speedRatio,
88  const float* inputSamples,
89  float* outputSamples,
90  int numOutputSamplesToProduce,
91  int available,
92  int wrapAround) noexcept;
93 
94  /** Resamples a stream of samples, adding the results to the output data
95  with a gain.
96 
97  @param speedRatio the number of input samples to use for each output sample
98  @param inputSamples the source data to read from. This must contain at
99  least (speedRatio * numOutputSamplesToProduce) samples.
100  @param outputSamples the buffer to write the results to - the result values will be added
101  to any pre-existing data in this buffer after being multiplied by
102  the gain factor
103  @param numOutputSamplesToProduce the number of output samples that should be created
104  @param gain a gain factor to multiply the resulting samples by before
105  adding them to the destination buffer
106 
107  @returns the actual number of input samples that were used
108  */
109  int processAdding (double speedRatio,
110  const float* inputSamples,
111  float* outputSamples,
112  int numOutputSamplesToProduce,
113  float gain) noexcept;
114 
115  /** Resamples a stream of samples, adding the results to the output data
116  with a gain.
117 
118  @param speedRatio the number of input samples to use for each output sample
119  @param inputSamples the source data to read from. This must contain at
120  least (speedRatio * numOutputSamplesToProduce) samples.
121  @param outputSamples the buffer to write the results to - the result values will be added
122  to any pre-existing data in this buffer after being multiplied by
123  the gain factor
124  @param numOutputSamplesToProduce the number of output samples that should be created
125  @param available the number of available input samples. If it needs more samples
126  than available, it either wraps back for wrapAround samples, or
127  it feeds zeroes
128  @param wrapAround if the stream exceeds available samples, it wraps back for
129  wrapAround samples. If wrapAround is set to 0, it will feed zeroes.
130  @param gain a gain factor to multiply the resulting samples by before
131  adding them to the destination buffer
132 
133  @returns the actual number of input samples that were used
134  */
135  int processAdding (double speedRatio,
136  const float* inputSamples,
137  float* outputSamples,
138  int numOutputSamplesToProduce,
139  int available,
140  int wrapAround,
141  float gain) noexcept;
142 
143 private:
144  float lastInputSamples[5];
145  double subSamplePos;
146 
147  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LagrangeInterpolator)
148 };
149 
150 } // namespace juce
151 
152 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
Interpolator for resampling a stream of floats using 4-point lagrange interpolation.