From 9a18aa6dbd6522dda0b3bff6d504e9c995ea9b65 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 14 May 2026 15:39:42 +0100 Subject: [PATCH] Lower DX7 fixed-frequency operators --- docs/dx7-calibration-plan.md | 10 ++++++-- src/AquariumSynth.Dsl/Dx7SysEx.cs | 17 +++++++++++-- state/evidence.jsonl | 1 + state/memory.json | 10 ++++---- state/scratch.md | 18 +++++++++++++ state/spine.yaml | 21 +++++++++++++--- .../Dx7ReferenceParityTests.cs | 25 +++++++++++++++++-- .../AquariumSynth.Dsl.Tests/Dx7SysExTests.cs | 19 ++++++++++++++ 8 files changed, 107 insertions(+), 14 deletions(-) diff --git a/docs/dx7-calibration-plan.md b/docs/dx7-calibration-plan.md index 513e4ab..3a66626 100644 --- a/docs/dx7-calibration-plan.md +++ b/docs/dx7-calibration-plan.md @@ -119,8 +119,14 @@ math is still fake in the places that matter perceptually. transpose byte, so `transpose=12` rendered one octave too high. Aquarium now uses `Dx7SysEx.NoteFrequencyHz(midiNote, transpose)`, where `24` is neutral. - - A first survey also tried `DX1 LEAD B`, `ANLGSYN 1`, `MELLOWSOLO`, and - `RES SYNTH1`; they were left out of the passing gate because listening and + - `ANLGSYN 1` exposed a second real pitch/frequency bug: DX7 fixed-frequency + operators were being lowered as fake note ratios. Aquarium now maps fixed + operators through the Dexed log-frequency formula and divides the absolute + Hz by the graph base frequency. This restores the low fixed-frequency + carrier/modulation buzz for op1/op3 instead of flattening the voice into + the wrong drone. + - A first survey also tried `DX1 LEAD B`, `MELLOWSOLO`, and `RES SYNTH1`; + they were left out of the passing gate because listening and log-mel/zero-crossing evidence do not justify calling them parity yet. Keep those failures as pressure for oscillator phase, feedback, and transient detail rather than padding the test with weak thresholds. diff --git a/src/AquariumSynth.Dsl/Dx7SysEx.cs b/src/AquariumSynth.Dsl/Dx7SysEx.cs index de2610d..a14ffb5 100644 --- a/src/AquariumSynth.Dsl/Dx7SysEx.cs +++ b/src/AquariumSynth.Dsl/Dx7SysEx.cs @@ -246,11 +246,11 @@ public static class Dx7SysEx : 6f / (outputStep.OutputCompensation + 1); } - public static float OperatorFrequencyRatio(Dx7Operator op, int midiNote = 60) + public static float OperatorFrequencyRatio(Dx7Operator op, int midiNote = 60, float baseFrequencyHz = 261.62558f) { if (op.FrequencyMode == Dx7FrequencyMode.Fixed) { - return Math.Max(0.5f, op.FrequencyCoarse); + return FixedOperatorFrequencyHz(op) / Math.Max(0.0001f, baseFrequencyHz); } var coarse = op.FrequencyCoarse == 0 ? 0.5f : op.FrequencyCoarse; @@ -258,6 +258,19 @@ public static class Dx7SysEx return coarse * fine * RatioModeDetuneFactor(op.Detune, midiNote); } + public static float FixedOperatorFrequencyHz(Dx7Operator op) + { + var coarse = Math.Clamp(op.FrequencyCoarse, 0, 31); + var fine = Math.Clamp(op.FrequencyFine, 0, 99); + var logFrequency = (4458616 * ((coarse & 3) * 100 + fine)) >> 3; + if (op.Detune != 7) + { + logFrequency += 13457 * (Math.Clamp(op.Detune, 0, 14) - 7); + } + + return MathF.Pow(2, logFrequency / (float)(1 << 24)); + } + public static float NoteFrequencyHz(int midiNote = 60, int transpose = 24) { var effectiveNote = Math.Clamp(midiNote + transpose - 24, 0, 127); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 19f15f5..cebb669 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -48,3 +48,4 @@ {"kind":"patch_library_taste","lesson":"Not every parity probe belongs in the patch library. Harsh project-authored DX7 calibration probes should stay in tests and ignored listening artifacts unless they are musically useful stock; the navigable .aqua library is for reusable inspiration, not measurement torture signals.","source":"User listening correction on 2026-05-14"} {"kind":"dx7_community_voice_parity","lesson":"Actual public-domain analog1.syx community voices are useful broader probes, but listening rejected the first loose gate. ANLGSYN 1, RES SYNTH1, DX1 LEAD B, and MELLOWSOLO should remain pressure until their timbre/zero-crossing mismatch is understood. Only Mooger and fixed Piano Bass are currently defensible rendered community parity targets.","source":"Community DX7 analog1.syx survey on 2026-05-14"} {"kind":"dx7_voice_transpose","lesson":"Piano Bass in analog1.syx proved imported DX7 voices must lower the voice transpose byte into graph frequency. Transpose 24 is neutral; transpose 12 lowers MIDI note 60 to 130.8128 Hz. Hardcoding 261.6256 made Piano Bass a full octave too high. After the fix, Piano Bass improves to log-mel 0.16180529, zero-crossing 0.905511, score 0.64267576. Do not call the broader analog1.syx survey passing; only Mooger and fixed Piano Bass are currently defensible.","source":"Piano Bass listening correction on 2026-05-14"} +{"kind":"dx7_fixed_frequency","lesson":"ANLGSYN 1 proved DX7 fixed-frequency operators must lower as absolute Hz divided by the graph base frequency, not as note ratios. Dexed fixed mode uses a log-frequency formula; op1 fixed 0/0 is about 1 Hz and op3 fixed 0/8 detune 14 is about 1.207 Hz, yielding ratios 0.007615 and 0.009227 against the transposed 130.8128 Hz graph base. This restores the low buzzing modulation and improves ANLGSYN 1 to log-mel 0.19427659, zero-crossing 0.94662774, score 0.659334.","source":"ANLGSYN 1 listening correction on 2026-05-14"} diff --git a/state/memory.json b/state/memory.json index abca36d..6627603 100644 --- a/state/memory.json +++ b/state/memory.json @@ -74,9 +74,9 @@ "rule": "Add DSL abstractions only when reference rebuilds prove the missing invariant. Do not consume references that cannot be backed by parity tests; parsing alone is inventory, not evidence of expressivity." }, "dx7_reference_path": { - "status": "DX7 SysEx parser extracts voice edit buffers, packed voices, packed 32-voice banks, six operators, envelopes, algorithm, feedback, oscillator sync, LFO, transpose, voice name, checksum validation, ReferencePatch features, algorithm topology from the reverse-engineered OPS algorithm ROM table, envelope-to-ADSR approximations, measured carrier output amplitude, isolated two-op modulation route scale, summed/cascaded route scale, calibrated feedback amount table, ratio detune lowering, voice transpose lowering, ROM COM output compensation, topology-aware route lowering, staged operator envelopes with per-segment curves, raw and block-interpolated DX7 envelope tracing, applied-envelope curved lowering, two Aquarium DSL rebuild attempts, first-class OperatorGraph support, public-domain SysEx fixture coverage, dexed-py reference rendering, project-authored Dexed patch rendering, Aquarium candidate rendering through Faust-generated C#, one thresholded rendered parity test for analog1.syx voice 13, a hard PRC SYNTH1 parity probe with listening WAV artifacts and log-mel <= 0.18, project-authored algorithm-8 summed-stack/cascade/summed-pair parity, rendered community parity for Mooger and fixed Piano Bass, and renderable delayed operator feedback.", - "lesson": "Algorithm 32's additive six-carrier shape maps cleanly to six Aquarium voices. Algorithm 8 justified OperatorGraph: operators, modulation edges, carriers, and feedback belong to a graph authority, not Voice fields. The first rendered parity rung is behavioral and sine-like, not exact DX7 operator execution. A harder algorithm-8 target exposed that feedback must be delayed recursion in Faust, not a direct cyclic self-reference. Static DX7 output-level approximation helped import/rebuild math but was mathematically wrong for carrier amplitude. A single-carrier Dexed sweep shows carrier amplitude follows 2^((outputLevel - 99) / 8). Isolated two-op DX7 FM maps full-level modulation to Aquarium route index 6.275; summed/cascaded algorithm-8 branches now use 6.0 after PRC listening, a project-authored combined stack probe, and split cascade/summed-pair probes showed lower values were under-bright. Feedback lowers through a fitted table instead of PRC-local constants. Ratio-mode detune belongs in operator frequency lowering. DX7 voice transpose belongs in graph base frequency: transpose 24 is neutral, transpose 12 lowers MIDI note 60 to 130.8128 Hz. ROM COM values carry output-count compensation; because the amplitude curve was fitted against algorithm 32, DX7 carriers scale by 6/(COM+1). Project-authored Dexed patch rendering now gives lawful calibration targets. Reusing the operator output curve for EG levels was tested and cut because it failed hard-target log-mel. Direct envelope tracing shows current linear `env=rl` cannot express DX7 EG spike/drop behavior. Dexed-style audio samples EG once per 64-sample block and interpolates applied gain, so raw EG parity alone is not audio parity. Staged operator envelopes now support linear/exponential segments and supranormal levels. `ApproximateAppliedRateLevelEnvelope` uses that surface and now picks the first near-peak before gate so slower rising modulators hit early instead of swelling late. PRC log-mel is down to 0.13874426 with RMS at unity; community voices beyond Mooger and fixed Piano Bass still expose timbre/zero-crossing mismatch and must not be called passing.", - "next": "Use the now-validated algorithm-8 route scale and transpose lowering as fixed inputs while isolating remaining community-voice zero-crossing/timbre mismatch, then expand to broader public-domain banks." + "status": "DX7 SysEx parser extracts voice edit buffers, packed voices, packed 32-voice banks, six operators, envelopes, algorithm, feedback, oscillator sync, LFO, transpose, voice name, checksum validation, ReferencePatch features, algorithm topology from the reverse-engineered OPS algorithm ROM table, envelope-to-ADSR approximations, measured carrier output amplitude, isolated two-op modulation route scale, summed/cascaded route scale, calibrated feedback amount table, ratio detune lowering, voice transpose lowering, fixed-frequency operator lowering, ROM COM output compensation, topology-aware route lowering, staged operator envelopes with per-segment curves, raw and block-interpolated DX7 envelope tracing, applied-envelope curved lowering, two Aquarium DSL rebuild attempts, first-class OperatorGraph support, public-domain SysEx fixture coverage, dexed-py reference rendering, project-authored Dexed patch rendering, Aquarium candidate rendering through Faust-generated C#, one thresholded rendered parity test for analog1.syx voice 13, a hard PRC SYNTH1 parity probe with listening WAV artifacts and log-mel <= 0.18, project-authored algorithm-8 summed-stack/cascade/summed-pair parity, rendered community parity for Mooger, Piano Bass, and ANLGSYN 1, and renderable delayed operator feedback.", + "lesson": "Algorithm 32's additive six-carrier shape maps cleanly to six Aquarium voices. Algorithm 8 justified OperatorGraph: operators, modulation edges, carriers, and feedback belong to a graph authority, not Voice fields. The first rendered parity rung is behavioral and sine-like, not exact DX7 operator execution. A harder algorithm-8 target exposed that feedback must be delayed recursion in Faust, not a direct cyclic self-reference. Static DX7 output-level approximation helped import/rebuild math but was mathematically wrong for carrier amplitude. A single-carrier Dexed sweep shows carrier amplitude follows 2^((outputLevel - 99) / 8). Isolated two-op DX7 FM maps full-level modulation to Aquarium route index 6.275; summed/cascaded algorithm-8 branches now use 6.0 after PRC listening, a project-authored combined stack probe, and split cascade/summed-pair probes showed lower values were under-bright. Feedback lowers through a fitted table instead of PRC-local constants. Ratio-mode detune belongs in operator frequency lowering. DX7 voice transpose belongs in graph base frequency: transpose 24 is neutral, transpose 12 lowers MIDI note 60 to 130.8128 Hz. DX7 fixed-frequency operators are absolute Hz, not note ratios; ANLGSYN 1 proved fixed op1/op3 must lower to ratios around 0.007615/0.009227 against a 130.8128 Hz graph base to preserve low buzzing modulation. ROM COM values carry output-count compensation; because the amplitude curve was fitted against algorithm 32, DX7 carriers scale by 6/(COM+1). Project-authored Dexed patch rendering now gives lawful calibration targets. Reusing the operator output curve for EG levels was tested and cut because it failed hard-target log-mel. Direct envelope tracing shows current linear `env=rl` cannot express DX7 EG spike/drop behavior. Dexed-style audio samples EG once per 64-sample block and interpolates applied gain, so raw EG parity alone is not audio parity. Staged operator envelopes now support linear/exponential segments and supranormal levels. `ApproximateAppliedRateLevelEnvelope` uses that surface and now picks the first near-peak before gate so slower rising modulators hit early instead of swelling late. PRC log-mel is down to 0.13874426 with RMS at unity; remaining community voices still expose timbre/zero-crossing mismatch and must not be called passing.", + "next": "Use the now-validated algorithm-8 route scale, transpose lowering, and fixed-frequency lowering as fixed inputs while isolating remaining community-voice timbre mismatch, then expand to broader public-domain banks." }, "note_and_envelope_model": { "rule": "Notes own frequency, gate duration, and host/MIDI source. Envelopes own ADSR level shape.", @@ -91,7 +91,7 @@ }, "last_verified": { "command": "AQUARIUM_DX7_PYTHON= dotnet test AquariumSynthCSharp.slnx --no-restore", - "result": "71 passed; Piano Bass transpose fixed and community gate narrowed to Mooger plus Piano Bass", - "commit": "pending DX7 transpose fix" + "result": "73 passed; ANLGSYN 1 fixed-frequency lowering restores low buzzing modulation and passes focused parity", + "commit": "pending DX7 fixed-frequency fix" } } diff --git a/state/scratch.md b/state/scratch.md index b12d9cb..4537619 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -15,6 +15,24 @@ Doctrine update: Completed this slice: +- Fixed DX7 fixed-frequency operator lowering after `ANLGSYN 1` exposed the + missing buzzing modulation. The old lowering treated fixed mode as a fake + note ratio, so fixed carriers op1/op3 became `0.5` ratio against the graph + frequency. Dexed treats fixed mode as absolute Hz. +- Added `Dx7SysEx.FixedOperatorFrequencyHz` using Dexed's fixed-mode + log-frequency formula and changed `OperatorFrequencyRatio` to return + `fixedHz / graphFrequency` for fixed operators. +- Fresh `ANLGSYN 1` candidate now lowers fixed op3 to ratio `.009227` and op1 + to `.007615` against `freq=130.8128`, instead of flattening both to `.5`. +- Added `PublicDomainDx7AnlgSyn1KeepsBuzzingModulationWhenInstalled` with + focused gates. Latest metrics: log-mel `.19427659`, envelope `.14924917`, + zero-crossing `.94662774`, centroid `.9182808`, score `.659334`. +- Verified with bundled Python/dexed-py: + `AQUARIUM_DX7_PYTHON= dotnet test AquariumSynthCSharp.slnx --no-restore`: + 73 passed. + +Previous slice: + - Fixed the `Piano Bass` octave bug. The parsed voice has `transpose=12`; the old generated Aquarium script hardcoded `freq=261.6256`, so it rendered an octave too high. `Dx7SysEx.NoteFrequencyHz(midiNote, transpose)` now treats diff --git a/state/spine.yaml b/state/spine.yaml index aae3fd9..9223521 100644 --- a/state/spine.yaml +++ b/state/spine.yaml @@ -1,6 +1,6 @@ project: AquariumSynthCSharp spine_version: 1 -updated: 2026-05-14T14:24:00+01:00 +updated: 2026-05-14T14:40:00+01:00 prime_directive: > Build coherent synth machinery. References exist to reveal missing structure, @@ -50,6 +50,7 @@ live_invariants: - DX7 feedback lowers through `Dx7SysEx.OperatorFeedbackAmount`; do not restore PRC-local `feedback * constant` folklore. - DX7 ratio-mode detune lowers through `Dx7SysEx.OperatorFrequencyRatio`; do not silently drop detune from operator graph scripts. - DX7 voice transpose lowers through `Dx7SysEx.NoteFrequencyHz`; transpose 24 is neutral, 12 is one octave down. Do not hardcode `freq=261.6256` for imported voices. + - DX7 fixed-frequency operators lower through `Dx7SysEx.FixedOperatorFrequencyHz` as absolute Hz divided by the graph base frequency; do not treat fixed mode as a note ratio. - DX7 algorithm output compensation lowers through ROM `COM` values relative to the algorithm-32 six-output baseline; do not restore PRC-local carrier scale tables. - DX7 route lowering is topology-aware: isolated direct branches use `OperatorModulationRouteIndex` (`6.275`); summed edges and direct edges feeding summed modulation use `SummedOperatorModulationRouteIndex` (`6.0`). - `SummedOperatorModulationRouteIndex` is backed by the hard PRC target, a project-authored algorithm-8 stack probe, and split cascade/summed-pair probes; do not restore the older under-bright `1.6` scale. @@ -126,8 +127,9 @@ next_agent_start_here: probes now back the 6.0 summed/cascaded route scale. Next pressure is residual PRC high-air/timbre mismatch and high zero-crossing mismatch on broader public-domain community voices before broad import. The community - gate is currently only `{ Mooger }` and fixed `Piano Bass`; do not describe - the other analog1.syx survey voices as passing. + gate now includes `{ Mooger }`, fixed `Piano Bass`, and fixed-frequency + `ANLGSYN 1`; do not describe the remaining analog1.syx survey voices as + passing. must_read: - AGENTS.md - docs/audio-doctrine.md @@ -140,6 +142,19 @@ next_agent_start_here: - "dotnet test AquariumSynthCSharp.slnx --no-restore" completed_slices: + - date: 2026-05-14 + summary: > + Fixed DX7 fixed-frequency operator lowering after listening caught + `ANLGSYN 1` losing its buzzing modulation and collapsing into the wrong + drone. `Dx7SysEx.FixedOperatorFrequencyHz` now follows Dexed's fixed-mode + log-frequency formula, and `OperatorFrequencyRatio` lowers fixed + operators as absolute Hz divided by the graph base frequency. In + `ANLGSYN 1`, fixed carriers op1/op3 now lower to ratios 0.007615 and + 0.009227 instead of the old fake 0.5. Added a focused parity test for + `ANLGSYN 1`; latest metrics improve to log-mel 0.19427659, envelope + 0.14924917, zero-crossing 0.94662774, centroid 0.9182808, score + 0.659334. + verification: "AQUARIUM_DX7_PYTHON= dotnet test AquariumSynthCSharp.slnx --no-restore: 73 passed" - date: 2026-05-14 summary: > Fixed DX7 voice transpose lowering after listening caught `Piano Bass` diff --git a/tests/AquariumSynth.Dsl.Tests/Dx7ReferenceParityTests.cs b/tests/AquariumSynth.Dsl.Tests/Dx7ReferenceParityTests.cs index 682c1a8..2876f5d 100644 --- a/tests/AquariumSynth.Dsl.Tests/Dx7ReferenceParityTests.cs +++ b/tests/AquariumSynth.Dsl.Tests/Dx7ReferenceParityTests.cs @@ -170,6 +170,25 @@ public sealed class Dx7ReferenceParityTests Assert.All(comparisons, item => Assert.True(item.Comparison.Score >= 0.6f, report)); } + [Fact] + public async Task PublicDomainDx7AnlgSyn1KeepsBuzzingModulationWhenInstalled() + { + var result = await RenderAndComparePublicDomainDx7VoiceAsync( + new CommunityDx7VoiceCase(7, "ANLGSYN 1", 0.65f, 1.0f, 0.25f)); + + if (result is null) + { + return; + } + + var report = $"{ParityReport(result.Value.Comparison)}{Environment.NewLine}artifacts: {result.Value.ArtifactDir}"; + + Assert.True(result.Value.Comparison.LogMelDistance <= 0.25f, report); + Assert.True(result.Value.Comparison.EnvelopeDistance <= 0.17f, report); + Assert.InRange(result.Value.Comparison.ZeroCrossingRatio, 0.8f, 1.2f); + Assert.True(result.Value.Comparison.Score >= 0.6f, report); + } + [Fact] public async Task ProjectAuthoredDx7AlgorithmEightSummedStackMeetsParityWhenInstalled() { @@ -354,7 +373,9 @@ public sealed class Dx7ReferenceParityTests builder.AppendLine(); builder.AppendLine("opgraph"); builder.AppendLine($" name={graphName}"); - builder.AppendLine($" freq={F(Dx7SysEx.NoteFrequencyHz(midiNote: 60, voice.Transpose))}"); + var graphFrequency = Dx7SysEx.NoteFrequencyHz(midiNote: 60, voice.Transpose); + var effectiveMidiNote = Math.Clamp(60 + voice.Transpose - 24, 0, 127); + builder.AppendLine($" freq={F(graphFrequency)}"); builder.AppendLine($" gain={F(graphGain)}"); builder.AppendLine(); @@ -363,7 +384,7 @@ public sealed class Dx7ReferenceParityTests var level = Dx7SysEx.ApproximateOperatorLevel(op).LinearLevel * Dx7SysEx.OperatorOutputCompensation(topology, op.Number); builder.AppendLine($"operator name=op{op.Number}"); - builder.AppendLine($" ratio={F(Dx7SysEx.OperatorFrequencyRatio(op, midiNote: Math.Clamp(60 + voice.Transpose - 24, 0, 127)))}"); + builder.AppendLine($" ratio={F(Dx7SysEx.OperatorFrequencyRatio(op, midiNote: effectiveMidiNote, baseFrequencyHz: graphFrequency))}"); builder.AppendLine($" level={F(level)}"); if (topology.SelfFeedbackOperators.Contains(op.Number)) { diff --git a/tests/AquariumSynth.Dsl.Tests/Dx7SysExTests.cs b/tests/AquariumSynth.Dsl.Tests/Dx7SysExTests.cs index c3887cf..6844978 100644 --- a/tests/AquariumSynth.Dsl.Tests/Dx7SysExTests.cs +++ b/tests/AquariumSynth.Dsl.Tests/Dx7SysExTests.cs @@ -270,6 +270,25 @@ public sealed class Dx7SysExTests Assert.InRange(Dx7SysEx.OperatorFrequencyRatio(flat, midiNote: 60), 0.9951f, 0.9952f); } + [Fact] + public void MapsDx7FixedFrequencyOperatorsToAbsoluteHertz() + { + var oneHertz = InitOperator( + frequencyMode: Dx7FrequencyMode.Fixed, + frequencyCoarse: 0, + frequencyFine: 0, + detune: 7); + var lowBuzz = InitOperator( + frequencyMode: Dx7FrequencyMode.Fixed, + frequencyCoarse: 0, + frequencyFine: 8, + detune: 14); + + Assert.InRange(Dx7SysEx.FixedOperatorFrequencyHz(oneHertz), 0.999f, 1.001f); + Assert.InRange(Dx7SysEx.FixedOperatorFrequencyHz(lowBuzz), 1.20f, 1.21f); + Assert.InRange(Dx7SysEx.OperatorFrequencyRatio(oneHertz, baseFrequencyHz: 130.8128f), 0.0076f, 0.0077f); + } + [Fact] public void AppliesDx7VoiceTransposeToRenderedNoteFrequency() {