Update emu8950.c

Fix bug where attack step 0 for eg_rate_h 15 causing envelop never switch to decay, causing some music missing notes in higher notes.
This commit is contained in:
TerryFi authored and GitHub committed 2024-06-05 11:06:17 -04:00
1 parent 5cf7cb6c39
commit 87d252176a
1 file changed
+17 -5
+17 -5
View File
@@ -868,7 +868,10 @@ static INLINE void calc_envelope(OPL_SLOT *slot, uint16_t eg_counter, uint8_t te
if (slot->eg_state == ATTACK) {
if (0 < slot->eg_out && slot->eg_rate_h > 0 && (eg_counter & mask) == 0) {
step = lookup_attack_step(slot, eg_counter);
slot->eg_out += (~slot->eg_out * step) >> 3;
if(step)
slot->eg_out += (~slot->eg_out * step) >> 3;
else
slot->eg_out = 0; // Switch immediately to decay for eg rate 0
}
} else {
if (slot->eg_rate_h > 0 && (eg_counter & mask) == 0) {
@@ -1411,7 +1414,10 @@ uint32_t __not_in_flash_func(slot_mod_linear)(OPL *opl, OPL_SLOT *slot, uint32_t
uint16_t mask = (1 << slot->eg_shift) - 1;
if (0 < slot->eg_out && slot->eg_rate_h > 0 && (eg_counter & mask) == 0) {
uint8_t step = lookup_attack_step(slot, eg_counter);
slot->eg_out += (~slot->eg_out * step) >> 3;
if (step)
slot->eg_out += (~slot->eg_out * step) >> 3;
else
slot->eg_out = 0;
}
if (slot->eg_out == 0) {
slot->eg_state = DECAY;
@@ -1513,7 +1519,10 @@ uint32_t __not_in_flash_func(slot_car_linear_alg1)(OPL *opl, OPL_SLOT *slot, uin
uint16_t mask = (1 << slot->eg_shift) - 1;
if (0 < slot->eg_out && slot->eg_rate_h > 0 && (eg_counter & mask) == 0) {
uint8_t step = lookup_attack_step(slot, eg_counter);
slot->eg_out += (~slot->eg_out * step) >> 3;
if (step)
slot->eg_out += (~slot->eg_out * step) >> 3;
else
slot->eg_out = 0;
}
if (slot->eg_out == 0) {
slot->eg_state = DECAY;
@@ -1612,7 +1621,10 @@ uint32_t __not_in_flash_func(slot_car_linear_alg0)(OPL *opl, OPL_SLOT *slot, uin
uint16_t mask = (1 << slot->eg_shift) - 1;
if (0 < slot->eg_out && slot->eg_rate_h > 0 && (eg_counter & mask) == 0) {
uint8_t step = lookup_attack_step(slot, eg_counter);
slot->eg_out += (~slot->eg_out * step) >> 3;
if (step)
slot->eg_out += (~slot->eg_out * step) >> 3;
else
slot->eg_out = 0;
}
if (slot->eg_out == 0) {
slot->eg_state = DECAY;
@@ -2025,4 +2037,4 @@ void OPL_writeReg(OPL *opl, uint32_t reg, uint8_t data) {
}
}
}
#endif
#endif