Closed snoopin1 closed 3 years ago
Happy to merge. This change also ignores the KSL value for the instrument (see https://moddingwiki.shikadi.net/wiki/OPL_chip#40-55:_Key_Scale_Level_.2F_Output_Level) so I presume having this change on its own is also not enough to justify considering it as a different instrument?
Yes; if only an instrument's carrier KSL changes, then I do not think it should be counted as a new instrument. Its dB/oct attenuation will be different, but its timbre will be exactly the same.
Since the carrier's OL and KSL values each only affect an instrument's volume and not its timbre, I think ignoring both of those for instrument detection should allow the tool to distinguish between instruments correctly.
I have also tested my changes with several games. For example, Duke Nukem II's 20 IMFs contain a total of 140 instruments (checked with both IMFCreator and gamemus). With DRO2MIDI's original instrument detection code (v1.6), a total of 680 instruments are detected; i.e., in a single song the same instrument will get re-detected as a new one if its carrier volume settings change. With DRO2MIDI's new instrument detection code (v1.7), the correct total of 140 instruments is detected. I have made sure that the "correct" number of instruments was detected for each of the 20 songs.
I will add that I am actually not 100% decided on how to handle carrier output level for initial instrument detection and writing SBIs. I have noticed that other tools will always force a detected instrument's C-OL to show as 0.00 dB.
Using the first instrument from Duke II's begonea.imf as an example, DRO2MIDI will "retain" the instrument's initial output level of -14.25 dB. This is the output level that will also be used in the exported SBI. However, other tools (such as IMFCreator and OPL3BankEditor) will instead ignore whatever instrument output level the song sets altogether and automatically force it to 0.00 dB.
This pull request is ready to merge; everything seems to be working as intended:
As for forcing detected instruments to maximum volume, I have found that OPL3BankEditor does this with IMFs but not CMFs for some reason, so for now I think DRO2MIDI's behavior in this regard (always retain initial instrument volume and carrier key scaling level) does not need to be changed.
The CMF discrepancy might be because the official Creative Labs CMF player always forces the volume to the loudest regardless of what the instrument setting is. I find it interesting that some CMF files contain notes at different MIDI velocities but that nuance is lost when the player just plays them at maximum volume regardless.
Improvements:
Edit: Still deciding how to handle carrier output level; see this comment.