Skip to content

Commit

Permalink
Rename "Second Decay Rate (D2R)" and "Secondary Amplitude (D1L/SL)" t…
Browse files Browse the repository at this point in the history
…o "Sustain Rate (SR)" and "Sustain Level (SL)" accordingly
  • Loading branch information
rhargreaves committed Aug 3, 2024
1 parent 6eae798 commit c5fc79c
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 75 deletions.
6 changes: 3 additions & 3 deletions src/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ static void setFmChanParameter(DeviceChannel* devChan, u8 controller, u8 value)
case CC_GENMDM_FIRST_DECAY_RATE_OP4:
if (isIgnoringNonGeneralMidiCCs())
break;
synth_operatorFirstDecayRate(
synth_operatorDecayRate(
devChan->number, controller - CC_GENMDM_FIRST_DECAY_RATE_OP1, RANGE(value, 32));
break;
case CC_GENMDM_SECOND_DECAY_RATE_OP1:
Expand All @@ -804,7 +804,7 @@ static void setFmChanParameter(DeviceChannel* devChan, u8 controller, u8 value)
case CC_GENMDM_SECOND_DECAY_RATE_OP4:
if (isIgnoringNonGeneralMidiCCs())
break;
synth_operatorSecondDecayRate(
synth_operatorSustainRate(
devChan->number, controller - CC_GENMDM_SECOND_DECAY_RATE_OP1, RANGE(value, 16));
break;
case CC_GENMDM_SECOND_AMPLITUDE_OP1:
Expand All @@ -813,7 +813,7 @@ static void setFmChanParameter(DeviceChannel* devChan, u8 controller, u8 value)
case CC_GENMDM_SECOND_AMPLITUDE_OP4:
if (isIgnoringNonGeneralMidiCCs())
break;
synth_operatorSecondaryAmplitude(
synth_operatorSustainLevel(
devChan->number, controller - CC_GENMDM_SECOND_AMPLITUDE_OP1, RANGE(value, 16));
break;
case CC_GENMDM_RELEASE_RATE_OP1:
Expand Down
46 changes: 23 additions & 23 deletions src/synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ static void writeGlobalLfo(void);
static void writeAlgorithmAndFeedback(u8 channel);
static void writeOperatorMultipleAndDetune(u8 channel, u8 operator);
static void writeOperatorRateScalingAndAttackRate(u8 channel, u8 operator);
static void writeOperatorAmplitudeModulationAndFirstDecayRate(u8 channel, u8 operator);
static void writeOperatorReleaseRateAndSecondaryAmplitude(u8 channel, u8 operator);
static void writeOperatorAmplitudeModulationAndDecayRate(u8 channel, u8 operator);
static void writeOperatorReleaseRateAndSustainLevel(u8 channel, u8 operator);
static void writeOperatorTotalLevel(u8 channel, u8 operator);
static void writeOperatorSecondaryDecayRate(u8 channel, u8 operator);
static void writeOperatorSustainRate(u8 channel, u8 operator);
static void writeOperatorSsgEg(u8 channel, u8 operator);
static void writeStereoAmsFms(u8 channel);
static void writeChannelReg(u8 channel, u8 baseReg, u8 data);
Expand Down Expand Up @@ -67,9 +67,9 @@ static void updateChannel(u8 chan)
for (u8 op = 0; op < MAX_FM_OPERATORS; op++) {
writeOperatorMultipleAndDetune(chan, op);
writeOperatorRateScalingAndAttackRate(chan, op);
writeOperatorAmplitudeModulationAndFirstDecayRate(chan, op);
writeOperatorSecondaryDecayRate(chan, op);
writeOperatorReleaseRateAndSecondaryAmplitude(chan, op);
writeOperatorAmplitudeModulationAndDecayRate(chan, op);
writeOperatorSustainRate(chan, op);
writeOperatorReleaseRateAndSustainLevel(chan, op);
writeOperatorTotalLevel(chan, op);
writeOperatorSsgEg(chan, op);
}
Expand Down Expand Up @@ -166,17 +166,17 @@ void synth_operatorAttackRate(u8 channel, u8 op, u8 attackRate)
channelParameterUpdated(channel);
}

void synth_operatorSecondDecayRate(u8 channel, u8 op, u8 secondDecayRate)
void synth_operatorSustainRate(u8 channel, u8 op, u8 sustainRate)
{
getOperator(channel, op)->secondaryDecayRate = secondDecayRate;
writeOperatorSecondaryDecayRate(channel, op);
getOperator(channel, op)->sustainRate = sustainRate;
writeOperatorSustainRate(channel, op);
channelParameterUpdated(channel);
}

void synth_operatorReleaseRate(u8 channel, u8 op, u8 releaseRate)
{
getOperator(channel, op)->releaseRate = releaseRate;
writeOperatorReleaseRateAndSecondaryAmplitude(channel, op);
writeOperatorReleaseRateAndSustainLevel(channel, op);
channelParameterUpdated(channel);
}

Expand All @@ -187,24 +187,24 @@ void synth_operatorSsgEg(u8 channel, u8 op, u8 ssgEg)
channelParameterUpdated(channel);
}

void synth_operatorSecondaryAmplitude(u8 channel, u8 op, u8 secondaryAmplitude)
void synth_operatorSustainLevel(u8 channel, u8 op, u8 sustainLevel)
{
getOperator(channel, op)->secondaryAmplitude = secondaryAmplitude;
writeOperatorReleaseRateAndSecondaryAmplitude(channel, op);
getOperator(channel, op)->sustainLevel = sustainLevel;
writeOperatorReleaseRateAndSustainLevel(channel, op);
channelParameterUpdated(channel);
}

void synth_operatorFirstDecayRate(u8 channel, u8 op, u8 firstDecayRate)
void synth_operatorDecayRate(u8 channel, u8 op, u8 decayRate)
{
getOperator(channel, op)->firstDecayRate = firstDecayRate;
writeOperatorAmplitudeModulationAndFirstDecayRate(channel, op);
getOperator(channel, op)->decayRate = decayRate;
writeOperatorAmplitudeModulationAndDecayRate(channel, op);
channelParameterUpdated(channel);
}

void synth_operatorAmplitudeModulation(u8 channel, u8 op, u8 amplitudeModulation)
{
getOperator(channel, op)->amplitudeModulation = amplitudeModulation;
writeOperatorAmplitudeModulationAndFirstDecayRate(channel, op);
writeOperatorAmplitudeModulationAndDecayRate(channel, op);
channelParameterUpdated(channel);
}

Expand Down Expand Up @@ -334,22 +334,22 @@ static void writeOperatorRateScalingAndAttackRate(u8 channel, u8 operator)
writeOperatorReg(channel, operator, 0x50, op->attackRate + (op->rateScaling << 6));
}

