Thursday, 19 November 2026
Raga Kafi, a just-intonation reading
Kafi, first expedition: a timbre where 5 of 6 steps land in consonance (an ordinary instrument: 3; Sethares' construction: 4).
A folk-rooted raga of spring, read in just intonation.
The numbers
- An ordinary instrument
- 3 of 6 steps land
- Sethares’ construction
- 4 of 6 steps land
- Tonight’s search
- 5 of 6 steps land, a new record
- The rule it found
- Shift each stretched harmonic toward the nearest scale‑step instead of adding a separate low‑amplitude scale‑aligned layer.
- Programs tried
- 76 programs, 62 valid, across 12 generations
- Also works for
- Bhairav (5 of 6)
- The piece
- Kafi, Spring Unfolding
Tonight’s film
Read the program
const PARAMS = 3; // [stretchFac, tiltFac, shiftFac]
function timbre(target, p) {
const clamp = (v, lo = 0, hi = 1) => Math.max(lo, Math.min(hi, v));
const stretch = 0.8 + 0.6 * clamp(p[0]); // 0.8 … 1.4
const tilt = 0.5 + 1.5 * clamp(p[1]); // 0.5 … 2.0
const shift = clamp(p[2]); // 0 … 1 (how far to pull toward scale)
const period = target.period; // usually 2
const notes = [1, ...target.steps]; // scale degrees inside one period
const maxRatio = 40;
const partials = [];
// number of backbone partials (including fundamental)
const count = 4 + Math.round(clamp(p[0]) * 12); // 4 … 16
for (let k = 1; k <= count; ++k) {
// fundamental kept exact
if (k === 1) {
partials.push({ ratio: 1, amp: 1 });
continue;
}
// stretched harmonic position
let ratio = Math.pow(k, stretch);
if (ratio > maxRatio) break;
// find nearest scale note (any octave)
let nearest = ratio;
let bestDist = Infinity;
for (const n of notes) {
const m = Math.round(Math.log(ratio / n) / Math.log(period));
const cand = n * Math.pow(period, m);
if (cand < 1 || cand > maxRatio) continue;
const d = Math.abs(Math.log(cand / ratio));
if (d < bestDist) {
bestDist = d;
nearest = cand;
}
}
// shift toward the nearest scale note
const logAdj = Math.log(ratio) - shift * Math.log(ratio / nearest);
const adjRatio = Math.exp(logAdj);
// amplitude decay
const amp = 1 / Math.pow(k, tilt);
partials.push({ ratio: adjRatio, amp });
}
// --- ensure fundamental is at least 20 % of the loudest ---
let maxAmp = 0;
for (const pt of partials) if (pt.amp > maxAmp) maxAmp = pt.amp;
const fund = partials.find(pt => Math.abs(pt.ratio - 1) < 1e-9);
if (fund && fund.amp < 0.2 * maxAmp) fund.amp = 0.2 * maxAmp;
// --- normalise amplitudes (peak = 1) ---
maxAmp = 0;
for (const pt of partials) if (pt.amp > maxAmp) maxAmp = pt.amp;
for (const pt of partials) pt.amp /= maxAmp;
// --- final clean‑up: clamp ratios, sort, limit to 32 partials ---
return partials
.map(pt => ({ ratio: Math.min(maxRatio, Math.max(1, pt.ratio)), amp: pt.amp }))
.sort((a, b) => a.ratio - b.ratio)
.slice(0, 32);
}Consonance here is measured with Sethares’ model of sensory dissonance, not by ear. A step lands when it sits at the bottom of a valley in the timbre’s dissonance curve. Perfect harmony is out of reach — pure fifths and thirds never close into one scale — which is why the search does not end.
Every morning, what the night found.
One email a day at 7am Singapore time, with the discovery, the music and the film.