Class BasicIndexGranularSource

java.lang.Object
net.paulhertz.pixelaudio.granular.BasicIndexGranularSource
All Implemented Interfaces:
PAFloatSource, PASource

public class BasicIndexGranularSource extends Object implements PASource
BasicIndexGranularSource A simple granular source that: - reads from a mono float[] source buffer, - uses a list of grain start indices (sample positions), - plays grains in order with fixed hop and fixed grain length, - applies a window (Minim WindowFunction) per grain, - sums all active grains into outL/outR. Timing: - Grains are scheduled relative to a "note start" time. - At note-on, call seekTo(noteStartAbsoluteSample) to define when this grain train begins. - Grain k starts at: noteStart + k * hopSamples, lasts grainLengthSamples. This class ignores per-grain pan for now; it writes mono into both outL and outR.
  • Field Details

    • source

      private final float[] source
    • grainStarts

      private final int[] grainStarts
    • grainLengthSamples

      private final int grainLengthSamples
    • hopSamples

      private final int hopSamples
    • windowFunction

      private final ddf.minim.analysis.WindowFunction windowFunction
    • windowCache

      private final WindowCache windowCache
    • windowCurve

      private final float[] windowCurve
    • numGrains

      private final int numGrains
    • noteStartSample

      private long noteStartSample
    • noteStarted

      private boolean noteStarted
  • Constructor Details

    • BasicIndexGranularSource

      public BasicIndexGranularSource(float[] source, int[] grainStarts, int grainLengthSamples, int hopSamples, ddf.minim.analysis.WindowFunction windowFunction)
      Parameters:
      source - mono audio buffer (float[])
      grainStarts - list of sample indices into 'source' where each grain is anchored
      grainLengthSamples - fixed grain length (in samples)
      hopSamples - fixed time between grain starts (in samples)
      windowFunction - Minim window function (Hann, Hamming, Blackman, ...)
  • Method Details

    • seekTo

      public void seekTo(long absoluteSample)
      Call this at note-on to define when the grain train starts in absolute sample time. Typically: scheduler or voice will call source.seekTo(nowAbsoluteSamples).
      Specified by:
      seekTo in interface PASource
      Parameters:
      absoluteSample - absolute sample index to seek to.
    • renderBlock

      public void renderBlock(long blockStart, int blockSize, float[] outL, float[] outR)
      Description copied from interface: PAFloatSource
      Render audio into the given block buffers. Implementations should: - Assume outL/outR length >= blockSize. - Mix into outL/outR (add), not clear them. - Avoid allocation on the audio thread.
      Specified by:
      renderBlock in interface PAFloatSource
      Parameters:
      blockStart - the absolute sample index in the source’s own sample domain (e.g., buffer index space).
      blockSize - number of samples in this block.
      outL - left channel buffer to mix into.
      outR - right channel buffer to mix into (may be same as outL for mono).
    • lengthSamples

      public long lengthSamples()
      Description copied from interface: PAFloatSource
      Duration in samples, or Long.MAX_VALUE if effectively infinite/streaming.
      Specified by:
      lengthSamples in interface PAFloatSource
    • pitchPolicy

      public PitchPolicy pitchPolicy()
      Description copied from interface: PASource
      Pitch policy hint for the instrument: should the instrument apply its pitch (playback rate) on top of this source?
      Specified by:
      pitchPolicy in interface PASource
    • getSource

      public float[] getSource()
    • getGrainStarts

      public int[] getGrainStarts()
    • getGrainLengthSamples

      public int getGrainLengthSamples()
    • getHopSamples

      public int getHopSamples()
    • getWindowFunction

      public ddf.minim.analysis.WindowFunction getWindowFunction()