Interface PASampler

All Known Implementing Classes:
PASharedBufferSampler

public interface PASampler
Backend engine contract for sampler implementations. Allows swapping implementations without changing higher layers.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears scheduled starts that have not fired yet.
    long
    Returns this sampler's current audio-thread sample clock.
    boolean
    Returns true if any currently active voice is looping.
    boolean
    Reports whether new sampler voices wrap source-buffer reads at the buffer end.
    int
    play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)
    Play command with all the useful arguments in standard order.
    void
    Releases all voices through their envelopes.
    void
    setBuffer(float[] buffer)
    Replaces the sampler source buffer.
    void
    setBuffer(float[] buffer, float playbackSampleRate)
    Replaces the sampler source buffer and playback sample rate.
    void
    setPlaybackSampleRate(float newRate)
    Updates the source-buffer playback sample rate.
    void
    setWrapAround(boolean wrapAround)
    Sets whether new sampler voices wrap source-buffer reads at the buffer end.
    void
    startAfterDelaySamples(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan, long delaySamples)
    Schedules playback after a delay in samples relative to this sampler's current audio clock.
    void
    startAtSampleTime(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan, long startSample)
    Schedules playback at an absolute sample time on this sampler's audio clock.
    void
    Stops all voices immediately.
  • Method Details

    • play

      int play(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan)
      Play command with all the useful arguments in standard order.
      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, linear value
      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
    • startAtSampleTime

      void startAtSampleTime(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan, long startSample)
      Schedules playback at an absolute sample time on this sampler's audio clock.
      Parameters:
      samplePos - index into the buffer to start sampling
      sampleLen - expected duration of the audio event
      amplitude - maximum amplitude of signal generated by the sampler, linear value
      env - ADSR style envelope for the entire event
      pitch - pitch multiplier, where 1.0f implies pitch is unchanged
      pan - location of audio event in stereo field, -1.0f = left, 0.0f = center, 1.0f = right
      startSample - absolute sample index on this sampler's clock
    • startAfterDelaySamples

      void startAfterDelaySamples(int samplePos, int sampleLen, float amplitude, ADSRParams env, float pitch, float pan, long delaySamples)
      Schedules playback after a delay in samples relative to this sampler's current audio clock.
      Parameters:
      samplePos - index into the buffer to start sampling
      sampleLen - expected duration of the audio event
      amplitude - maximum amplitude of signal generated by the sampler, linear value
      env - ADSR style envelope for the entire event
      pitch - pitch multiplier, where 1.0f implies pitch is unchanged
      pan - location of audio event in stereo field, -1.0f = left, 0.0f = center, 1.0f = right
      delaySamples - delay from the current sample time
    • getCurrentSampleTime

      long getCurrentSampleTime()
      Returns this sampler's current audio-thread sample clock.
      Returns:
      absolute sample cursor maintained by the sampler
    • clearScheduled

      void clearScheduled()
      Clears scheduled starts that have not fired yet.
    • setWrapAround

      void setWrapAround(boolean wrapAround)
      Sets whether new sampler voices wrap source-buffer reads at the buffer end.

      Wrapping is distinct from looping: a wrapped one-shot still plays for its requested duration and envelope, but sample reads that pass the end of the source buffer continue from the beginning.

      Parameters:
      wrapAround - true to wrap source-buffer reads for newly triggered voices
    • isWrapAround

      boolean isWrapAround()
      Reports whether new sampler voices wrap source-buffer reads at the buffer end.
      Returns:
      true when source-buffer wrapping is enabled
    • isLooping

      boolean isLooping()
      Returns true if any currently active voice is looping.
      Returns:
      true if one or more voices are looping
    • stopAll

      void stopAll()
      Stops all voices immediately.
    • releaseAll

      void releaseAll()
      Releases all voices through their envelopes.
    • setPlaybackSampleRate

      void setPlaybackSampleRate(float newRate)
      Updates the source-buffer playback sample rate.

      This is distinct from the audio device or Minim UGen sample rate. It controls how source-buffer sample positions are interpreted for playback speed and envelope duration calculations.

      Parameters:
      newRate - new source-buffer playback sample rate in Hz
    • setBuffer

      void setBuffer(float[] buffer)
      Replaces the sampler source buffer.
      Parameters:
      buffer - mono source sample buffer
    • setBuffer

      void setBuffer(float[] buffer, float playbackSampleRate)
      Replaces the sampler source buffer and playback sample rate.
      Parameters:
      buffer - mono source sample buffer
      playbackSampleRate - sample rate of the source buffer in Hz