Package net.paulhertz.pixelaudio.granular

# Class PABurstGranularSource

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

All Implemented Interfaces:
  `PAFloatSource`, `PASource`

public final class PABurstGranularSource extends Object implements PASource
Core class in the PAGranularInstrumentDirector granular synthesis processing chain, provides windowed granular synthesis with normalization.
Calling chain: PAGranularInstrumentDirector -> PAGranularInstrument -> PAGranularSampler -> PAGranularVoice,
with PABurstGranularSource handling the complexities of the granular synthesis sample by sample.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `private final int`
  `baseIndex`
  `private final int`
  `burstGrains`
  `private float`
  `gain`
  `private int`
  `grainLength`
  `private ddf.minim.analysis.WindowFunction`
  `grainWindow`
  `private final int`
  `indexHopSamples`
  `private boolean`
  `noteStarted`
  `private long`
  `noteStartSample`
  `private final float`
  `pitchRatio`
  `private final float[]`
  `source`
  `private final int`
  `timeHopSamples`
  `private float[]`
  `windowCurve`
  `private float[]`
  `wsum`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PABurstGranularSource(float[] source, int baseIndex, int grainLengthSamples, int burstGrains, int timeHopSamples, int indexHopSamples, float pitchRatio)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `private void`
  `ensureWSum(int blockSize)`
  `float`
  `getGain()`
  `long`
  `lengthSamples()`
  Duration in samples, or Long.MAX_VALUE if effectively infinite/streaming.
  `PitchPolicy`
  `pitchPolicy()`
  Pitch policy hint for the instrument: should the instrument apply its pitch (playback rate) on top of this source?
  `private static float`
  `readLinear(float[] buf, float pos)`
  Reads interpolated value at pos in buf and returns it.
  `void`
  `renderBlock(long blockStart, int blockSize, float[] outL, float[] outR)`
  Render audio into the given block buffers.
  `void`
  `seekTo(long absoluteSample)`
  Optional seek/rewind hook, mainly for transport or "note-on" start time.
  `void`
  `setGain(float gain)`
  Optional: set multiplicative gain applied after OLA normalization.
  `void`
  `setGrainWindow(ddf.minim.analysis.WindowFunction wf, int grainLenSamples)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface net.paulhertz.pixelaudio.granular.PASource

  `getMultiChannelBuffer`

- ## Field Details

  - ### source

    private final float[] source

  - ### baseIndex

    private final int baseIndex

  - ### burstGrains

    private final int burstGrains

  - ### timeHopSamples

    private final int timeHopSamples

  - ### indexHopSamples

    private final int indexHopSamples

  - ### pitchRatio

    private final float pitchRatio

  - ### gain

    private float gain

  - ### grainLength

    private int grainLength

  - ### grainWindow

    private ddf.minim.analysis.WindowFunction grainWindow

  - ### windowCurve

    private float[] windowCurve

  - ### noteStartSample

    private long noteStartSample

  - ### noteStarted

    private boolean noteStarted

  - ### wsum

    private float[] wsum

- ## Constructor Details

  - ### PABurstGranularSource

    public PABurstGranularSource(float[] source, int baseIndex, int grainLengthSamples, int burstGrains, int timeHopSamples, int indexHopSamples, float pitchRatio)

- ## Method Details

  - ### setGain

    public void setGain(float gain)
    Optional: set multiplicative gain applied after OLA normalization.

  - ### getGain

    public float getGain()

  - ### seekTo

    public void seekTo(long absoluteSample)
    Description copied from interface: `PASource`
    Optional seek/rewind hook, mainly for transport or "note-on" start time. Default implementation does nothing.
    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`

  - ### setGrainWindow

    public void setGrainWindow(ddf.minim.analysis.WindowFunction wf, int grainLenSamples)
    Specified by:
      `setGrainWindow` in interface `PASource`

  - ### ensureWSum

    private void ensureWSum(int blockSize)

  - ### readLinear

    private static float readLinear(float[] buf, float pos)
    Reads interpolated value at pos in buf and returns it.
    Parameters:
      `buf` - the audio buffer we use to generate grains
      `pos` - current position in the buffer
    Returns:
      linear interpolated value at pos in buf