Class OverlapUtil

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

public final class OverlapUtil extends Object
Utility methods for converting absolute sample spans to block-local overlap ranges.

OverlapUtil works with half-open sample intervals. A span is represented as [spanStart, spanEnd), and the current audio block is represented as [blockStart, blockStart + blockSize). The returned OverlapUtil.Slice gives the portion of the block that overlaps the span, expressed as indices into the current block.

The main use is granular rendering, where each grain occupies an absolute sample span but each audio callback renders only one block at a time. PABurstGranularSource uses this class to find the loop bounds for samples that belong to the active grain.

  • Constructor Details

    • OverlapUtil

      private OverlapUtil()
  • Method Details

    • computeBlockSlice

      public static OverlapUtil.Slice computeBlockSlice(long blockStart, int blockSize, long spanStart, long spanEnd)
      Computes the portion of the current block overlapped by an absolute sample span.

      The span and block are treated as half-open intervals. Touching endpoints do not count as overlap: for example, a span ending exactly at blockStart, or starting exactly at blockStart + blockSize, produces hasOverlap == false.

      For overlapping intervals, the returned indices are clamped to the range [0, blockSize] and are suitable as loop bounds into block-sized audio buffers.

      Parameters:
      blockStart - absolute sample index of the first sample in the block
      blockSize - number of samples in the block
      spanStart - absolute start of the span, inclusive
      spanEnd - absolute end of the span, exclusive
      Returns:
      a Slice indicating [startIndex, endIndex) within the block, or hasOverlap == false if there is no overlap