Map Zyn PAD detune and filter order
This commit is contained in:
parent
85245363b0
commit
01eea5eccf
10 changed files with 145 additions and 4 deletions
|
|
@ -224,9 +224,10 @@ public static class FaustEmitter
|
|||
var hpf = $"clip01({parameters.Expression(OwnerField(ownerPath, "filter/hpf"), voice.Filter.HighPass)} * (1.0 + {parameters.Expression(OwnerField(ownerPath, "filter/hpf_ramp"), voice.Filter.HighPassRamp)} * age * 2.0) + patch_mod_hpf + {hpfMod})";
|
||||
var hasResonance = voice.Filter.LowPassResonance > 0 || parameters.IsBound(OwnerField(ownerPath, "filter/resonance"));
|
||||
var resonance = parameters.Expression(OwnerField(ownerPath, "filter/resonance"), voice.Filter.LowPassResonance);
|
||||
var lowPassOrder = Math.Clamp(voice.Filter.LowPassOrder, 1, 12);
|
||||
var lowpass = hasResonance
|
||||
? $"fi.resonlp(max(20.0, {lpf} * 18000.0), 0.7 + clip01({resonance}) * 18.0, 1.0)"
|
||||
: $"fi.lowpass(1, max(20.0, {lpf} * 18000.0))";
|
||||
: $"fi.lowpass({lowPassOrder}, max(20.0, {lpf} * 18000.0))";
|
||||
|
||||
source.AppendLine($"{name}_freq = {frequency};");
|
||||
source.AppendLine($"{name}_osc = {oscillator};");
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ public sealed record Filter(
|
|||
float LowPass = 1,
|
||||
float LowPassRamp = 0,
|
||||
float LowPassResonance = 0,
|
||||
int LowPassOrder = 1,
|
||||
float HighPass = 0,
|
||||
float HighPassRamp = 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -441,6 +441,7 @@ public static class PatchScript
|
|||
GetBoundFloat(fields, line, 1, OwnerField(ownerPath, "filter/lpf"), "lpf", "l"),
|
||||
GetBoundFloat(fields, line, 0, OwnerField(ownerPath, "filter/lpf_ramp"), "lpf_ramp", "lr"),
|
||||
GetBoundFloat(fields, line, 0, OwnerField(ownerPath, "filter/resonance"), "resonance", "res"),
|
||||
GetBoundInt(fields, line, 1, OwnerField(ownerPath, "filter/lpf_order"), "lpf_order", "lpfo"),
|
||||
GetBoundFloat(fields, line, 0, OwnerField(ownerPath, "filter/hpf"), "hpf", "h"),
|
||||
GetBoundFloat(fields, line, 0, OwnerField(ownerPath, "filter/hpf_ramp"), "hpf_ramp", "hr")),
|
||||
Phaser = new Phaser(
|
||||
|
|
@ -707,6 +708,24 @@ public static class PatchScript
|
|||
params string[] keys) =>
|
||||
TryGetAny(fields, keys, out var value) ? ParseBoundFloat(value, line, fallback, fieldPath) : fallback;
|
||||
|
||||
private int GetBoundInt(
|
||||
IReadOnlyDictionary<string, string> fields,
|
||||
int line,
|
||||
int fallback,
|
||||
string fieldPath,
|
||||
params string[] keys)
|
||||
{
|
||||
if (!TryGetAny(fields, keys, out var value))
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
if (value.StartsWith('@'))
|
||||
{
|
||||
throw new PatchScriptException(line, $"parameter binding is not supported for integer field `{fieldPath}`");
|
||||
}
|
||||
return ParseInt(value, line);
|
||||
}
|
||||
|
||||
private float ParseBoundFloat(string value, int line, float fallback, string fieldPath)
|
||||
{
|
||||
if (!value.StartsWith('@'))
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ public sealed record SfxrParams
|
|||
Math.Clamp(LpfFreq, 0, 1),
|
||||
Math.Clamp(LpfRamp, -1, 1),
|
||||
Math.Clamp(LpfResonance, 0, 1),
|
||||
1,
|
||||
Math.Clamp(HpfFreq, 0, 1),
|
||||
Math.Clamp(HpfRamp, -1, 1)),
|
||||
Phaser = new Phaser(
|
||||
|
|
|
|||
|
|
@ -249,6 +249,8 @@ public static class ZynInstrumentReader
|
|||
MathF.Pow(0.1f, 3.0f * (1.0f - volume / 96.0f)),
|
||||
0.001f,
|
||||
1.5f);
|
||||
var frequency = pad.Element("FREQUENCY_PARAMETERS");
|
||||
var noteFrequencyHz = ZynPadPlaybackFrequency(frequency, playbackFrequencyHz);
|
||||
var attack = EnvelopeTime(envelope, "A_dt", 0.28f);
|
||||
var decay = EnvelopeTime(envelope, "D_dt", 0.42f);
|
||||
var release = EnvelopeTime(envelope, "R_dt", 1.2f);
|
||||
|
|
@ -259,6 +261,7 @@ public static class ZynInstrumentReader
|
|||
var position = ZynPositionText(pad.Element("HARMONIC_POSITION"));
|
||||
var filter = pad.Element("FILTER_PARAMETERS");
|
||||
var lowPass = ZynPadLowPass(filter);
|
||||
var lowPassOrder = ZynPadLowPassOrder(filter);
|
||||
var safeName = includeKitSuffix ? $"{safeBaseName}_{kitId}" : safeBaseName;
|
||||
var partialText = string.Join(",", harmonics.Select(partial => $"{F(partial.Ratio)}:{F(partial.Gain)}"));
|
||||
|
||||
|
|
@ -267,6 +270,7 @@ public static class ZynInstrumentReader
|
|||
matched.Add(new($"{featurePrefix}oscillator_base_function", IntParam(oscillator, "base_function", 0).ToString(CultureInfo.InvariantCulture), "Expanded Zyn OscilGen base function into harmonic partials before PAD synthesis."));
|
||||
matched.Add(new($"{featurePrefix}oscillator_spectrum_adjust", $"{IntParam(oscillator, "spectrum_adjust_type", 0)}:{IntParam(oscillator, "spectrum_adjust_par", 64)}", "Applied Zyn OscilGen spectrum adjustment to generated harmonic partials."));
|
||||
matched.Add(new($"{featurePrefix}table_root", F(tableRootFrequencyHz), "Root frequency comes from the Zyn oracle generated sample basefreq."));
|
||||
matched.Add(new($"{featurePrefix}note_frequency", F(noteFrequencyHz), "Mapped Zyn PAD coarse/fine detune into Aquarium table playback frequency."));
|
||||
matched.Add(new($"{featurePrefix}volume", volume.ToString(CultureInfo.InvariantCulture), "Mapped PAD amplitude volume into Aquarium layer gain."));
|
||||
matched.Add(new($"{featurePrefix}bandwidth", bandwidth.ToString(CultureInfo.InvariantCulture), "Mapped Zyn PAD bandwidth into Aquarium spectral table generation."));
|
||||
matched.Add(new($"{featurePrefix}bandwidth_scale", bandwidthScale.ToString(CultureInfo.InvariantCulture), "Mapped Zyn PAD bandwidth scaling exponent selection."));
|
||||
|
|
@ -275,14 +279,15 @@ public static class ZynInstrumentReader
|
|||
if (lowPass < 1)
|
||||
{
|
||||
matched.Add(new($"{featurePrefix}filter_lpf", F(lowPass), "Mapped static Zyn PAD global low-pass frequency into Aquarium layer filtering."));
|
||||
matched.Add(new($"{featurePrefix}filter_lpf_order", lowPassOrder.ToString(CultureInfo.InvariantCulture), "Mapped Zyn analog LP1/LP2 and stage count into Aquarium low-pass order."));
|
||||
}
|
||||
if (filter is not null)
|
||||
{
|
||||
missing.Add(new($"{featurePrefix}filter_modulation", "present", "Filter envelope/LFO lowering remains separate pressure."));
|
||||
}
|
||||
|
||||
script.AppendLine($"layer name={safeName} engine=pad gain={F(layerGain)} lpf={F(lowPass)} env=rl rates={F(attack)},{F(decay)},1,{F(release)} levels=1,1,1,0 curves=lin,lin,lin,lin gate=1.5");
|
||||
script.AppendLine($"spectrum layer={safeName} root={F(tableRootFrequencyHz)} freq={F(playbackFrequencyHz)} spread=0 zyn_mode={mode} zyn_bandwidth={bandwidth} zyn_bwscale={bandwidthScale} zyn_profile={profile} zyn_position={position} partials={partialText}");
|
||||
script.AppendLine($"layer name={safeName} engine=pad gain={F(layerGain)} lpf={F(lowPass)} lpf_order={lowPassOrder} env=rl rates={F(attack)},{F(decay)},1,{F(release)} levels=1,1,1,0 curves=lin,lin,lin,lin gate=1.5");
|
||||
script.AppendLine($"spectrum layer={safeName} root={F(tableRootFrequencyHz)} freq={F(noteFrequencyHz)} spread=0 zyn_mode={mode} zyn_bandwidth={bandwidth} zyn_bwscale={bandwidthScale} zyn_profile={profile} zyn_position={position} partials={partialText}");
|
||||
}
|
||||
|
||||
private static ZynKitItem ParseKitItem(XElement item)
|
||||
|
|
@ -825,6 +830,87 @@ public static class ZynInstrumentReader
|
|||
return Math.Clamp(cutoffHz / 18000.0f, 20.0f / 18000.0f, 1f);
|
||||
}
|
||||
|
||||
private static int ZynPadLowPassOrder(XElement? filter)
|
||||
{
|
||||
if (filter is null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var category = DescendantIntParam(filter, "category", 0);
|
||||
var type = DescendantIntParam(filter, "type", 0);
|
||||
if (category != 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var poles = type switch
|
||||
{
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
_ => 1
|
||||
};
|
||||
return Math.Clamp(poles * (DescendantIntParam(filter, "stages", 0) + 1), 1, 12);
|
||||
}
|
||||
|
||||
private static float ZynPadPlaybackFrequency(XElement? frequency, float playbackFrequencyHz)
|
||||
{
|
||||
var detuneCents = ZynDetuneCents(
|
||||
IntParam(frequency, "detune_type", 1),
|
||||
IntParam(frequency, "coarse_detune", 0),
|
||||
IntParam(frequency, "detune", 8192));
|
||||
return playbackFrequencyHz * MathF.Pow(2.0f, detuneCents / 1200.0f);
|
||||
}
|
||||
|
||||
private static float ZynDetuneCents(int type, int coarseDetune, int fineDetune)
|
||||
{
|
||||
var octave = coarseDetune / 1024;
|
||||
if (octave >= 8)
|
||||
{
|
||||
octave -= 16;
|
||||
}
|
||||
|
||||
var coarse = coarseDetune % 1024;
|
||||
if (coarse > 512)
|
||||
{
|
||||
coarse -= 1024;
|
||||
}
|
||||
|
||||
var fine = fineDetune - 8192;
|
||||
float coarseCents;
|
||||
float fineCents;
|
||||
switch (type)
|
||||
{
|
||||
case 2:
|
||||
coarseCents = MathF.Abs(coarse * 10.0f);
|
||||
fineCents = MathF.Abs(fine / 8192.0f) * 10.0f;
|
||||
break;
|
||||
case 3:
|
||||
coarseCents = MathF.Abs(coarse * 100.0f);
|
||||
fineCents = MathF.Pow(10.0f, MathF.Abs(fine / 8192.0f) * 3.0f) / 10.0f - 0.1f;
|
||||
break;
|
||||
case 4:
|
||||
coarseCents = MathF.Abs(coarse * 701.95500087f);
|
||||
fineCents = (MathF.Pow(2.0f, MathF.Abs(fine / 8192.0f) * 12.0f) - 1.0f) / 4095.0f * 1200.0f;
|
||||
break;
|
||||
default:
|
||||
coarseCents = MathF.Abs(coarse * 50.0f);
|
||||
fineCents = MathF.Abs(fine / 8192.0f) * 35.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
if (fineDetune < 8192)
|
||||
{
|
||||
fineCents = -fineCents;
|
||||
}
|
||||
if (coarse < 0)
|
||||
{
|
||||
coarseCents = -coarseCents;
|
||||
}
|
||||
|
||||
return octave * 1200.0f + coarseCents + fineCents;
|
||||
}
|
||||
|
||||
private static int IntParam(XElement? root, string name, int fallback)
|
||||
{
|
||||
var value = root?.Elements("par")
|
||||
|
|
|
|||
Loading…
Reference in a new issue