Member Junction
    Preparing search index...
    • Downsamples a raw mono sample buffer into barCount per-bucket amplitudes and normalizes the result to 0..1 (the loudest bucket becomes 1).

      The samples are partitioned into barCount contiguous, (near-)equal buckets in index order; each bucket is reduced to one amplitude via aggregation:

      • 'max-abs' (default) — the maximum absolute sample in the bucket (crisp peaks),
      • 'rms' — the root-mean-square of the bucket (smoother, energy-weighted).

      Edge cases:

      • empty / null input → an array of barCount zeros,
      • fewer samples than bars → every sample still lands in a bucket; trailing empty buckets are 0 (no out-of-bounds reads),
      • a silent or constant-zero buffer → all zeros (normalization is skipped when the peak is 0, so we never divide by zero).

      Parameters

      • samples: number[] | Float32Array<ArrayBufferLike> | null | undefined

        raw mono channel data (e.g. AudioBuffer.getChannelData(0))

      • barCount: number = DEFAULT_WAVEFORM_BARS

        number of output bars (clamped to >= 1)

      • aggregation: WaveformAggregation = 'max-abs'

        per-bucket reducer (default 'max-abs')

      Returns number[]

      a barCount-length array of normalized 0..1 peaks