Downsamples a raw mono sample buffer into barCount per-bucket amplitudes and normalizes the result to 0..1 (the loudest bucket becomes 1).
barCount
0..1
1
The samples are partitioned into barCount contiguous, (near-)equal buckets in index order; each bucket is reduced to one amplitude via aggregation:
aggregation
'max-abs'
'rms'
Edge cases:
0
raw mono channel data (e.g. AudioBuffer.getChannelData(0))
AudioBuffer.getChannelData(0)
number of output bars (clamped to >= 1)
>= 1
per-bucket reducer (default 'max-abs')
a barCount-length array of normalized 0..1 peaks
Downsamples a raw mono sample buffer into
barCountper-bucket amplitudes and normalizes the result to0..1(the loudest bucket becomes1).The samples are partitioned into
barCountcontiguous, (near-)equal buckets in index order; each bucket is reduced to one amplitude viaaggregation:'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:
barCountzeros,0(no out-of-bounds reads),0, so we never divide by zero).