Add DX7 algorithm topology metadata

This commit is contained in:
Meta Vens 2026-05-13 00:49:53 +01:00
commit fec6c60096
6 changed files with 246 additions and 13 deletions

View file

@ -56,6 +56,28 @@ public sealed record Dx7Lfo(
Dx7LfoWaveform Waveform,
int PitchModulationSensitivity);
public sealed record Dx7AlgorithmRomStep(
int Operator,
int TargetOperator,
int Selector,
bool FeedbackRegisterWrite,
int MemoryRegisterMode,
int OutputCompensation);
public sealed record Dx7ModulationEdge(
IReadOnlyList<int> SourceOperators,
int TargetOperator,
string Kind);
public sealed record Dx7AlgorithmTopology(
int Algorithm,
IReadOnlyList<int> CarrierOperators,
IReadOnlyList<Dx7ModulationEdge> ModulationEdges,
IReadOnlyList<int> FeedbackSourceOperators,
IReadOnlyList<int> SelfFeedbackOperators,
IReadOnlyList<int> DelayedFeedbackTargets,
IReadOnlyList<Dx7AlgorithmRomStep> RomSteps);
public sealed record Dx7Voice(
string Name,
IReadOnlyList<Dx7Operator> Operators,
@ -77,6 +99,7 @@ public sealed record Dx7Voice(
public IReadOnlyList<ReferenceFeature> Features()
{
var topology = Dx7SysEx.AlgorithmTopology(Algorithm);
var enabledOperators = Operators.Count(op => op.OutputLevel > 0);
var loudest = Operators.OrderByDescending(op => op.OutputLevel).First();
return
@ -84,7 +107,11 @@ public sealed record Dx7Voice(
new("operator_count", Operators.Count.ToString(), "DX7 voices use six operators."),
new("enabled_operator_count", enabledOperators.ToString(), "Operators with non-zero output level."),
new("algorithm", Algorithm.ToString(), "DX7 algorithm number, 1-32."),
new("carrier_operators", string.Join(",", topology.CarrierOperators), "Operators routed to the audio output."),
new("modulation_edge_count", topology.ModulationEdges.Count.ToString(), "Number of extracted algorithm modulation edges."),
new("feedback", Feedback.ToString(), "Global DX7 feedback level, 0-7."),
new("feedback_sources", string.Join(",", topology.FeedbackSourceOperators), "Operators that write the DX7 feedback register in this algorithm."),
new("self_feedback_operators", string.Join(",", topology.SelfFeedbackOperators), "Operators with direct self-feedback paths."),
new("oscillator_sync", OscillatorSync ? "on" : "off"),
new("lfo_waveform", Lfo.Waveform.ToString()),
new("lfo_pitch_mod_depth", Lfo.PitchModulationDepth.ToString()),
@ -125,6 +152,83 @@ public static class Dx7SysEx
public static ReferenceSource SourceForBytes(string uri, string license, ReadOnlySpan<byte> bytes, string notes = "") =>
new("dx7-sysex", uri, license, Convert.ToHexString(SHA256.HashData(bytes)).ToLowerInvariant(), notes);
public static Dx7AlgorithmTopology AlgorithmTopology(int algorithm)
{
if (algorithm is < 1 or > 32)
{
throw new ArgumentOutOfRangeException(nameof(algorithm), algorithm, "DX7 algorithm must be 1-32");
}
var steps = AlgorithmRom[algorithm - 1]
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
.Select((entry, index) => ParseAlgorithmStep(operatorNumber: 6 - index, entry))
.ToList();
var carrierOperators = steps
.Where(step => step.OutputCompensation > 0)
.Select(step => step.TargetOperator)
.Order()
.ToList();
if (carrierOperators.Count == 0)
{
carrierOperators.Add(1);
}
var memory = new SortedSet<int>();
var feedbackSources = new SortedSet<int>();
var selfFeedback = new SortedSet<int>();
var delayedFeedbackTargets = new SortedSet<int>();
var edges = new List<Dx7ModulationEdge>();
foreach (var step in steps)
{
var nextMemory = step.MemoryRegisterMode switch
{
0 => [],
1 => [step.Operator],
2 => new SortedSet<int>(memory),
3 => new SortedSet<int>(memory.Concat([step.Operator])),
_ => new SortedSet<int>(memory)
};
switch (step.Selector)
{
case 1:
edges.Add(new Dx7ModulationEdge([step.Operator], step.TargetOperator, "direct"));
break;
case 2 when nextMemory.Count > 0:
edges.Add(new Dx7ModulationEdge(nextMemory.ToArray(), step.TargetOperator, "sum"));
break;
case 3 when memory.Count > 0:
edges.Add(new Dx7ModulationEdge(memory.ToArray(), step.TargetOperator, "delayed-sum"));
break;
case 4 when feedbackSources.Count > 0:
delayedFeedbackTargets.Add(step.TargetOperator);
edges.Add(new Dx7ModulationEdge(feedbackSources.ToArray(), step.TargetOperator, "delayed-feedback"));
break;
case 5:
selfFeedback.Add(step.TargetOperator);
edges.Add(new Dx7ModulationEdge([step.TargetOperator], step.TargetOperator, "self-feedback"));
break;
}
if (step.FeedbackRegisterWrite)
{
feedbackSources.Add(step.Operator);
}
memory = nextMemory;
}
return new Dx7AlgorithmTopology(
algorithm,
carrierOperators,
edges,
feedbackSources.ToArray(),
selfFeedback.ToArray(),
delayedFeedbackTargets.ToArray(),
steps);
}
public static byte[] UnpackVoice(ReadOnlySpan<byte> packed)
{
if (packed.Length != PackedVoiceLength)
@ -322,4 +426,61 @@ public static class Dx7SysEx
private static int Value(ReadOnlySpan<byte> data, int index) => SevenBit(data[index]);
private static byte SevenBit(byte value) => (byte)(value & 0x7F);
private static Dx7AlgorithmRomStep ParseAlgorithmStep(int operatorNumber, string entry)
{
var pieces = entry.Split('/');
if (pieces.Length != 3 || pieces[1].Length != 3)
{
throw new FormatException($"bad DX7 algorithm ROM entry `{entry}`");
}
var selector = int.Parse(pieces[0]);
var control = pieces[1];
return new Dx7AlgorithmRomStep(
operatorNumber,
operatorNumber == 1 ? 6 : operatorNumber - 1,
selector,
control[0] == '1',
int.Parse(control[1..], System.Globalization.NumberStyles.BinaryNumber),
int.Parse(pieces[2]));
}
// Extracted from Ken Shirriff's reverse-engineered DX7 OPS algorithm ROM table.
// Each row contains operator 6..1 entries as selector/feedback+memory/compensation.
private static readonly string[] AlgorithmRom =
[
"1/100/0 1/000/0 1/000/1 0/001/0 1/010/1 5/011/0",
"1/000/0 1/000/0 1/000/1 5/001/0 1/110/1 0/011/0",
"1/100/0 1/000/1 0/001/0 1/010/0 1/010/1 5/011/0",
"1/000/0 1/000/1 0/101/0 1/010/0 1/010/1 5/011/0",
"1/100/2 0/001/0 1/010/2 0/011/0 1/010/2 5/011/0",
"1/000/2 0/101/0 1/010/2 0/011/0 1/010/2 5/011/0",
"1/100/0 0/001/0 2/011/1 0/001/0 1/010/1 5/011/0",
"1/000/0 5/001/0 2/111/1 0/001/0 1/010/1 0/011/0",
"1/000/0 0/001/0 2/011/1 5/001/0 1/110/1 0/011/0",
"0/001/0 2/011/1 5/001/0 1/110/0 1/010/1 0/011/0",
"0/101/0 2/011/1 0/001/0 1/010/0 1/010/1 5/011/0",
"0/001/0 0/011/0 2/011/1 5/001/0 1/110/1 0/011/0",
"0/101/0 0/011/0 2/011/1 0/001/0 1/010/1 5/011/0",
"0/101/0 2/011/0 1/000/1 0/001/0 1/010/1 5/011/0",
"0/001/0 2/011/0 1/000/1 5/001/0 1/110/1 0/011/0",
"1/100/0 0/001/0 1/010/0 0/011/0 2/011/0 5/001/0",
"1/000/0 0/001/0 1/010/0 5/011/0 2/111/0 0/001/0",
"1/000/0 1/000/0 5/001/0 0/111/0 2/011/0 0/001/0",
"1/100/2 4/001/2 0/011/0 1/010/0 1/010/2 5/011/0",
"0/001/0 2/011/2 5/001/0 1/110/2 4/011/2 0/011/0",
"1/001/3 3/001/3 5/011/0 1/110/3 4/011/3 0/011/0",
"1/100/3 4/001/3 4/011/3 0/011/0 1/010/3 5/011/0",
"1/100/3 4/001/3 0/011/0 1/010/3 0/011/3 5/011/0",
"1/100/4 4/001/4 4/011/4 0/011/4 0/011/4 5/011/0",
"1/100/4 4/001/4 0/011/4 0/011/4 0/011/4 5/011/0",
"0/101/0 2/011/2 0/001/0 1/010/2 0/011/2 5/011/0",
"0/001/0 2/011/2 5/001/0 1/110/2 0/011/2 0/011/0",
"5/001/0 1/110/0 1/010/2 0/011/0 1/010/2 0/011/2",
"1/100/3 0/001/0 1/010/3 0/011/3 0/011/3 5/011/0",
"5/001/0 1/110/0 1/010/3 0/011/3 0/011/3 0/011/3",
"1/100/4 0/001/4 0/011/4 0/011/4 0/011/4 5/011/0",
"0/101/5 0/011/5 0/011/5 0/011/5 0/011/5 5/011/5"
];
}

View file

@ -11,3 +11,4 @@
{"kind":"runtime_patch_parameters","lesson":"Aquarium patch scripts now have first-class `param` declarations and patch/reference model contracts. Faust emission exposes declared parameters as smoothed hslider controls, but target binding is intentionally still absent and warned about; do not claim parameters shape sound until binding is designed.","source":"parameter contract implementation on 2026-05-13"}
{"kind":"runtime_patch_parameters","lesson":"Aquarium parameter binding uses Option B: numeric field values may reference declared parameters with `@/path`, producing exact field bindings such as `/voices/0/filter/lpf`. The field owns the meaning; the parameter owns the runtime value. Avoid target-routing parameter semantics unless a new authority is deliberately mapped.","source":"user rejected target binding as a landmine; field-site binding implemented on 2026-05-13"}
{"kind":"dx7_reference_path","lesson":"DX7 reference elaboration starts with structural extraction, not translation. The repo now parses 155-byte voice edit buffers, 128-byte packed voices, and 4104-byte packed 32-voice SysEx banks into neutral DX7 records with checksum validation and ReferencePatch features. Next pressure point is explicit algorithm topology metadata for carriers, modulation edges, and feedback edge location.","source":"DX7 SysEx parser slice on 2026-05-13"}
{"kind":"dx7_reference_path","lesson":"DX7 algorithm topology is now derived from the reverse-engineered OPS algorithm ROM table, not hand-drawn diagrams. Topology exposes carrier operators, modulation edges, feedback-register writers, self-feedback operators, delayed-feedback targets, and raw ROM steps. Use this as pressure evidence before adding an Aquarium operator graph layer.","source":"DX7 algorithm topology slice on 2026-05-13; Ken Shirriff OPS ROM table"}

View file

@ -13,6 +13,7 @@
"patch parameter contracts",
"reference patch contracts",
"DX7 SysEx structural parsing",
"DX7 algorithm topology metadata",
"patch script parser",
"SFXR atoms and parameter mapping",
"analysis/comparison metrics",
@ -45,8 +46,8 @@
"rule": "Add DSL abstractions only when reference rebuilds prove the missing invariant."
},
"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, and ReferencePatch features.",
"next": "Add algorithm topology metadata for algorithms 1-32 before translating DX7 voices into Aquarium DSL."
"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, and algorithm topology from the reverse-engineered OPS algorithm ROM table.",
"next": "Rebuild tiny DX7-style references in Aquarium DSL and use topology mismatches to decide whether an operator graph layer is needed."
},
"runtime_parameters": {
"rule": "Patch parameters are runtime controls, not compile-time constants.",
@ -56,7 +57,7 @@
},
"last_verified": {
"command": "dotnet test AquariumSynthCSharp.slnx --no-restore",
"result": "28 passed",
"commit": "pending DX7 SysEx reference parsing commit"
"result": "31 passed",
"commit": "pending DX7 algorithm topology commit"
}
}

View file

@ -7,6 +7,19 @@ the synth library while Aquarium work continues elsewhere.
Completed this slice:
- Added DX7 algorithm topology metadata for algorithms 1-32 using Ken
Shirriff's reverse-engineered OPS algorithm ROM table.
- `Dx7SysEx.AlgorithmTopology` now exposes carrier operators, modulation
edges, feedback-register writers, direct self-feedback operators,
delayed-feedback targets, and raw ROM steps.
- `Dx7Voice.Features()` now emits `carrier_operators`,
`modulation_edge_count`, `feedback_sources`, and
`self_feedback_operators`.
- Representative tests cover algorithm 8, algorithm 16, and algorithm 32.
- Verified with `dotnet test AquariumSynthCSharp.slnx --no-restore`: 31 passed.
Previous slice:
- Added `Dx7SysEx` records and parsing for DX7 voice edit buffers, packed
128-byte voices, and packed 32-voice SysEx banks.
- Extracted six operators, envelopes, algorithm, feedback, oscillator sync,
@ -16,7 +29,7 @@ Completed this slice:
- Checksum validation rejects bad wrapped SysEx payloads.
- Verified with `dotnet test AquariumSynthCSharp.slnx --no-restore`: 28 passed.
Previous slice:
Earlier slice:
- Added explicit `PatchParameter` contracts: stable path, label, default, min,
max, step, unit, automation-rate notes, and notes.
@ -35,9 +48,8 @@ Previous slice:
Next likely slice:
- Add explicit DX7 algorithm topology metadata: carrier operators, modulator
edges, and feedback edge location for algorithms 1-32. Keep it as reference
topology data, not Aquarium graph translation yet.
- Rebuild one or two small DX7-style sounds in Aquarium DSL.
- Compare those rebuilds against DX7 topology features and document the missing
graph concepts before adding any new DSL shape.
- Keep tests focused on structure first, then add rendered audio comparison once
the render path is explicit.

View file

@ -1,6 +1,6 @@
project: AquariumSynthCSharp
spine_version: 1
updated: 2026-05-13T00:43:44+01:00
updated: 2026-05-13T00:49:07+01:00
prime_directive: >
Build coherent synth machinery. References exist to reveal missing structure,
@ -41,10 +41,10 @@ reference_targets:
priority: 1
purpose: "Structured FM/operator graph pressure test."
source: "https://github.com/asb2m10/dexed"
status: "DX7 SysEx parser and structural feature extraction exist; topology edge maps are next."
status: "DX7 SysEx parser and algorithm topology extraction exist; tiny Aquarium DSL rebuilds are next."
first_slice:
- "Add algorithm topology metadata for carrier operators, modulator edges, and feedback edge location."
- "Rebuild two small DX7-style references in Aquarium DSL."
- "Compare rebuilds against DX7 topology features and document missing graph concepts."
zynaddsubfx:
priority: 2
purpose: "Additive, subtractive, PAD, formant, kit, and layered-instrument pressure test."
@ -78,8 +78,8 @@ reference_targets:
next_agent_start_here:
recommended_first_task: >
Add DX7 algorithm topology metadata for algorithms 1-32, then rebuild one
or two tiny DX7-style references in Aquarium DSL. Do not import a giant
Rebuild one or two tiny DX7-style references in Aquarium DSL, using the
parsed DX7 topology features as pressure evidence. Do not import a giant
bank.
must_read:
- AGENTS.md
@ -92,6 +92,14 @@ next_agent_start_here:
- "dotnet test AquariumSynthCSharp.slnx --no-restore"
completed_slices:
- date: 2026-05-13
summary: >
Added DX7 algorithm topology metadata for algorithms 1-32 from the
reverse-engineered OPS algorithm ROM table. Topology exposes carrier
operators, modulation edges, feedback-register writers, self-feedback
operators, delayed-feedback targets, raw ROM steps, and ReferencePatch
feature pressure.
verification: "dotnet test AquariumSynthCSharp.slnx --no-restore: 31 passed"
- date: 2026-05-13
summary: >
Added DX7 SysEx records and parsing for 155-byte voice edit buffers,

View file

@ -87,6 +87,8 @@ public sealed class Dx7SysExTests
Assert.Contains(reference.Features, feature => feature.Name == "operator_count" && feature.Value == "6");
Assert.Contains(reference.Features, feature => feature.Name == "algorithm" && feature.Value == "12");
Assert.Contains(reference.Features, feature => feature.Name == "feedback" && feature.Value == "4");
Assert.Contains(reference.Features, feature => feature.Name == "carrier_operators");
Assert.Contains(reference.Features, feature => feature.Name == "modulation_edge_count");
}
[Fact]
@ -100,6 +102,54 @@ public sealed class Dx7SysExTests
Assert.Contains("checksum", exception.Message);
}
[Fact]
public void AlgorithmEightTopologyMatchesDocumentedExample()
{
var topology = Dx7SysEx.AlgorithmTopology(8);
Assert.Equal([1, 3], topology.CarrierOperators);
Assert.Contains(topology.ModulationEdges, edge =>
edge.Kind == "direct" &&
edge.TargetOperator == 5 &&
edge.SourceOperators.SequenceEqual([6]));
Assert.Contains(topology.ModulationEdges, edge =>
edge.Kind == "self-feedback" &&
edge.TargetOperator == 4 &&
edge.SourceOperators.SequenceEqual([4]));
Assert.Contains(topology.ModulationEdges, edge =>
edge.Kind == "sum" &&
edge.TargetOperator == 3 &&
edge.SourceOperators.SequenceEqual([4, 5]));
Assert.Contains(topology.ModulationEdges, edge =>
edge.Kind == "direct" &&
edge.TargetOperator == 1 &&
edge.SourceOperators.SequenceEqual([2]));
Assert.Contains(4, topology.FeedbackSourceOperators);
Assert.Equal([4], topology.SelfFeedbackOperators);
}
[Fact]
public void AlgorithmSixteenFallsBackToSingleCarrierOperatorOne()
{
var topology = Dx7SysEx.AlgorithmTopology(16);
Assert.Equal([1], topology.CarrierOperators);
Assert.Contains(topology.ModulationEdges, edge =>
edge.Kind == "sum" &&
edge.TargetOperator == 1 &&
edge.SourceOperators.Count >= 2);
}
[Fact]
public void AlgorithmThirtyTwoExposesSixCarrierAdditiveTopology()
{
var topology = Dx7SysEx.AlgorithmTopology(32);
Assert.Equal([1, 2, 3, 4, 5, 6], topology.CarrierOperators);
Assert.DoesNotContain(topology.ModulationEdges, edge => edge.Kind is "direct" or "sum" or "delayed-sum");
Assert.Equal([6], topology.SelfFeedbackOperators);
}
private static byte[] InitVoice(string name, int algorithm, int feedback)
{
var data = new byte[Dx7SysEx.VoiceEditBufferLength];