Package net.paulhertz.pixelaudio.granular

# Class PAGranularVoice

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

public class PAGranularVoice extends Object
PAGranularVoice A single granular "voice" driven by a PASource. Provides: - nextSample() API so it can be mixed like PASamplerVoice - voice-level ADSR envelope (macro envelope) - per-voice amplitude + pan - optional looping of entire grain path Internally uses: - Block buffer (blockL / blockR) - Absolute sample counter (absSample) - Cursor into current block

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `private long`
  `absSample`
  `private boolean`
  `active`
  `private final float[]`
  `blockL`
  `private final float[]`
  `blockR`
  `private final int`
  `blockSize`
  `private int`
  `cursor`
  `(package private) ADSRParams`
  `defaultEnvParams`
  `private boolean`
  `endTriggered`
  `private SimpleADSR`
  `envelope`
  `private boolean`
  `finished`
  `private float`
  `gain`
  `private int`
  `grainLenSamples`
  `private ddf.minim.analysis.WindowFunction`
  `grainWindow`
  `private boolean`
  `looping`
  `private static long`
  `NEXT_VOICE_ID`
  `private float`
  `pan`
  `private float`
  `panGainL`
  `private float`
  `panGainR`
  `private float`
  `playbackSampleRate`
  `private boolean`
  `released`
  `private PASource`
  `source`
  `private long`
  `voiceId`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PAGranularVoice(PASource source, int blockSize, float playbackSampleRate)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `activate(PASource source, ADSRParams envParams, float gain, float pan, boolean looping)`
  `void`
  `activate(PASource source, ADSRParams envParams, float gain, float pan, boolean looping, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples)`
  `private static float`
  `clampPan(float p)`
  `float`
  `getPan()`
  `long`
  `getVoiceId()`
  `boolean`
  `isActive()`
  `boolean`
  `isFinished()`
  `boolean`
  `isReleasing()`
  `float`
  `nextSample()`
  `void`
  `nextSampleStereo(float[] outLR)`
  `private void`
  `refillBlock()`
  `void`
  `release()`
  `void`
  `setSource(PASource source)`
  `void`
  `stop()`
  `private void`
  `updatePanGains()`

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

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

- ## Field Details

  - ### NEXT_VOICE_ID

    private static long NEXT_VOICE_ID

  - ### source

    private PASource source

  - ### blockSize

    private final int blockSize

  - ### voiceId

    private long voiceId

  - ### active

    private boolean active

  - ### released

    private boolean released

  - ### finished

    private boolean finished

  - ### gain

    private float gain

  - ### pan

    private float pan

  - ### looping

    private boolean looping

  - ### playbackSampleRate

    private float playbackSampleRate

  - ### blockL

    private final float[] blockL

  - ### blockR

    private final float[] blockR

  - ### cursor

    private int cursor

  - ### absSample

    private long absSample

  - ### envelope

    private SimpleADSR envelope

  - ### defaultEnvParams

    ADSRParams defaultEnvParams

  - ### panGainL

    private float panGainL

  - ### panGainR

    private float panGainR

  - ### grainWindow

    private ddf.minim.analysis.WindowFunction grainWindow

  - ### grainLenSamples

    private int grainLenSamples

  - ### endTriggered

    private boolean endTriggered

- ## Constructor Details

  - ### PAGranularVoice

    public PAGranularVoice(PASource source, int blockSize, float playbackSampleRate)

- ## Method Details

  - ### setSource

    public void setSource(PASource source)

  - ### activate

    public void activate(PASource source, ADSRParams envParams, float gain, float pan, boolean looping)

  - ### activate

    public void activate(PASource source, ADSRParams envParams, float gain, float pan, boolean looping, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples)

  - ### nextSampleStereo

    public void nextSampleStereo(float[] outLR)

  - ### nextSample

    public float nextSample()

  - ### refillBlock

    private void refillBlock()

  - ### updatePanGains

    private void updatePanGains()

  - ### release

    public void release()

  - ### stop

    public void stop()

  - ### isActive

    public boolean isActive()

  - ### isReleasing

    public boolean isReleasing()

  - ### isFinished

    public boolean isFinished()

  - ### getVoiceId

    public long getVoiceId()

  - ### getPan

    public float getPan()

  - ### clampPan

    private static float clampPan(float p)