Class PAIndexParametric

java.lang.Object
net.paulhertz.pixelaudio.curves.PAIndexParametric
All Implemented Interfaces:
PAControlCurve

public final class PAIndexParametric extends Object implements 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
    Modifier and Type
    Field
    Description
    private final int
     
    private final int[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PAIndexParametric(int[] offsets)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static float
    clamp01(float u)
     
    int[]
     
    int
     
    private static float
    lerp(int a, int b, float u)
     
    float
    sample(float u)
    Sample the curve at parameter u ∈ [0,1], returning the interpolated scalar value as a float.
    int
    sampleIndex(float u)
    Alias for sampleInt(u), preserving the old public API shape if desired.
    int
    sampleInt(float u)
    Sample the curve at parameter u ∈ [0,1], returning the interpolated scalar value rounded to the nearest int.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      sample in interface PAControlCurve
    • 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)