Skip to main content

Module hpcp

Module hpcp 

Source
Expand description

Harmonic Pitch Class Profile (HPCP) from spectral peaks.

This replaces the fake bin % 12 “chroma” that used to live in music.rs. Each spectral peak (freq_hz, magnitude) is mapped to a real pitch class via log2(f / ref_freq) — an equal division of the octave into n_pc bins — and its magnitude is accumulated into the nearest pitch-class bin.

§Tuning is a declared parameter, not a universal truth

  • ref_freq_hz is the tuning reference (the frequency of concert A, A4); it defaults to 440 Hz by convention only — the caller passes whatever the material actually uses (see super::tuning to estimate it). Nothing here hardcodes 440.
  • n_pc is the number of pitch classes per octave. 12 is the 12-TET case, but any n_pc ≥ 1 (e.g. 24 for quarter-tones, or a non-12 microtonal system) is accepted. Qualia is modality-first and does not privilege 12-TET.

§Pitch-class origin

Bin 0 is the C-equivalent origin: with the chromatic convention, A sits 0.75 of an octave (9 of 12 semitones) above C, so the reference A maps to bin 0.75 * n_pc and bin 0 corresponds to ref_freq * 2^(-0.75). This origin is a labelling convention for the 12-TET chromatic layout; the frequency→bin mapping itself is fully general for any n_pc.

Zero-heap: the profile is written into caller-owned out; no allocation.

Functions§

hpcp
Accumulate spectral peaks into a Harmonic Pitch Class Profile.