Class WindowCache

java.lang.Object
net.paulhertz.pixelaudio.granular.WindowCache

public final class WindowCache extends Object
Thread-safe cache for generated Minim window curves. PixelAudio uses a Hann window by default. Minim provides additional WindowFunction classes and a model for creating your own.

WindowCache stores the arrays returned by WindowFunction.generateCurve(int) so repeated granular voices can reuse the same window data instead of regenerating it for every grain or playback event.

Cache entries are keyed by the concrete WindowFunction class and the requested length. Two different instances of the same window-function class therefore share a cached curve when the requested length is the same.

The cache is safe to access from multiple threads. For strict real-time audio behavior, call prewarm(WindowFunction, int) during setup or scheduling so the audio thread can later call getWindowCurve(WindowFunction, int) without triggering curve generation.

The returned arrays are cached and shared. Callers should treat them as read-only.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final WindowCache
    Shared cache instance used by the granular synthesis engine.
    private final Map<WindowCache.Key,float[]>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    float[]
    getWindowCurve(ddf.minim.analysis.WindowFunction wf, int length)
    Returns a cached window curve for the given window function and length.
    float[]
    prewarm(ddf.minim.analysis.WindowFunction wf, int length)
    Precomputes and caches a window curve.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INSTANCE

      public static final WindowCache INSTANCE
      Shared cache instance used by the granular synthesis engine.
    • windowCurves

      private final Map<WindowCache.Key,float[]> windowCurves
  • Constructor Details

    • WindowCache

      private WindowCache()
  • Method Details

    • prewarm

      public float[] prewarm(ddf.minim.analysis.WindowFunction wf, int length)
      Precomputes and caches a window curve.

      Use this method during setup or scheduling to avoid first-use curve generation on the audio thread. If the curve is already cached, this method returns the existing shared array.

      Parameters:
      wf - window function used to generate the curve
      length - number of samples in the generated curve
      Returns:
      the cached window curve; callers should treat the returned array as read-only
      Throws:
      NullPointerException - if wf is null
    • getWindowCurve

      public float[] getWindowCurve(ddf.minim.analysis.WindowFunction wf, int length)
      Returns a cached window curve for the given window function and length.

      If no matching curve has been cached, this method generates one lazily and stores it. For strict real-time safety, prefer calling prewarm(WindowFunction, int) ahead of time.

      Parameters:
      wf - window function used to generate the curve
      length - number of samples in the generated curve
      Returns:
      the cached window curve; callers should treat the returned array as read-only
      Throws:
      NullPointerException - if wf is null