Skip to content

Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.

rock: chords are an electric guitar (S4 ensemble, bridge pickup, clean DI) through a new amp + cab stage in the mix chain (mixDsp.ampSim: normalised DI, pre-EQ, 2x oversampled asymmetric drive, 4x12 cab curve, energy-matched), not string stabs; strings move to alternates; the lead guitar alternate is the neck-pickup electric through the amp. Any part can ask for the amp with opts.amp (drive)

Alex Greenshpun77c2df5f1e98
diff --git a/skills/anidoodle/engine/src/canvas-core/music/mixDsp.ts b/skills/anidoodle/engine/src/canvas-core/music/mixDsp.ts
index 95a165a..cfcb028 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/mixDsp.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/mixDsp.ts
@@ -61,6 +61,26 @@ export const saturate = (x: Float32Array, sr: number, drive: number, bias = 0, m
return x;
};
+/**
+ * Guitar amp + cab, in place on a stereo stem (a part with `opts.amp` = drive, 1 clean .. 8 high gain). The DI is
+ * normalised so the playing peak hits the same point of the curve whatever the fader, then: a tube-screamer style
+ * pre-EQ (HP 110 Hz, +3 dB at 750 Hz), 2x oversampled asymmetric saturation (even harmonics), a 4x12 cab curve
+ * (HP 80 Hz, +2 dB at 2.4 kHz, 12 dB/oct low-pass at 5 kHz) and the stem's energy matched back: the fader keeps the balance.
+ */
+export const ampSim = (L: Float32Array, R: Float32Array, sr: number, drive: number) => {
+ let pk = 0, e0 = 0; for (let i = 0; i < L.length; i++) { pk = Math.max(pk, Math.abs(L[i]), Math.abs(R[i])); e0 += L[i] * L[i] + R[i] * R[i]; }
+ if (pk < 1e-9 || drive <= 0) return;
+ const ref = 0.5 / pk;
+ for (const c of [L, R]) {
+ for (let i = 0; i < c.length; i++) c[i] *= ref;
+ for (const b of [Biquad.make(sr, "hp", 110, 0.7071), Biquad.make(sr, "peak", 750, 0.8, 3)]) b.run(c);
+ saturate(c, sr, drive, 0.12);
+ for (const b of [Biquad.make(sr, "hp", 80, 0.7071), Biquad.make(sr, "peak", 2400, 1.1, 2), Biquad.make(sr, "lp", 5000, 0.7071)]) b.run(c);
+ }
+ let e1 = 0; for (let i = 0; i < L.length; i++) e1 += L[i] * L[i] + R[i] * R[i];
+ if (e1 > 0) { const k = Math.sqrt(e0 / e1); for (let i = 0; i < L.length; i++) { L[i] *= k; R[i] *= k; } }
+};
+
// ---------------------------------------------------------------- compressor
export type CompOpts = { ratio: number; attackMs: number; releaseMs: number; kneeDb?: number; /** target gain reduction on the loud passages (p90 of GR while active); the threshold is solved for it */ targetGrDb: number; maxGrDb?: number };
/** Stereo-linked feed-forward compressor with auto threshold (solved so the loud passages see `targetGrDb`) and RMS makeup. Returns the measured GR stats. */
diff --git a/skills/anidoodle/engine/src/canvas-core/music/render.ts b/skills/anidoodle/engine/src/canvas-core/music/render.ts
index f3374b2..4dcf771 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/render.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/render.ts
@@ -15,7 +15,7 @@ import { pumpCurve, lofiStem, lofiMaster, LOFI_DUSTY } from "./lofiFx";
import { loudness, truePeak, stemBalance } from "./meter";
import { STYLES } from "./tables";
import { rng as mkRng } from "../core";
-import { eqChain, runEq, stereoPan, compress, saturate, bandWidth, smoothLimiter } from "./mixDsp";
+import { eqChain, runEq, stereoPan, compress, saturate, bandWidth, smoothLimiter, ampSim } from "./mixDsp";
import { reverb, type Space } from "./mixReverb";
import { mixProfile, partEq, ROLE_SEND, type MixProfile } from "./mixProfiles";
@@ -144,6 +144,7 @@ const renderV2 = (piece: Piece, sr: number, o: RenderOpts = {}): Rendered => {
if (pt.inst === "piano") { const old = !!o.piano, r = old ? renderPiano(keys, perf.pedal, sr, n, o.piano!, piece.seed + pi) : renderPianoV2(keys, perf.pedal, sr, n, pt.opts ?? {}, piece.seed + pi); sL = r.L; sR = r.R; if (old ? o.piano!.pedal : pt.opts?.pedal !== false) for (let i = 0; i < n; i++) haloL[i] += r.halo[i] * db(pt.gainDb ?? 0); }
else { const r = voice(pt, keys, sr, n, piece.seed * 101 + pi, kitCtx); sL = r.L; sR = r.R; }
if (lofi) lofiStem(lofi, pt.id, sL, sR, sr, keys.map((k) => k.t), piece.seed, period);
+ if (typeof pt.opts?.amp === "number") ampSim(sL, sR, sr, pt.opts.amp); // a guitar (or any DI) through the amp + cab
if (pump && dk!.parts.includes(pt.id)) for (let i = 0; i < n; i++) { sL[i] *= pump[i]; sR[i] *= pump[i]; }
// corrective EQ, then match the stem's RMS back (+-3 dB cap): EQ shapes the tone, the fader keeps the calibrated balance
// the stem meter reads the part as the fader set it (pre-EQ): the EQ is energy-neutral in the audible band, while stemRms
diff --git a/skills/anidoodle/engine/src/canvas-core/music/vocabMore.ts b/skills/anidoodle/engine/src/canvas-core/music/vocabMore.ts
index 802c7a7..2425227 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/vocabMore.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/vocabMore.ts
@@ -80,8 +80,9 @@ export const VOCAB_MORE: StyleVocab[] = [
melody: { range: "extremes: below C3 or above C6", contour: "a 2-3 note cell, often a semitone", density: "sparse, irregular", motif: "a semitone sigh or a tritone leap, repeated slower each time" },
arrangement: { shape: "drone -> pulse enters -> rising ostinato -> stinger on the hit -> silence -> aftermath drone", transitions: "cut to silence; a slow crescendo that stops short", endings: "unresolved: a held cluster, or a single low hit" }, avoid: "a major cadence, melody in the middle register, busy drums" },
{ id: "rock", name: "rock / band", atmosphere: "live-band energy: driven guitars, bass locked to the kick, a tight kit, maybe organ", tempo: [90, 160], meters: ["4/4", "6/8"], swing: [0.5, 0.52],
- palette: { chords: V("strings", "accomp", -6, { attack: 0.005, release: 0.08, bright: 2.0, width: 0.9, grid: true }, 0.2), lead: V("leadSynth", "melody", -2, { cut: 1400, env: 3000, square: 0.8, glide: 0.02 }, 0.25), bass: V("bass", "bass", -2, { kind: "pick", drive: 2.2 }), counter: V("organ", "color", -6, { bright: 1.2 }, 0.3), ...kit(0, 0.5) },
- alternates: { chords: { organ: V("organ", "accomp", -4, { bright: 1.3 }, 0.25), piano: V("piano", "accomp", -3, undefined, 0.2) }, lead: { guitar: V("guitar", "melody", 2, undefined, 0.2) } }, fx: {},
+ // chords: an electric guitar (ensemble.ts, bridge pickup, clean DI) driven through the mix chain's amp + cab (mixDsp ampSim), not string stabs
+ palette: { chords: V("guitar", "accomp", 4, { kind: "electric", pickup: "bridge", drive: 1, amp: 5, width: 0.8, grid: true }, 0.2), lead: V("leadSynth", "melody", -2, { cut: 1400, env: 3000, square: 0.8, glide: 0.02 }, 0.25), bass: V("bass", "bass", -2, { kind: "pick", drive: 2.2 }), counter: V("organ", "color", -6, { bright: 1.2 }, 0.3), ...kit(0, 0.5) },
+ alternates: { chords: { strings: V("strings", "accomp", -6, { attack: 0.005, release: 0.08, bright: 2.0, width: 0.9, grid: true }, 0.2), organ: V("organ", "accomp", -4, { bright: 1.3 }, 0.25), piano: V("piano", "accomp", -3, undefined, 0.2) }, lead: { guitar: V("guitar", "melody", 17, { kind: "electric", pickup: "neck", drive: 1, amp: 3.5 }, 0.3) } }, fx: {},
stemTargets: T({ ...std, chords: -19, lead: -16, bass: -17, counter: -23, kick: -13, snare: -17, hat: -27, perc: -26 }), calibrated: false, grooves: ["rock", "halfTime", "shuffle", "fourFloor"], moods: ["drive", "anger", "triumph", "joy", "heroic"],
harmony: { modes: ["mixolydian", "aeolian", "major", "blues", "dorian"], qualities: "power chords (root-5th-octave), triads, sus4", tendencies: "I-bVII-IV, i-bVI-bVII, riffs on the pentatonic, a chorus a 4th up", rhythm: "one chord per bar in verses, two in choruses", voicing: "power chords low (E2-E4), the bass doubling the root in 8ths", tension: "a riff held on the V, a stop before the chorus" },
melody: { range: "E3-A5", contour: "riff-based, pentatonic, strong beats", density: "8ths", motif: "a 1-2 bar riff that IS the song; the vocal-like lead answers it" },