Package net.paulhertz.pixelaudio.curves
Class PAIndexParametric
java.lang.Object
net.paulhertz.pixelaudio.curves.PAIndexParametric
- All Implemented Interfaces:
PAControlCurve
PAIndexParametric
Parametric view of an indexed offset list, typically into a float[] buffer
(for example, an audio signal or lookup table).
u ∈ [0,1] -> f(u)
For now, u is interpreted over the index domain of the offset list:
- u = 0 -> first offset
- u = 1 -> last offset
- intermediate u -> linear interpolation between neighboring offsets
This class now implements PAControlCurve so it can be used anywhere a
normalized scalar control curve is needed.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static floatclamp01(float u) int[]intprivate static floatlerp(int a, int b, float u) floatsample(float u) Sample the curve at parameter u ∈ [0,1], returning the interpolated scalar value as a float.intsampleIndex(float u) Alias for sampleInt(u), preserving the old public API shape if desired.intsampleInt(float u) Sample the curve at parameter u ∈ [0,1], returning the interpolated scalar value rounded to the nearest int.
-
Field Details
-
offsets
private final int[] offsets -
count
private final int count
-
-
Constructor Details
-
PAIndexParametric
public PAIndexParametric(int[] offsets) - Parameters:
offsets- ordered offsets in a buffer; must contain at least 2 offsets
-
-
Method Details
-
getPointCount
public int getPointCount()- Returns:
- number of offsets in this parametric series
-
getOffsets
public int[] getOffsets()- Returns:
- defensive copy of the underlying offsets
-
sample
public float sample(float u) Sample the curve at parameter u ∈ [0,1], returning the interpolated scalar value as a float. u is clamped to [0,1].- Specified by:
samplein interfacePAControlCurve
-
sampleInt
public int sampleInt(float u) Sample the curve at parameter u ∈ [0,1], returning the interpolated scalar value rounded to the nearest int. Handy when offsets are ultimately used as buffer indices. -
sampleIndex
public int sampleIndex(float u) Alias for sampleInt(u), preserving the old public API shape if desired. -
clamp01
private static float clamp01(float u) -
lerp
private static float lerp(int a, int b, float u)
-