Add DX7 graph pitch LFO lowering

This commit is contained in:
Meta Vens 2026-05-14 19:27:04 +01:00
commit bfa70f9754
11 changed files with 129 additions and 28 deletions

View file

@ -399,6 +399,13 @@ public sealed class Dx7ReferenceParityTests
var effectiveMidiNote = Math.Clamp(60 + voice.Transpose - 24, 0, 127);
builder.AppendLine($" freq={F(graphFrequency)}");
builder.AppendLine($" gain={F(graphGain)}");
var pitchLfoDepth = Dx7SysEx.PitchLfoDepth(voice.Lfo);
if (pitchLfoDepth > 0)
{
builder.AppendLine($" vibrato={F(pitchLfoDepth)}");
builder.AppendLine($" vibrato_hz={F(Dx7SysEx.LfoFrequencyHz(voice.Lfo))}");
builder.AppendLine($" vibrato_delay={F(Dx7SysEx.LfoDelaySeconds(voice.Lfo))}");
}
builder.AppendLine();
foreach (var op in voice.Operators.OrderByDescending(op => op.Number))

View file

@ -419,6 +419,21 @@ public sealed class Dx7SysExTests
Assert.True(approximation.Envelope.Level3 >= 0.9f);
}
[Fact]
public void MapsPitchLfoIntoGraphVibrato()
{
var data = InitVoice("ANLFO", algorithm: 2, feedback: 7);
data[137] = 38;
data[138] = 33;
data[139] = 32;
data[143] = 1;
var voice = Dx7SysEx.ParseVoice(data);
Assert.InRange(Dx7SysEx.LfoFrequencyHz(voice.Lfo), 5.9f, 6.0f);
Assert.InRange(Dx7SysEx.LfoDelaySeconds(voice.Lfo), .23f, .24f);
Assert.InRange(Dx7SysEx.PitchLfoDepth(voice.Lfo), .0036f, .0037f);
}
private static byte[] InitVoice(string name, int algorithm, int feedback)
{
var data = new byte[Dx7SysEx.VoiceEditBufferLength];

View file

@ -305,12 +305,13 @@ public sealed class PatchScriptTests
public void ReadableOperatorGraphSyntaxParsesRoutesCarriersAndEnvelopes()
{
var patch = PatchScript.Parse("""
opgraph name=pair freq=220 gain=.2
opgraph name=pair freq=220 gain=.2 vibrato=.004 vibrato_hz=6 vibrato_delay=.2
operator name=op2 ratio=2 level=.8 env=ad:.01:.2
operator name=op1 ratio=1 level=1 env=adsr:.02:.1:.65:.3
route from=op2 to=op1 index=1.4
carrier name=op1
""");
var export = FaustEmitter.Emit(patch);
var graph = Assert.Single(patch.OperatorGraphs);
var op2 = graph.Operators.Single(op => op.Id == 2);
@ -319,6 +320,9 @@ public sealed class PatchScriptTests
Assert.Equal("pair", graph.Name);
Assert.Equal([1], graph.Carriers);
Assert.Single(graph.Edges);
Assert.Equal(.004f, graph.VibratoDepth, 5);
Assert.Equal(6, graph.VibratoHz);
Assert.Equal(.2f, graph.VibratoDelaySeconds, 5);
Assert.Equal(.01f, op2.Envelope.AttackSeconds, 5);
Assert.Equal(.2f, op2.Envelope.DecaySeconds, 5);
Assert.Equal(.02f, op1.Envelope.AttackSeconds, 5);
@ -326,6 +330,8 @@ public sealed class PatchScriptTests
Assert.Equal(.65f, op1.Envelope.SustainLevel, 5);
Assert.Equal(.3f, op1.Envelope.ReleaseSeconds, 5);
Assert.Equal(.21f, op2.Note.GateSeconds, 5);
Assert.Contains("lfo_sin(6, 0.0)", export.Source);
Assert.Contains("clip01(age / max(0.0001, 0.2))", export.Source);
}
[Fact]