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