nx_pitch_grade.nx
buildroot/runtime/nx_pitch_grade.nx
about
nx_pitch_grade.nx -- AUDIO arc, singing-tutor thread: grade how on-pitch a
sung/spoken note is against a target note. Composes the rung-0 F0 detector
(nx_pitch) -- "am I on the right note?" is exactly target-F0 vs measured-F0.
cents error = 1200 * log2(f_meas / f_target). We avoid a runtime log by the
first-order form cents ~= (1200/ln2) * (f_meas - f_target) / f_target
= 1731 * (f_meas - f_target) / f_target
The SIGN is always exact (sharp vs flat), and the MAGNITUDE is accurate to a
few cents inside the tuning regime (|err| < ~100 cents) -- which is the regime
a tuner cares about. A later rung can swap in fx_log2 for wide-range exactness.
nx_pitch_grade(pcm,start,win,fs,min_lag,max_lag,target_hz,out) -> cents
out[0] = verdict (PG_ON / PG_FLAT / PG_SHARP / PG_NOPITCH)
out[1] = measured F0 (Hz)
license_tier: ORIGINAL
module: nishi-core.audio.pitch_grade
depends: nishi-core.audio.pitch
capability: AUDIO_PITCH_GRADE
dependencies 1 imports · 1 importers
imports: nx_pitch.nx
imported by: nx_pitch_grade_gate.nx
structs
| none |
consts
| 22 | const PG_TOL_CENTS: i64 = 25 // within +-25 cents = on pitch |
| 23 | const PG_CENTS_K: i64 = 1731 // round(1200 / ln2) |
| 24 | const PG_ON: i64 = 0 |
| 25 | const PG_FLAT: i64 = 1 |
| 26 | const PG_SHARP: i64 = 2 |
| 27 | const PG_NOPITCH: i64 = 3 |
functions
| 29 | func nx_pitch_grade(pcm: *u8, start: i64, win: i64, fs: i64, |