Class PASharedBufferSampler

java.lang.Object
ddf.minim.UGen
net.paulhertz.pixelaudio.voices.PASharedBufferSampler
All Implemented Interfaces:
PASampler

public class PASharedBufferSampler extends ddf.minim.UGen implements PASampler
UGen-based sampler that plays multiple PASamplerVoice instances from a single shared mono buffer (channel 0 of a MultiChannelBuffer) which is an array of floating point samples over (-1.0..1.0). Features: - Shared buffer (no duplication) - Polyphony with voice pooling - Looping (global default + per-voice) - ADSR per voice via ADSRParams - Oldest-first voice recycling, optional smooth stealing - Thread-safe triggering Automatically patches to the provided AudioOutput.
  • Nested Class Summary

    Nested classes/interfaces inherited from class ddf.minim.UGen

    ddf.minim.UGen.InputType, ddf.minim.UGen.UGenInput
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private float[]
     
    private int
     
    protected boolean
     
    private boolean
     
    private int
     
    private final ddf.minim.AudioOutput
     
    private float
     
    private boolean
     
    private final List<PASamplerVoice>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, float sampleRate, ddf.minim.AudioOutput out)
    Construct a sampler over a shared MultiChannelBuffer.
    PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, float playbackSampleRate, ddf.minim.AudioOutput out, int maxVoices)
     
    PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, ddf.minim.AudioOutput out)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    ddf.minim.AudioOutput
     
    Get a free voice, or recycle the oldest active one if at the polyphony limit.
    int
     
    int
     
    float
    Returns the current sample rate of this sampler.
    Read-only list of voices for GUI or debugging.
    boolean
     
    boolean
    Returns true if any currently active voice is looping.
    boolean
     
    int
    play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)
    Play command with all the useful arguments in standard order, overrides PASampler.play().
    void
    setBuffer(float[] buffer)
     
    void
    setBuffer(float[] buffer, float playbackSampleRate)
     
    void
    setGlobalLooping(boolean looping)
    Default looping for newly triggered voices.
    void
    setMaxVoices(int maxVoices)
    Change maximum polyphony at runtime.
    void
    setPlaybackSampleRate(float newRate)
    Updates the playback sample rate used for reading from the buffer.
    void
    setSmoothSteal(boolean smoothSteal)
    Enable/disable smooth stealing (release envelope) on voice recycle.
    void
    Stops all voices immediately.
    protected void
    uGenerate(float[] channels)
     
    void
    Convenience: synchronize playback rate with AudioOutput's sample rate.

    Methods inherited from class ddf.minim.UGen

    addAudio, addControl, addControl, addInput, channelCount, channelCountChanged, getLastValues, patch, patch, patch, printInputs, removeInput, sampleRate, sampleRateChanged, setChannelCount, setSampleRate, tick, unpatch, unpatch

    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.voices.PASampler

    setSampleRate
  • Field Details

    • buffer

      private float[] buffer
    • bufferLen

      private int bufferLen
    • playbackSampleRate

      private float playbackSampleRate
    • out

      private final ddf.minim.AudioOutput out
    • voices

      private final List<PASamplerVoice> voices
    • maxVoices

      private int maxVoices
    • globalLooping

      private boolean globalLooping
    • smoothSteal

      private boolean smoothSteal
    • DEBUG

      protected boolean DEBUG
  • Constructor Details

    • PASharedBufferSampler

      public PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, float sampleRate, ddf.minim.AudioOutput out)
      Construct a sampler over a shared MultiChannelBuffer. Automatically patches to the provided AudioOutput.
      Parameters:
      multiBuffer - shared source buffer (mono or stereo)
      sampleRate - sample rate of the buffer
      out - target AudioOutput for playback
    • PASharedBufferSampler

      public PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, float playbackSampleRate, ddf.minim.AudioOutput out, int maxVoices)
    • PASharedBufferSampler

      public PASharedBufferSampler(ddf.minim.MultiChannelBuffer multiBuffer, ddf.minim.AudioOutput out)
  • Method Details

    • play

      public int play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)
      Play command with all the useful arguments in standard order, overrides PASampler.play(). TODO We plan to make this the only play() method PASharedBufferSampler.
      Specified by:
      play in interface PASampler
      Parameters:
      samplePos - index into the buffer to start sampling
      sampleLen - expected duration of the audio event, which is expected to return its actual duration
      amplitude - maximum amplitude of signal generated by the sampler
      env - ADSR style envelope for the entire event
      pitch - pitch multiplier, where 1.0f implies pitch is unchanged and all samples are read
      pan - location of audio event in stereo field, -1.0f = left, 0.0f = center, 1.0f = right
      Returns:
      actual duration of event in samples, typically sampleLen + envelope release time
    • getAvailableVoice

      private PASamplerVoice getAvailableVoice()
      Get a free voice, or recycle the oldest active one if at the polyphony limit.
    • uGenerate

      protected void uGenerate(float[] channels)
      Specified by:
      uGenerate in class ddf.minim.UGen
    • stopAll

      public void stopAll()
      Description copied from interface: PASampler
      Stops all voices immediately.
      Specified by:
      stopAll in interface PASampler
    • isLooping

      public boolean isLooping()
      Description copied from interface: PASampler
      Returns true if any currently active voice is looping.
      Specified by:
      isLooping in interface PASampler
    • setGlobalLooping

      public void setGlobalLooping(boolean looping)
      Default looping for newly triggered voices.
    • isGlobalLooping

      public boolean isGlobalLooping()
    • setSmoothSteal

      public void setSmoothSteal(boolean smoothSteal)
      Enable/disable smooth stealing (release envelope) on voice recycle.
    • isSmoothSteal

      public boolean isSmoothSteal()
    • setMaxVoices

      public void setMaxVoices(int maxVoices)
      Change maximum polyphony at runtime.
    • getMaxVoices

      public int getMaxVoices()
    • getVoices

      public List<PASamplerVoice> getVoices()
      Read-only list of voices for GUI or debugging.
    • setBuffer

      public void setBuffer(float[] buffer)
      Specified by:
      setBuffer in interface PASampler
    • setBuffer

      public void setBuffer(float[] buffer, float playbackSampleRate)
      Specified by:
      setBuffer in interface PASampler
    • countAvailableVoices

      public int countAvailableVoices()
    • getPlaybackSampleRate

      public float getPlaybackSampleRate()
      Returns the current sample rate of this sampler.
    • setPlaybackSampleRate

      public void setPlaybackSampleRate(float newRate)
      Updates the playback sample rate used for reading from the buffer. Does not affect Minim's UGen sample rate.
    • updatePlaybackRateFromOutput

      public void updatePlaybackRateFromOutput()
      Convenience: synchronize playback rate with AudioOutput's sample rate. Useful if you want playback speed tied to system rate.
    • getBufferLength

      public int getBufferLength()
    • getAudioOutput

      public ddf.minim.AudioOutput getAudioOutput()