static void writeOperatorAmplitudeModulationAndFirstDecayRate(u8 channel, u8 operator)
static void writeOperatorAmplitudeModulationAndDecayRate(u8 channel, u8 operator)
{
Operator* op = getOperator(channel, operator);
writeOperatorReg(channel, operator, 0x60, op->firstDecayRate + (op->amplitudeModulation << 7));
writeOperatorReg(channel, operator, 0x60, op->decayRate + (op->amplitudeModulation << 7));
}

static void writeOperatorSecondaryDecayRate(u8 channel, u8 operator)
static void writeOperatorSustainRate(u8 channel, u8 operator)
{
Operator* op = getOperator(channel, operator);
writeOperatorReg(channel, operator, 0x70, op->secondaryDecayRate);
writeOperatorReg(channel, operator, 0x70, op->sustainRate);
}

static void writeOperatorReleaseRateAndSecondaryAmplitude(u8 channel, u8 operator)
static void writeOperatorReleaseRateAndSustainLevel(u8 channel, u8 operator)
{
Operator* op = getOperator(channel, operator);
writeOperatorReg(channel, operator, 0x80, op->releaseRate + (op->secondaryAmplitude << 4));
writeOperatorReg(channel, operator, 0x80, op->releaseRate + (op->sustainLevel << 4));
}

