summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2015-05-27 21:37:52 -0400
committerSimon Howard2015-05-27 21:37:52 -0400
commit4f8f8a43e174f1e82dc0160c0ea96070e1cf6ef9 (patch)
tree7ba75a0096bc79e88f2dfe135cbd7535e3a0c54e /src
parent172188c35a1c9f79890e385de688db72fedf8c42 (diff)
downloadchocolate-doom-4f8f8a43e174f1e82dc0160c0ea96070e1cf6ef9.tar.gz
chocolate-doom-4f8f8a43e174f1e82dc0160c0ea96070e1cf6ef9.tar.bz2
chocolate-doom-4f8f8a43e174f1e82dc0160c0ea96070e1cf6ef9.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/i_oplmusic.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c
index c02f1941..a5910056 100644
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -353,7 +353,8 @@ static boolean LoadInstrumentTable(void)
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 @@ static void SetVoiceVolume(opl_voice_t *voice, unsigned int volume)
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 @@ static void SetVoiceVolume(opl_voice_t *voice, unsigned int volume)
// 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 @@ static void SetVoiceVolume(opl_voice_t *voice, unsigned int volume)
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 @@ static void KeyOffEvent(opl_track_data_t *track, midi_event_t *event)
// 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 @@ static void ReplaceExistingVoice()
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;
}