ref: 4f8f8a43e174f1e82dc0160c0ea96070e1cf6ef9
parent: 172188c35a1c9f79890e385de688db72fedf8c42
author: Simon Howard <fraggle@soulsphere.org>
date: Wed May 27 17:37:52 EDT 2015
opl: Tweak voice replacement algorithm. Prefer replacing a second voice before a voice from a higher- numbered channel. This resolves some issues with the MAP01 music, as noted in comments on #468; it may not be Vanilla behavior in terms of code but seems to better match it based on observation, and makes logical sense. Also adjust code to fit to the 80 column limit.
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -353,7 +353,8 @@
main_instrs = (genmidi_instr_t *) (lump + strlen(GENMIDI_HEADER));
percussion_instrs = main_instrs + GENMIDI_NUM_INSTRS;
- main_instr_names = (char (*)[32]) (percussion_instrs + GENMIDI_NUM_PERCUSSION);
+ main_instr_names =
+ (char (*)[32]) (percussion_instrs + GENMIDI_NUM_PERCUSSION);
percussion_names = main_instr_names + GENMIDI_NUM_INSTRS;
return true;
@@ -529,7 +530,8 @@
midi_volume = 2 * (volume_mapping_table[(voice->channel->volume
* current_music_volume) / 127] + 1);
- full_volume = (volume_mapping_table[voice->note_volume] * midi_volume) >> 9;
+ full_volume = (volume_mapping_table[voice->note_volume] * midi_volume)
+ >> 9;
// The volume value to use in the register:
car_volume = 0x3f - full_volume;
@@ -545,7 +547,8 @@
// If we are using non-modulated feedback mode, we must set the
// volume for both voices.
- if ((opl_voice->feedback & 0x01) != 0 && opl_voice->modulator.level != 0x3f)
+ if ((opl_voice->feedback & 0x01) != 0
+ && opl_voice->modulator.level != 0x3f)
{
mod_volume = 0x3f - opl_voice->modulator.level;
if (mod_volume >= car_volume)
@@ -553,7 +556,8 @@
mod_volume = car_volume;
}
OPL_WriteRegister(OPL_REGS_LEVEL + voice->op1,
- mod_volume | (opl_voice->modulator.scale & 0xc0));
+ mod_volume |
+ (opl_voice->modulator.scale & 0xc0));
}
}
}
@@ -668,7 +672,7 @@
// passed to the function is the channel for the new note to be
// played.
-static void ReplaceExistingVoice()
+static void ReplaceExistingVoice(void)
{
opl_voice_t *rover;
opl_voice_t *result;
@@ -685,8 +689,9 @@
for (rover = voice_alloced_list; rover != NULL; rover = rover->next)
{
- if (rover->current_instr_voice != 0
- || rover->channel >= result->channel)
+ if (rover->current_instr_voice > result->current_instr_voice
+ || (rover->current_instr_voice == result->current_instr_voice
+ && rover->channel >= result->channel))
{
result = rover;
}