diff --git a/src/main/java/de/mossgrabers/convertwithmoss/format/dls/DlsDetector.java b/src/main/java/de/mossgrabers/convertwithmoss/format/dls/DlsDetector.java index d0dda6e2..be36f148 100644 --- a/src/main/java/de/mossgrabers/convertwithmoss/format/dls/DlsDetector.java +++ b/src/main/java/de/mossgrabers/convertwithmoss/format/dls/DlsDetector.java @@ -235,7 +235,10 @@ private static void applyArticulations (final DlsInstrument dlsInstrument, final { final IEnvelope pitchEnvelope = createEnvelope (dlsInstrument, dlsRegion, true); final IEnvelopeModulator pitchEnvelopeModulator = zone.getPitchEnvelopeModulator (); - pitchEnvelopeModulator.setDepth (normalizeEG2ToPitch (pitchModulation.get ().getScale ())); + // The scale is a relative pitch in cent, stored as a 32-bit fixed point number with + // 65536 representing one cent + final double depthCents = pitchModulation.get ().getScale () / 65536.0; + pitchEnvelopeModulator.setDepth (Math.clamp (depthCents, -IEnvelope.MAX_ENVELOPE_DEPTH, IEnvelope.MAX_ENVELOPE_DEPTH) / IEnvelope.MAX_ENVELOPE_DEPTH); pitchEnvelopeModulator.setSource (pitchEnvelope); } @@ -243,7 +246,8 @@ private static void applyArticulations (final DlsInstrument dlsInstrument, final final Optional pitchTuning = getArticulation (dlsInstrument, dlsRegion, DlsArticulation.CONN_SRC_NONE, DlsArticulation.CONN_DST_PITCH); if (pitchTuning.isPresent ()) { - final double tuning = normalizeEG2ToPitch (pitchTuning.get ().getScale ()); + // The scale is a relative pitch in cent (65536 per cent), the tuning is in semi-tones + final double tuning = pitchTuning.get ().getScale () / 65536.0 / 100.0; zone.setTuning (zone.getTuning () + tuning); } @@ -281,10 +285,7 @@ private static IEnvelope createEnvelope (final DlsInstrument dlsInstrument, fina if (isEnvelope1) sustain = getLevel (dlsInstrument, dlsRegion, DlsArticulation.CONN_DST_EG1_SUSTAINLEVEL); else - { - final Optional articulation = getArticulation (dlsInstrument, dlsRegion, DlsArticulation.CONN_SRC_NONE, DlsArticulation.CONN_DST_EG2_SUSTAINLEVEL); - sustain = articulation.isEmpty () ? -1 : normalizeEG2ToPitch (articulation.get ().getScale ()); - } + sustain = getLevel (dlsInstrument, dlsRegion, DlsArticulation.CONN_DST_EG2_SUSTAINLEVEL); final IEnvelope envelope = new DefaultEnvelope (); if (delay >= 0) @@ -346,16 +347,4 @@ private static double normalizeKeyNumberToGain (final int scale) { return Math.clamp (scale / (655360.0 * 127.0), -1, 1); } - - - /** - * Normalizes a DLS Modulation EG to Pitch lScale value to the range 0.0..1.0. - * - * @param cents The raw 32-bit signed relative pitch value - * @return Normalized value in range [0.0, 1.0] - */ - public static double normalizeEG2ToPitch (final int cents) - { - return Math.clamp (cents, -1200, 1200) / 1200.0; - } }