Class PABufferBackedSource

java.lang.Object
net.paulhertz.pixelaudio.granular.PABufferBackedSource
All Implemented Interfaces:
PAFloatSource, PASource

public final class PABufferBackedSource extends Object implements PASource
  • Field Details

    • name

      private final String name
    • sampleRate

      private final float sampleRate
    • mcb

      private final ddf.minim.MultiChannelBuffer mcb
    • pitchPolicy

      private final PitchPolicy pitchPolicy
    • grainWindow

      private ddf.minim.analysis.WindowFunction grainWindow
    • grainLenSamples

      private int grainLenSamples
    • baseOffset

      private volatile long baseOffset
      Base offset applied to blockStart in renderBlock(long, int, float[], float[]). Semantics: after seekTo(long) with value T, a call to renderBlock(T, ...) begins reading from buffer index 0.
  • Constructor Details

    • PABufferBackedSource

      public PABufferBackedSource(String name, float sampleRate, ddf.minim.MultiChannelBuffer mcb, PitchPolicy pitchPolicy)
  • Method Details

    • fromMono

      public static PABufferBackedSource fromMono(String name, float[] mono, float sampleRate)
      Copies mono into an internal 1-channel MultiChannelBuffer.
    • fromStereo

      public static PABufferBackedSource fromStereo(String name, float[] left, float[] right, float sampleRate)
      Copies left/right into an internal 2-channel MultiChannelBuffer.
    • fromChannels

      public static PABufferBackedSource fromChannels(String name, float sampleRate, float[]... channels)
      Copies per-channel arrays into an internal MultiChannelBuffer. All channels must have the same length (frames).
    • name

      public String name()
    • getSampleRate

      public float getSampleRate()
      Convenience (not required by PASource).
    • 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
    • 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.
    • getMultiChannelBuffer

      public ddf.minim.MultiChannelBuffer getMultiChannelBuffer()
      Description copied from interface: PASource
      Optional access to an underlying MultiChannelBuffer, if this source is fundamentally buffer-backed (e.g., plain sample playback or a rendered granular "tape"). Implementations that are not backed by a fixed buffer (true streams, procedural sources, etc.) should simply return null.
      Specified by:
      getMultiChannelBuffer in interface PASource
    • 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
    • setGrainWindow

      public void setGrainWindow(ddf.minim.analysis.WindowFunction wf, int grainLenSamples)
      Specified by:
      setGrainWindow in interface PASource
    • 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).
    • toString

      public String toString()
      Overrides:
      toString in class Object