Class PAGranularSampler

java.lang.Object
ddf.minim.UGen
net.paulhertz.pixelaudio.granular.PAGranularSampler

public class PAGranularSampler extends ddf.minim.UGen
PAGranularSampler UGen-based multi-voice granular sampler. Features: - Voice pooling (PAGranularVoice instances) - Per-voice ADSR, gain, and pan - Optional looping of the grain path - Thread-safe play() method - Per-sample mixing (like PASharedBufferSampler)
  • Field Details

    • out

      private final ddf.minim.AudioOutput out
    • voices

      private final List<PAGranularVoice> voices
    • maxVoices

      private int maxVoices
    • blockSize

      private int blockSize
    • smoothSteal

      private boolean smoothSteal
    • scheduler

    • sampleCursor

      private long sampleCursor
    • tmpStereo

      private final float[] tmpStereo
    • mixNorm

      private float mixNorm
    • globalMakeUpGain

      private float globalMakeUpGain
  • Constructor Details

    • PAGranularSampler

      public PAGranularSampler(ddf.minim.AudioOutput out, int maxVoices)
      Initializes this PAGranularSampler, which extends UGen and gets patched to an AudioOutput, with the result that its uGenerate method is called on each audio block.
      Parameters:
      out - a Minim AudioOutput that this PAGranularSampler will patch to
      maxVoices - maximum number of voices to allocate
    • PAGranularSampler

      public PAGranularSampler(ddf.minim.AudioOutput out)
  • Method Details

    • getAvailableVoice

      private PAGranularVoice getAvailableVoice(PASource src, ADSRParams env, float gain, float pan, boolean looping, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples)
      Allocate a PAGranularVoice instance. Called from play() and uGenerate() methods.
      Parameters:
      src - A PASource
      env - ADSRParams envelope, could be null
      gain - gain as a decimal value scaling amplitude
      pan - pan in stereo space, but grains can set individually
      looping - looping flag, best be false
      grainWindow - a Minim WindowFunction
      grainLenSamples - number of samples in one grain
      Returns:
    • getAvailableVoice

      private PAGranularVoice getAvailableVoice(PASource src, ADSRParams env, float gain, float pan, boolean looping)
    • play

      public long play(PASource src, ADSRParams env, float gain, float pan, boolean looping)
      Play a granular source as a voice.
      Parameters:
      src - PASource (PathGranularSource or BasicIndexGranularSource)
      env - ADSR for the macro envelope
      gain - amplitude
      pan - -1..+1
      looping - loop granular path
      Returns:
      voiceId or -1
    • play

      public long play(PASource src, ADSRParams env, float gain, float pan)
    • play

      public long play(PASource src, float gain, float pan, ADSRParams defaultEnv, boolean looping)
    • startAtSampleTime

      public void startAtSampleTime(PASource src, ADSRParams env, float gain, float pan, boolean looping, long startSample)
      Schedule a new voice to start at an absolute sample time.
      Parameters:
      src - PASource
      env - ADSR (already resolved: either custom or default)
      gain - final gain
      pan - final pan
      looping - loop flag
      startSample - absolute sample index at which to start the voice
    • startAtSampleTime

      public void startAtSampleTime(PASource src, ADSRParams env, float gain, float pan, boolean looping, long startSample, ddf.minim.analysis.WindowFunction grainWindow, int grainLenSamples)
      Called by PAGranularInstrument.startAtSampleTime(...), creates a ScheduledPlay instance with PASource src and other arguments, then passes it to AudioScheduler scheduler, which will be handled through Minim's uGenerate call to this instance of PAGranularSampler.
      Parameters:
      src - PASource
      env - ADSR (already resolved: either custom or default)
      gain - final gain
      pan - final pan
      looping - loop flag
      startSample - absolute sample index at which to start the voice
      grainWindow - a window function for shaping grain amplitude
      grainLenSamples - number of samples in one grain
    • startAfterDelaySamples

      public void startAfterDelaySamples(PASource src, ADSRParams env, float gain, float pan, boolean looping, long delaySamples)
      Schedule a new voice to start after a given delay in samples.
      Parameters:
      src - PASource
      env - ADSR
      gain - final gain
      pan - final pan
      looping - loop flag
      delaySamples - how many samples from "now" to start
    • getCurrentSampleTime

      public long getCurrentSampleTime()
      Expose the current absolute sample cursor (for higher-level scheduling).
    • uGenerate

      protected void uGenerate(float[] channels)
      Provides per-sample frame processing with AudioScheduler, called through Minim.
      Specified by:
      uGenerate in class ddf.minim.UGen
    • softClipSoftsign

      private static float softClipSoftsign(float x, float drive)
    • stopAll

      public void stopAll()
    • setMaxVoices

      public void setMaxVoices(int maxVoices)
    • getMaxVoices

      public int getMaxVoices()
    • setSmoothSteal

      public void setSmoothSteal(boolean smoothSteal)
    • isSmoothSteal

      public boolean isSmoothSteal()
    • getVoices

      public List<PAGranularVoice> getVoices()
    • getAudioOutput

      public ddf.minim.AudioOutput getAudioOutput()