Skip to content

Commit

Permalink
Improve conversion of pitch envelope levels when converting to ZenCor…
Browse files Browse the repository at this point in the history
…e format
  • Loading branch information
sagamusix committed Jan 3, 2024
1 parent cc7a069 commit 6e81876
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
33 changes: 29 additions & 4 deletions JDTools/Convert800toVST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ static T SignedTable(const T (&table)[N], int8_t offset)
return value;
}

static uint8_t ConvertPitchEnvLevel(uint8_t value)
{
int converted = value - 50;
// Real JD-800 has a pitch envelope range of -3 octaves to +1 octave... ZenCore only supports +/-1 octave.
if (converted <= -46)
{
converted = -50;
}
else if (converted < 0)
{
converted = (converted * 50 - 23) / 46;
}

return static_cast<uint8_t>(converted);
}

static void ConvertTone800ToVST(const Tone800 &t800, const bool enabled, const bool selected, ToneVST &tVST)
{
tVST.common.layerEnabled = enabled;
Expand Down Expand Up @@ -55,6 +71,11 @@ static void ConvertTone800ToVST(const Tone800 &t800, const bool enabled, const b
tVST.wg.pitchCoarse = t800.wg.pitchCoarse - 48;
tVST.wg.pitchFine= t800.wg.pitchFine - 50;
tVST.wg.pitchRandom = t800.wg.pitchRandom;
if (tVST.wg.pitchRandom > 0 && tVST.wg.pitchRandom < 20)
{
tVST.wg.pitchRandom = 20;
std::cerr << "LOSSY CONVERSION! Pitch Random values 1-19 do nothing, setting to 20 instead" << std::endl;
}
tVST.wg.keyFollow = t800.wg.keyFollow;
tVST.wg.benderSwitch = t800.wg.benderSwitch;
tVST.wg.aTouchBend = t800.wg.aTouchBend;
Expand Down Expand Up @@ -98,12 +119,16 @@ static void ConvertTone800ToVST(const Tone800 &t800, const bool enabled, const b
tVST.pitchEnv.velo = t800.pitchEnv.velo - 50;
tVST.pitchEnv.timeVelo = t800.pitchEnv.timeVelo - 50;
tVST.pitchEnv.timeKF = t800.pitchEnv.timeKF - 10;
tVST.pitchEnv.level0 = t800.pitchEnv.level0 - 50;
tVST.pitchEnv.level1 = t800.pitchEnv.level1 - 50;
tVST.pitchEnv.level2 = t800.pitchEnv.level2 - 50;
tVST.pitchEnv.level0 = ConvertPitchEnvLevel(t800.pitchEnv.level0);
tVST.pitchEnv.level1 = ConvertPitchEnvLevel(t800.pitchEnv.level1);
tVST.pitchEnv.level2 = ConvertPitchEnvLevel(t800.pitchEnv.level2);
tVST.pitchEnv.time1 = t800.pitchEnv.time1;
tVST.pitchEnv.time2 = t800.pitchEnv.time2;
tVST.pitchEnv.time3 = t800.pitchEnv.time3;
if (t800.pitchEnv.level0 < 4 || t800.pitchEnv.level1 < 4 || t800.pitchEnv.level2 < 4)
{
std::cerr << "LOSSY CONVERSION! Pitch envelope cannot go lower than one octave" << std::endl;
}

tVST.tvf.filterMode = 2 - t800.tvf.filterMode;
tVST.tvf.cutoffFreq = t800.tvf.cutoffFreq;
Expand Down Expand Up @@ -258,7 +283,7 @@ static void FillPrecomputedToneVST(const ToneVST &tVST, const PatchVST &pVST, To
common.cs4.destination2 = 4; // Level
common.cs4.depth2 = static_cast<uint8_t>(SafeTable(AtouchSensTVA, tVST.tva.aTouchSens + 50));

common.cs5.destination1 = 0x64;
common.unknown293_64 = 0x64;

ToneVSTPrecomputed::PitchEnv &pitchEnv = tpVST.pitchEnv[tone];
pitchEnv.unknown680_33 = 0x33;
Expand Down
18 changes: 15 additions & 3 deletions JDTools/ConvertVSTto800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ static void ConvertEQBand(const T(&freqTable)[N], uint8_t &freq, uint8_t &gain,
std::cerr << "LOSSY CONVERSION! Truncating EQ " << name << " gain fractional precision: " << srcGain * 0.1f << " dB" << std::endl;
}

static uint8_t ConvertPitchEnvLevel(uint8_t value)
{
int converted = static_cast<int8_t>(value);
// Real JD-800 has a pitch envelope range of -3 octaves to +1 octave... ZenCore only supports +/-1 octave.
if (converted < 0)
{
converted = (converted * 46 - 25) / 50;
}

return static_cast<uint8_t>(converted + 50);
}

static void ConvertToneVSTTo800(const ToneVST &tVST, Tone800 &t800)
{
if (tVST.wg.gain != 3 && tVST.common.layerEnabled)
Expand Down Expand Up @@ -194,12 +206,12 @@ static void ConvertToneVSTTo800(const ToneVST &tVST, Tone800 &t800)
t800.pitchEnv.velo = tVST.pitchEnv.velo + 50;
t800.pitchEnv.timeVelo = tVST.pitchEnv.timeVelo + 50;
t800.pitchEnv.timeKF = tVST.pitchEnv.timeKF + 10;
t800.pitchEnv.level0 = tVST.pitchEnv.level0 + 50;
t800.pitchEnv.level0 = ConvertPitchEnvLevel(tVST.pitchEnv.level0);
t800.pitchEnv.time1 = tVST.pitchEnv.time1;
t800.pitchEnv.level1 = tVST.pitchEnv.level1 + 50;
t800.pitchEnv.level1 = ConvertPitchEnvLevel(tVST.pitchEnv.level1);
t800.pitchEnv.time2 = tVST.pitchEnv.time2;
t800.pitchEnv.time3 = tVST.pitchEnv.time3;
t800.pitchEnv.level2 = tVST.pitchEnv.level2 + 50;
t800.pitchEnv.level2 = ConvertPitchEnvLevel(tVST.pitchEnv.level2);

t800.tvf.filterMode = 2 - tVST.tvf.filterMode;
t800.tvf.cutoffFreq = tVST.tvf.cutoffFreq;
Expand Down
13 changes: 12 additions & 1 deletion JDTools/JD-08.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,19 @@ struct ToneVSTPrecomputed
ControlSource cs2; // 256
ControlSource cs3; // 268
ControlSource cs4; // 280
ControlSource cs5; // Probably something completely different, given that Roland typically provides 4 modulation sources
uint8_t
unknown292_00,
unknown293_64,
unknown294_00,
unknown295_00,
unknown296_00,
unknown297_00,
unknown298_00,
unknown299_00,
unknown300_00,
unknown301_00,
unknown302_00,
unknown303_00,
unknown304_00,
unknown305_00,
unknown306_00,
Expand Down
2 changes: 1 addition & 1 deletion license.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
JDTools is released under the 3-clause BSD license:

Copyright (c) 2022, Johannes Schultz
Copyright (c) 2022 - 2024, Johannes Schultz
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down

0 comments on commit 6e81876

Please sign in to comment.