Approximate DX7 envelopes as ADSR

This commit is contained in:
Meta Vens 2026-05-13 16:55:30 +01:00
commit 82f99bc61d
9 changed files with 102 additions and 13 deletions

View file

@ -28,6 +28,17 @@ public sealed record Dx7Envelope(
int Level3,
int Level4);
public sealed record Dx7EnvelopeApproximation(
Envelope Envelope,
float GateSeconds,
string Notes)
{
public string ToScriptSpec() =>
$"env=adsr:{F(Envelope.AttackSeconds)}:{F(Envelope.DecaySeconds)}:{F(Envelope.SustainLevel)}:{F(Envelope.ReleaseSeconds)} gate={F(GateSeconds)}";
private static string F(float value) => value.ToString("0.######", System.Globalization.CultureInfo.InvariantCulture);
}
public sealed record Dx7Operator(
int Number,
Dx7Envelope Envelope,
@ -136,6 +147,26 @@ public static class Dx7SysEx
return ParseVoiceEditBuffer(data);
}
public static Dx7EnvelopeApproximation ApproximateEnvelope(Dx7Envelope envelope)
{
var l1 = Level(envelope.Level1);
var l2 = Level(envelope.Level2);
var l3 = Level(envelope.Level3);
var l4 = Level(envelope.Level4);
var peak = Math.Max(0.0001f, l1);
var attack = SegmentSeconds(envelope.Rate1, Math.Abs(l1 - l4));
var decay = SegmentSeconds(envelope.Rate2, Math.Abs(l1 - l2)) +
SegmentSeconds(envelope.Rate3, Math.Abs(l2 - l3));
var release = SegmentSeconds(envelope.Rate4, Math.Abs(l3 - l4));
var sustain = Math.Clamp(l3 / peak, 0, 1);
var gate = Math.Max(attack + decay, 0.02f);
return new Dx7EnvelopeApproximation(
new Envelope(attack, decay, sustain, release),
gate,
"Approximation: DX7 EG uses four rate/level segments; ADSR keeps one sustain level and a key-off release.");
}
public static Dx7VoiceBank ParseBank(ReadOnlySpan<byte> bytes)
{
var data = PackedBankData(bytes);
@ -350,6 +381,15 @@ public static class Dx7SysEx
Value(data, 144));
}
private static float Level(int value) => Math.Clamp(value, 0, 99) / 99f;
private static float SegmentSeconds(int rate, float distance)
{
var normalizedRate = Math.Clamp(rate, 0, 99) / 99f;
var scaledDistance = Math.Clamp(distance, 0, 1);
return 0.004f + 12f * scaledDistance * MathF.Pow(1 - normalizedRate, 2.2f);
}
private static byte[] VoiceEditBuffer(ReadOnlySpan<byte> bytes)
{
if (bytes.Length == VoiceEditBufferLength) return bytes.ToArray();

View file

@ -23,10 +23,11 @@ public static class ReferenceRebuildCatalog
[
new("carrier_operators", "1,2,3,4,5,6", "Six independent carriers map cleanly to six Aquarium voices."),
new("modulation_edge_count", "0", "No operator-to-operator modulation is needed for the additive shape."),
new("self_feedback_operators", "6", "Approximated with fold/drive on the highest partial.")
new("self_feedback_operators", "6", "Approximated with fold/drive on the highest partial."),
new("operator_envelope_approximation", "DX7 EG -> ADSR", "DX7 four-rate/four-level envelopes can now be lowered to labeled ADSR approximations.")
],
[
new("operator_envelopes", "per-operator four-stage DX7 EG", "Aquarium now has ADSR envelopes, but not DX7 rate/level envelopes."),
new("operator_envelope_exactness", "per-operator four-stage DX7 EG", "Aquarium has an ADSR approximation helper, not exact DX7 rate/level envelope execution."),
new("output_compensation", "algorithm ROM COM", "Aquarium voice gains are explicit and not derived from DX7 COM scaling.")
],
"This is the honest easy case: DX7 algorithm 32 is mostly additive synthesis, so the current voice DSL can represent the carrier layout without pretending to own a full operator graph."),
@ -40,11 +41,12 @@ public static class ReferenceRebuildCatalog
new("carrier_operators", "1,3", "Represented as carriers in a first-class Aquarium operator graph."),
new("modulation_edges", "6->5,4+5->3,2->1", "Represented as explicit operator edges in the graph."),
new("feedback_sources", "4", "Represented as operator-local feedback approximation on operator 4."),
new("runtime_macros", "brightness,strike", "Field-site parameters expose useful sound controls without recompilation.")
new("runtime_macros", "brightness,strike", "Field-site parameters expose useful sound controls without recompilation."),
new("operator_envelope_approximation", "DX7 EG -> ADSR", "DX7 four-rate/four-level envelopes can now be lowered to labeled ADSR approximations.")
],
[
new("dx7_feedback_register", "one-sample feedback register", "Aquarium operator feedback currently uses a smoothed self-reference approximation, not exact DX7 feedback register timing."),
new("operator_envelopes", "independent DX7 rate/level envelopes", "Aquarium has simpler per-voice envelopes, not per-operator EGs.")
new("operator_envelope_exactness", "independent DX7 rate/level envelopes", "Aquarium has per-operator ADSR approximation, not exact DX7 EG execution.")
],
"This patch is deliberately a pressure test. The new operator graph owns the topology; exact DX7 envelope and feedback-register behavior remain pressure for later refinement.")
];