LMMS
Loading...
Searching...
No Matches
juce_Interpolators.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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
23namespace juce
24{
25
35{
36private:
38 {
39 static constexpr float algorithmicLatency = 100.0f;
40
41 static forcedinline float windowedSinc (float firstFrac, int index) noexcept
42 {
43 auto index2 = index + 1;
44 auto frac = firstFrac;
45
46 auto value1 = lookupTable[index];
47 auto value2 = lookupTable[index2];
48
49 return value1 + (frac * (value2 - value1));
50 }
51
52 static forcedinline float valueAtOffset (const float* const inputs, const float offset, int indexBuffer) noexcept
53 {
54 const int numCrossings = 100;
55 const float floatCrossings = (float) numCrossings;
56 float result = 0.0f;
57
58 auto samplePosition = indexBuffer;
59 float firstFrac = 0.0f;
60 float lastSincPosition = -1.0f;
61 int index = 0, sign = -1;
62
63 for (int i = -numCrossings; i <= numCrossings; ++i)
64 {
65 auto sincPosition = (1.0f - offset) + (float) i;
66
67 if (i == -numCrossings || (sincPosition >= 0 && lastSincPosition < 0))
68 {
69 auto indexFloat = (sincPosition >= 0.f ? sincPosition : -sincPosition) * 100.0f;
70 auto indexFloored = std::floor (indexFloat);
71 index = (int) indexFloored;
72 firstFrac = indexFloat - indexFloored;
73 sign = (sincPosition < 0 ? -1 : 1);
74 }
75
76 if (sincPosition == 0.0f)
77 result += inputs[samplePosition];
78 else if (sincPosition < floatCrossings && sincPosition > -floatCrossings)
79 result += inputs[samplePosition] * windowedSinc (firstFrac, index);
80
81 if (++samplePosition == numCrossings * 2)
82 samplePosition = 0;
83
84 lastSincPosition = sincPosition;
85 index += 100 * sign;
86 }
87
88 return result;
89 }
90
91 static const float lookupTable[10001];
92 };
93
95 {
96 static constexpr float algorithmicLatency = 2.0f;
97
98 static float valueAtOffset (const float*, float, int) noexcept;
99 };
100
102 {
103 //==============================================================================
104 static constexpr float algorithmicLatency = 2.0f;
105
106 static forcedinline float valueAtOffset (const float* const inputs, const float offset, int index) noexcept
107 {
108 auto y0 = inputs[index]; if (++index == 4) index = 0;
109 auto y1 = inputs[index]; if (++index == 4) index = 0;
110 auto y2 = inputs[index]; if (++index == 4) index = 0;
111 auto y3 = inputs[index];
112
113 auto halfY0 = 0.5f * y0;
114 auto halfY3 = 0.5f * y3;
115
116 return y1 + offset * ((0.5f * y2 - halfY0)
117 + (offset * (((y0 + 2.0f * y2) - (halfY3 + 2.5f * y1))
118 + (offset * ((halfY3 + 1.5f * y1) - (halfY0 + 1.5f * y2))))));
119 }
120 };
121
123 {
124 static constexpr float algorithmicLatency = 1.0f;
125
126 static forcedinline float valueAtOffset (const float* const inputs, const float offset, int index) noexcept
127 {
128 auto y0 = inputs[index];
129 auto y1 = inputs[index == 0 ? 1 : 0];
130
131 return y1 * offset + y0 * (1.0f - offset);
132 }
133 };
134
136 {
137 static constexpr float algorithmicLatency = 0.0f;
138
139 static forcedinline float valueAtOffset (const float* const inputs, const float, int) noexcept
140 {
141 return inputs[0];
142 }
143 };
144
145public:
151};
152
153//==============================================================================
171
188
205
222
241
242} // namespace juce
Definition juce_GenericInterpolator.h:41
Definition juce_Interpolators.h:35
GenericInterpolator< ZeroOrderHoldTraits, 1 > ZeroOrderHold
Definition juce_Interpolators.h:150
GenericInterpolator< WindowedSincTraits, 200 > WindowedSinc
Definition juce_Interpolators.h:146
GenericInterpolator< LagrangeTraits, 5 > Lagrange
Definition juce_Interpolators.h:147
GenericInterpolator< LinearTraits, 2 > Linear
Definition juce_Interpolators.h:149
GenericInterpolator< CatmullRomTraits, 4 > CatmullRom
Definition juce_Interpolators.h:148
register unsigned i
Definition inflate.c:1575
#define forcedinline
Definition carla_juce.cpp:31
Interpolators::Lagrange LagrangeInterpolator
Definition juce_Interpolators.h:187
Interpolators::ZeroOrderHold ZeroOrderHoldInterpolator
Definition juce_Interpolators.h:240
Interpolators::Linear LinearInterpolator
Definition juce_Interpolators.h:221
Interpolators::WindowedSinc WindowedSincInterpolator
Definition juce_Interpolators.h:170
Interpolators::CatmullRom CatmullRomInterpolator
Definition juce_Interpolators.h:204
Definition juce_Interpolators.h:102
static constexpr float algorithmicLatency
Definition juce_Interpolators.h:104
static forcedinline float valueAtOffset(const float *const inputs, const float offset, int index) noexcept
Definition juce_Interpolators.h:106
Definition juce_Interpolators.h:95
static constexpr float algorithmicLatency
Definition juce_Interpolators.h:96
static float valueAtOffset(const float *, float, int) noexcept
Definition juce_LagrangeInterpolator.cpp:49
Definition juce_Interpolators.h:123
static forcedinline float valueAtOffset(const float *const inputs, const float offset, int index) noexcept
Definition juce_Interpolators.h:126
static constexpr float algorithmicLatency
Definition juce_Interpolators.h:124
Definition juce_Interpolators.h:38
static forcedinline float valueAtOffset(const float *const inputs, const float offset, int indexBuffer) noexcept
Definition juce_Interpolators.h:52
static const float lookupTable[10001]
Definition juce_Interpolators.h:91
static forcedinline float windowedSinc(float firstFrac, int index) noexcept
Definition juce_Interpolators.h:41
static constexpr float algorithmicLatency
Definition juce_Interpolators.h:39
Definition juce_Interpolators.h:136
static constexpr float algorithmicLatency
Definition juce_Interpolators.h:137
static forcedinline float valueAtOffset(const float *const inputs, const float, int) noexcept
Definition juce_Interpolators.h:139
int result
Definition process.c:1455
typedef int(UZ_EXP MsgFn)()