Day 14 of ∞All days

Tuesday, 17 November 2026

Raga Bhairav, a just-intonation reading

Bhairav, first expedition: a timbre where 6 of 6 steps land in consonance (an ordinary instrument: 3; Sethares' construction: 4).

The dawn raga of flattened second and sixth, read in just intonation.

The numbers

An ordinary instrument
3 of 6 steps land
Sethares’ construction
4 of 6 steps land
Tonight’s search
6 of 6 steps land, a new record
The rule it found
Add a high‑frequency amplitude boost to raise spectral centroid and richness without increasing roughness.
Programs tried
76 programs, 63 valid, across 12 generations
Also works for
Kafi (5 of 6), Malkauns (3 of 4)
The piece
Bhairav, First Light

Tonight’s film

Read the program
const PARAMS = 8; // [count, tilt, stretch, snapTol, anchorAmp, cbThresh, boostStart, boostFactor]

function timbre(target, p) {
  // ---------- knobs ----------
  const count   = 4 + Math.round(p[0] * 10);          // 4‑14 stretched partials
  const tilt    = 0.5 + 1.5 * p[1];                    // amplitude roll‑off
  const stretch = 0.9 + 0.2 * p[2];                    // harmonic stretch exponent
  const snapTol = 0.02 + 0.08 * p[3];                 // relative snap tolerance
  const anchorAmp = 0.05 + 0.25 * p[4];               // amplitude of added anchors
  const cbThresh = 0.01 + 0.04 * p[5];                // critical‑band distance threshold
  const boostStart = 3 + 7 * p[6];                    // ratio where high‑freq boost begins (3‑10)
  const boostFactor = 0.0 + 0.5 * p[7];               // max extra gain for highest partial (0‑0.5)

  const MAX_RATIO = 40;

  // ---------- all scale ratios up to 40:1 ----------
  const notes = [1];
  let period = 1;
  while (period * target.period <= MAX_RATIO) {
    period *= target.period;          // next period (e.g., octave)
    notes.push(period);               // tonic of that period
    for (const step of target.steps) {
      const r = period * step;
      if (r <= MAX_RATIO) notes.push(r);
    }
  }
  notes.sort((a, b) => a - b);

  // ---------- stretched (inharmonic) series ----------
  const partials = [{ ratio: 1, amp: 1 }]; // fundamental
  for (let k = 2; k <= count; k++) {
    let r = Math.pow(k, stretch);
    // nearest scale ratio
    let best = r, bestDist = Infinity;
    for (const n of notes) {
      const d = Math.abs(r - n);
      if (d < bestDist) {
        bestDist = d;
        best = n;
      }
    }
    // snap if within tolerance
    if (bestDist / best < snapTol) r = best;
    const amp = 1 / Math.pow(k, tilt);
    partials.push({ ratio: r, amp });
  }

  // ---------- add anchor partials on uncovered scale steps ----------
  const anchorThresh = 0.04; // relative distance to decide “missing”
  for (const n of notes) {
    if (n === 1) continue; // fundamental already present
    if (partials.length >= 32) break;
    let minRel = Infinity;
    for (const pt of partials) {
      const rel = Math.abs(pt.ratio - n) / n;
      if (rel < minRel) minRel = rel;
    }
    if (minRel > anchorThresh) {
      partials.push({ ratio: n, amp: anchorAmp });
    }
  }

  // ---------- critical‑band aware amplitude reduction ----------
  for (let i = 0; i < partials.length; i++) {
    let minRel = Infinity;
    const ri = partials[i].ratio;
    for (let j = 0; j < partials.length; j++) {
      if (i === j) continue;
      const rel = Math.abs(partials[j].ratio - ri) / ri;
      if (rel < minRel) minRel = rel;
    }
    if (minRel < cbThresh) {
      const factor = minRel / cbThresh; // fade to zero at zero distance
      partials[i].amp *= factor;
    }
  }

  // ---------- high‑frequency boost (new idea) ----------
  for (const pt of partials) {
    if (pt.ratio > boostStart) {
      const relPos = (pt.ratio - boostStart) / (MAX_RATIO - boostStart);
      pt.amp *= 1 + boostFactor * relPos;
    }
  }

  // ---------- normalise, enforce fundamental rule ----------
  let maxAmp = 0;
  for (const pt of partials) if (pt.amp > maxAmp) maxAmp = pt.amp;
  if (maxAmp > 0) {
    for (const pt of partials) pt.amp /= maxAmp; // now max = 1
  }
  // fundamental must be ≥20 % of loudest
  const fund = partials[0];
  if (fund.amp < 0.2) fund.amp = 0.2;

  // ---------- keep ≤32 loudest partials ----------
  partials.sort((a, b) => b.amp - a.amp);
  if (partials.length > 32) partials.length = 32;

  // ---------- ensure at least six audible partials ----------
  const audible = partials.filter(pt => pt.amp >= 0.08);
  if (audible.length < 6) {
    const needed = 6 - audible.length;
    for (let i = partials.length - 1; i >= 0 && needed > 0; i--) {
      if (partials[i].amp < 0.08) {
        partials[i].amp = 0.08;
        needed--;
      }
    }
  }

  return partials;
}

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.