Module waveform

Source
Expand description

Audio waveform peaks per (file, audio stream): computed once on a background thread (decoding the whole stream through an AudioSource), cached in memory and on disk under Settings::cache_dir() (key = hash of path + file size + mtime + stream). PEAKS_PER_SEC buckets of mono (min, max).

StructsΒ§

Peaks
State πŸ”’
WaveformCache

ConstantsΒ§

PEAKS_PER_SEC

FunctionsΒ§

cache_file πŸ”’
compute_peaks πŸ”’
Sequentially decode source in 4800-frame blocks into 10 ms mono (min, max) buckets. Stops at the first all-zero block at/after duration (so an unknown duration of 0 stops at the first silent block).
load_or_compute πŸ”’
Disk cache first; else decode the whole stream (empty Peaks when the stream can’t be opened).
mem_key πŸ”’
ponytail: 64-bit hash as the map key so the per-frame lookup allocates nothing β€” collisions are astronomically unlikely.