static void writeOperatorSsgEg(u8 channel, u8 operator)
Expand Down
12 changes: 6 additions & 6 deletions src/synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ typedef struct Operator {
u8 detune;
u8 attackRate;
u8 rateScaling;
u8 firstDecayRate;
u8 decayRate;
u8 amplitudeModulation;
u8 secondaryAmplitude;
u8 secondaryDecayRate;
u8 sustainLevel;
u8 sustainRate;
u8 releaseRate;
u8 totalLevel;
u8 ssgEg;
Expand Down Expand Up @@ -59,9 +59,9 @@ void synth_operatorMultiple(u8 channel, u8 op, u8 multiple);
void synth_operatorDetune(u8 channel, u8 op, u8 detune);
void synth_operatorRateScaling(u8 channel, u8 op, u8 rateScaling);
void synth_operatorAttackRate(u8 channel, u8 op, u8 attackRate);
void synth_operatorFirstDecayRate(u8 channel, u8 op, u8 firstDecayRate);
void synth_operatorSecondDecayRate(u8 channel, u8 op, u8 secondDecayRate);
void synth_operatorSecondaryAmplitude(u8 channel, u8 op, u8 secondaryAmplitude);
void synth_operatorDecayRate(u8 channel, u8 op, u8 decayRate);
void synth_operatorSustainRate(u8 channel, u8 op, u8 sustainRate);
void synth_operatorSustainLevel(u8 channel, u8 op, u8 sustainLevel);
void synth_operatorAmplitudeModulation(u8 channel, u8 op, u8 amplitudeModulation);
void synth_operatorReleaseRate(u8 channel, u8 op, u8 releaseRate);
void synth_operatorSsgEg(u8 channel, u8 op, u8 ssgEg);
Expand Down
12 changes: 5 additions & 7 deletions src/ui_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ static void printChannelParameterHeadings(void)
ui_draw_text(" DT", OP_HEADING_X, BASE_Y + 7);
ui_draw_text(" RS", OP_HEADING_X, BASE_Y + 8);
ui_draw_text(" AM", OP_HEADING_X, BASE_Y + 9);
ui_draw_text("D1R", OP_HEADING_X, BASE_Y + 10);
ui_draw_text("D2R", OP_HEADING_X, BASE_Y + 11);
ui_draw_text(" DR", OP_HEADING_X, BASE_Y + 10);
ui_draw_text(" SR", OP_HEADING_X, BASE_Y + 11);
ui_draw_text(" SL", OP_HEADING_X, BASE_Y + 12);
ui_draw_text(" RR", OP_HEADING_X, BASE_Y + 13);
ui_draw_text("SSG", OP_HEADING_X, BASE_Y + 14);
Expand Down Expand Up @@ -246,11 +246,9 @@ static void updateOpValues(const FmChannel* channel, bool forceRefresh)
updateOpValue(&lastOper->rateScaling, &oper->rateScaling, forceRefresh, op, 8);
updateOpValue(
&lastOper->amplitudeModulation, &oper->amplitudeModulation, forceRefresh, op, 9);
updateOpValue(&lastOper->firstDecayRate, &oper->firstDecayRate, forceRefresh, op, 10);
updateOpValue(
&lastOper->secondaryDecayRate, &oper->secondaryDecayRate, forceRefresh, op, 11);
updateOpValue(
&lastOper->secondaryAmplitude, &oper->secondaryAmplitude, forceRefresh, op, 12);
updateOpValue(&lastOper->decayRate, &oper->decayRate, forceRefresh, op, 10);
updateOpValue(&lastOper->sustainRate, &oper->sustainRate, forceRefresh, op, 11);
updateOpValue(&lastOper->sustainLevel, &oper->sustainLevel, forceRefresh, op, 12);
updateOpValue(&lastOper->releaseRate, &oper->releaseRate, forceRefresh, op, 13);
updateOpValue(&lastOper->ssgEg, &oper->ssgEg, forceRefresh, op, 14);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ MOCKS=midi_process \
synth_operatorDetune \
synth_operatorRateScaling \
synth_operatorAttackRate \
synth_operatorFirstDecayRate \
synth_operatorSecondDecayRate \
synth_operatorSecondaryAmplitude \
synth_operatorDecayRate \
synth_operatorSustainRate \
synth_operatorSustainLevel \
synth_operatorAmplitudeModulation \
synth_operatorReleaseRate \
synth_operatorSsgEg \
Expand Down
19 changes: 9 additions & 10 deletions tests/unit/test_midi_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ static void test_midi_sets_operator_first_decay_rate(UNUSED void** state)
for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) {
for (u8 cc = 47; cc <= 50; cc++) {
u8 expectedOp = cc - 47;
expect_value(__wrap_synth_operatorFirstDecayRate, channel, chan);
expect_value(__wrap_synth_operatorFirstDecayRate, op, expectedOp);
expect_value(__wrap_synth_operatorFirstDecayRate, firstDecayRate, expectedValue);
expect_value(__wrap_synth_operatorDecayRate, channel, chan);
expect_value(__wrap_synth_operatorDecayRate, op, expectedOp);
expect_value(__wrap_synth_operatorDecayRate, decayRate, expectedValue);

__real_midi_cc(chan, cc, 8);
}
Expand All @@ -297,9 +297,9 @@ static void test_midi_sets_operator_second_decay_rate(UNUSED void** state)
for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) {
for (u8 cc = 51; cc <= 54; cc++) {
u8 expectedOp = cc - 51;
expect_value(__wrap_synth_operatorSecondDecayRate, channel, chan);
expect_value(__wrap_synth_operatorSecondDecayRate, op, expectedOp);
expect_value(__wrap_synth_operatorSecondDecayRate, secondDecayRate, expectedValue);
expect_value(__wrap_synth_operatorSustainRate, channel, chan);
expect_value(__wrap_synth_operatorSustainRate, op, expectedOp);
expect_value(__wrap_synth_operatorSustainRate, sustainRate, expectedValue);

__real_midi_cc(chan, cc, 8);
}
Expand All @@ -313,10 +313,9 @@ static void test_midi_sets_operator_secondary_amplitude(UNUSED void** state)
for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) {
for (u8 cc = 55; cc <= 58; cc++) {
u8 expectedOp = cc - 55;
expect_value(__wrap_synth_operatorSecondaryAmplitude, channel, chan);
expect_value(__wrap_synth_operatorSecondaryAmplitude, op, expectedOp);
expect_value(
__wrap_synth_operatorSecondaryAmplitude, secondaryAmplitude, expectedValue);
expect_value(__wrap_synth_operatorSustainLevel, channel, chan);
expect_value(__wrap_synth_operatorSustainLevel, op, expectedOp);
expect_value(__wrap_synth_operatorSustainLevel, sustainLevel, expectedValue);

__real_midi_cc(chan, cc, 8);
}
Expand Down
20 changes: 9 additions & 11 deletions tests/unit/test_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,26 +204,25 @@ static void test_synth_sets_operator_attack_rate_and_rate_scaling(UNUSED void**
static void test_synth_sets_operator_second_decay_rate(UNUSED void** state)
{
const u8 baseReg = 0x70;
u8 secondDecayRate = 16;
u8 sustainRate = 16;
for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) {
for (u8 op = 0; op < MAX_FM_OPERATORS; op++) {
expect_ym2612_write_operator(chan, op, baseReg, secondDecayRate);
__real_synth_operatorSecondDecayRate(chan, op, secondDecayRate);
expect_ym2612_write_operator(chan, op, baseReg, sustainRate);
__real_synth_operatorSustainRate(chan, op, sustainRate);
}
}
}

static void test_synth_sets_operator_release_rate_and_secondary_amplitude(UNUSED void** state)
{
const u8 baseReg = 0x80;
u8 secondaryAmplitude = 15;
u8 sustainLevel = 15;
u8 releaseRate = 4;
for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) {
for (u8 op = 0; op < MAX_FM_OPERATORS; op++) {
expect_ym2612_write_operator_any_data(chan, op, baseReg);
__real_synth_operatorSecondaryAmplitude(chan, op, secondaryAmplitude);
expect_ym2612_write_operator(
chan, op, baseReg, releaseRate + (secondaryAmplitude << 4));
__real_synth_operatorSustainLevel(chan, op, sustainLevel);
expect_ym2612_write_operator(chan, op, baseReg, releaseRate + (sustainLevel << 4));
__real_synth_operatorReleaseRate(chan, op, releaseRate);
}
}
Expand All @@ -233,13 +232,12 @@ static void test_synth_sets_operator_amplitude_modulation_and_first_decay_rate(U
{
const u8 baseReg = 0x60;
u8 amplitudeModulation = 1;
u8 firstDecayRate = 16;
u8 decayRate = 16;
for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) {
for (u8 op = 0; op < MAX_FM_OPERATORS; op++) {
expect_ym2612_write_operator_any_data(chan, op, baseReg);
__real_synth_operatorFirstDecayRate(chan, op, firstDecayRate);
expect_ym2612_write_operator(
chan, op, baseReg, firstDecayRate + (amplitudeModulation << 7));
__real_synth_operatorDecayRate(chan, op, decayRate);
expect_ym2612_write_operator(chan, op, baseReg, decayRate + (amplitudeModulation << 7));
__real_synth_operatorAmplitudeModulation(chan, op, amplitudeModulation);
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/wraps.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,25 @@ void __wrap_synth_operatorAttackRate(u8 channel, u8 op, u8 attackRate)
check_expected(attackRate);
}

void __wrap_synth_operatorFirstDecayRate(u8 channel, u8 op, u8 firstDecayRate)
void __wrap_synth_operatorDecayRate(u8 channel, u8 op, u8 decayRate)
{
check_expected(channel);
check_expected(op);
check_expected(firstDecayRate);
check_expected(decayRate);
}

void __wrap_synth_operatorSecondDecayRate(u8 channel, u8 op, u8 secondDecayRate)
void __wrap_synth_operatorSustainRate(u8 channel, u8 op, u8 sustainRate)
{
check_expected(channel);
check_expected(op);
check_expected(secondDecayRate);
check_expected(sustainRate);
}

void __wrap_synth_operatorSecondaryAmplitude(u8 channel, u8 op, u8 secondaryAmplitude)
void __wrap_synth_operatorSustainLevel(u8 channel, u8 op, u8 sustainLevel)
{
check_expected(channel);
check_expected(op);
check_expected(secondaryAmplitude);
check_expected(sustainLevel);
}

void __wrap_synth_operatorAmplitudeModulation(u8 channel, u8 op, u8 amplitudeModulation)
Expand Down
12 changes: 6 additions & 6 deletions tests/wraps.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ void __wrap_synth_operatorMultiple(u8 channel, u8 op, u8 multiple);
void __wrap_synth_operatorDetune(u8 channel, u8 op, u8 detune);
void __wrap_synth_operatorRateScaling(u8 channel, u8 op, u8 rateScaling);
void __wrap_synth_operatorAttackRate(u8 channel, u8 op, u8 attackRate);
void __wrap_synth_operatorFirstDecayRate(u8 channel, u8 op, u8 firstDecayRate);
void __wrap_synth_operatorSecondDecayRate(u8 channel, u8 op, u8 secondDecayRate);
void __wrap_synth_operatorSecondaryAmplitude(u8 channel, u8 op, u8 secondaryAmplitude);
void __wrap_synth_operatorDecayRate(u8 channel, u8 op, u8 decayRate);
void __wrap_synth_operatorSustainRate(u8 channel, u8 op, u8 sustainRate);
void __wrap_synth_operatorSustainLevel(u8 channel, u8 op, u8 sustainLevel);
void __wrap_synth_operatorAmplitudeModulation(u8 channel, u8 op, u8 amplitudeModulation);
void __wrap_synth_operatorReleaseRate(u8 channel, u8 op, u8 releaseRate);
void __wrap_synth_operatorSsgEg(u8 channel, u8 op, u8 ssgEg);
Expand Down Expand Up @@ -63,9 +63,9 @@ extern void __real_synth_operatorMultiple(u8 channel, u8 op, u8 multiple);
extern void __real_synth_operatorDetune(u8 channel, u8 op, u8 detune);
extern void __real_synth_operatorRateScaling(u8 channel, u8 op, u8 rateScaling);
extern void __real_synth_operatorAttackRate(u8 channel, u8 op, u8 attackRate);
extern void __real_synth_operatorFirstDecayRate(u8 channel, u8 op, u8 firstDecayRate);
extern void __real_synth_operatorSecondDecayRate(u8 channel, u8 op, u8 secondDecayRate);
extern void __real_synth_operatorSecondaryAmplitude(u8 channel, u8 op, u8 secondaryAmplitude);
extern void __real_synth_operatorDecayRate(u8 channel, u8 op, u8 decayRate);
extern void __real_synth_operatorSustainRate(u8 channel, u8 op, u8 sustainRate);
extern void __real_synth_operatorSustainLevel(u8 channel, u8 op, u8 sustainLevel);
extern void __real_synth_operatorAmplitudeModulation(u8 channel, u8 op, u8 amplitudeModulation);
extern void __real_synth_operatorReleaseRate(u8 channel, u8 op, u8 releaseRate);
extern void __real_synth_operatorSsgEg(u8 channel, u8 op, u8 ssgEg);
Expand Down

0 comments on commit c5fc79c

Please sign in to comment.