OpenShot Library | OpenShotAudio  0.2.2
juce_CatmullRomInterpolator.cpp
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  The code included in this file is provided under the terms of the ISC license
11  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12  To use, copy, modify, and/or distribute this software for any purpose with or
13  without fee is hereby granted provided that the above copyright notice and
14  this permission notice appear in all copies.
15 
16  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18  DISCLAIMED.
19 
20  ==============================================================================
21 */
22 
23 namespace juce
24 {
25 
27 {
28  static forcedinline float valueAtOffset (const float* const inputs, const float offset) noexcept
29  {
30  auto y0 = inputs[3];
31  auto y1 = inputs[2];
32  auto y2 = inputs[1];
33  auto y3 = inputs[0];
34 
35  auto halfY0 = 0.5f * y0;
36  auto halfY3 = 0.5f * y3;
37 
38  return y1 + offset * ((0.5f * y2 - halfY0)
39  + (offset * (((y0 + 2.0f * y2) - (halfY3 + 2.5f * y1))
40  + (offset * ((halfY3 + 1.5f * y1) - (halfY0 + 1.5f * y2))))));
41  }
42 };
43 
44 CatmullRomInterpolator::CatmullRomInterpolator() noexcept { reset(); }
45 CatmullRomInterpolator::~CatmullRomInterpolator() noexcept {}
46 
48 {
49  subSamplePos = 1.0;
50 
51  for (auto& s : lastInputSamples)
52  s = 0;
53 }
54 
55 int CatmullRomInterpolator::process (double actualRatio, const float* in, float* out, int numOut, int available, int wrap) noexcept
56 {
57  return interpolate<CatmullRomAlgorithm> (lastInputSamples, subSamplePos, actualRatio, in, out, numOut, available, wrap);
58 }
59 
60 int CatmullRomInterpolator::process (double actualRatio, const float* in, float* out, int numOut) noexcept
61 {
62  return interpolate<CatmullRomAlgorithm> (lastInputSamples, subSamplePos, actualRatio, in, out, numOut);
63 }
64 
65 int CatmullRomInterpolator::processAdding (double actualRatio, const float* in, float* out, int numOut, int available, int wrap, float gain) noexcept
66 {
67  return interpolateAdding<CatmullRomAlgorithm> (lastInputSamples, subSamplePos, actualRatio, in, out, numOut, available, wrap, gain);
68 }
69 
70 int CatmullRomInterpolator::processAdding (double actualRatio, const float* in, float* out, int numOut, float gain) noexcept
71 {
72  return interpolateAdding<CatmullRomAlgorithm> (lastInputSamples, subSamplePos, actualRatio, in, out, numOut, gain);
73 }
74 
75 } // namespace juce
int process(double speedRatio, const float *inputSamples, float *outputSamples, int numOutputSamplesToProduce) noexcept
Resamples a stream of samples.
void reset() noexcept
Resets the state of the interpolator.
int processAdding(double speedRatio, const float *inputSamples, float *outputSamples, int numOutputSamplesToProduce, float gain) noexcept
Resamples a stream of samples, adding the results to the output data with a gain. ...