Attempt minimizing polyphony problems

This commit is contained in:
Cacodemon345
2022-11-29 12:08:01 +06:00
parent f77e0cf706
commit 83f256bed9

View File

@@ -314,7 +314,23 @@ get_voice(const YRW801_WAVE_DATA *wave_data, opl4_midi_t *opl4_midi)
}
}
/* If no free voice found, deactivate the 'oldest' */
/* If no free voice is found, look for one with the same instrument */
if (free_voice->is_active) {
for (uint8_t voice = 0; voice < 24; voice++) {
if (opl4_midi_cur->voice_data[voice].is_active
&& opl4_midi_cur->voice_data[voice].wave_data == wave_data) {
free_voice = &opl4_midi_cur->voice_data[voice];
free_voice->is_active = 0;
free_voice->activated = 0;
free_voice->reg_misc &= ~OPL4_KEY_ON_BIT;
opl4_write_wave_register(OPL4_REG_MISC + free_voice->number, free_voice->reg_misc, opl4_midi);
return free_voice;
}
}
}
/* If still no free voice found, deactivate the 'oldest' */
if (free_voice->is_active) {
free_voice = oldest_voice;
free_voice->is_active = 0;