Hi sto, I started an IMF player yesterday for my own experiments, it is very easy to do. I already have players for my own reg-dump format, dosbox DRO dump and .LAA midi based files so IMF is not a problem.
I actually dug out some exact timing values for playing out .IMF files from Wolf3D. The sound init uses a base rate of 70 Hz, but for Adlib music it multiplies this base rate by 10, so 700 Hz timer interrupt is requested.
But it turns out the timer rate setting code has a slight miscalculation and uses 1192030 as the timer tick frequency, so the requested timer tick period is 1192030/700 which truncates to 1702 ticks. With the real timer frequency of approximately 1193182, the actual IMF timer frequency is something like 701.047 Hz. Because both the timer and OPL2 chip are run at least in theory from the same crystal, it means that for each IMF timer tick there is really 1702*12 crystal ticks and for each OPL sample there is 288 crystal ticks, so this is the time base that is correct. As it is not an integer, I will first just begin with the fact that in each IMF timer tick there are 1704*12 crystal ticks that results into exactly 71 OPL samples. I think nobody can hear the difference. This timing is Wolf3D specific so other 700Hz files may use different timer period. Again, close enough.
First test: Can you be more detailed? What other values like decay, sustain and release should be used? What frequency square wave? I don't know how much delay there is, but with attack rate 15 the output jumps directly to maximum when it does. AR 14 is already double speed (or double fast per sample), and AR 13 is the "reference" with one step per sample, and all values below that have 2^N integer samples per step. But it is not 2^N steps from setting the KEYON bit, there is some free-running timer that ticks away and divides the sample clock, and there is up to 2^N - 1 samples before you see the KEYON have an effect on the amplitude. And since attack starts from previous amplitude that is not necessarily 0, I think what happens with AR=0 is that the sound amplitude does not attack, but it stays where it is left off previously during decay, sustain or release. This can also be tested with RR=0 so the sound does not release at all, and thus SL sets the level it stays at KEYOFF event. Mind you, that after KON even the phase generator will have zero phase I hope, if there is no delay or the phase generator is accidentally loaded with the increment instead of zero. Fortunately there is a trick to run a waveform backwards, just set waveform parameters so that instead of increasing 1 waveform table entry per sample (512), you increase 1023 waveform table entries per sample which equals to -1 entry per sample. I think this means FNUM=1023, BLOCK=7 and MULTI=8x so phase increment is 0x7FE00 or 1023<<9.
Second test: Yes this is still on my todo list. I should try feedback with some other more complex waveform than square, maybe with waveforms #0, #1 and #3 (sine, sine with positive peaks only and negative peak is flat 0, or the rising quarter with flat during falling quarter). I think it would be safest with waveforms #1 and #3 as they do not have negative output, so the waveform is never negative. With sine, even if amplitude is minimum but the sound is running, it still alternates between 0 and -1 because of the sign flag. Oh, but I can of course start a sine wave with frequency of 0, so it will reset phase to 0 and stay there until I change FNUM. And hope the amplitude is small enough not to cause feedback at zero phase, it's only 12 in PCM value.
KSL: "...no other ROM's larger than 16 samples". The sin and exp tables are located in the "operator" block, as that is what converts phase and envelope info to waveform and to output values. There should be no output from the tables anywhere else like to the envelope generator. So this KSL algorithm could be a separate table with up to 16 entries that gets modified by amount indicated by FNUM and BLOCK. 128 entry table in C code should do it for all purposes, although bits need to be correctly shifted or dropped out when selecting between the 3 different KSL levels (4th being no KSL). Verifying this has been on my todo list as well. The odd interface might be a leftover from an older chip that had only no KSL or only 3dB/octave KSL, but I did not currently find any reference to this. I have a vague memory that some older chip had only 1 bit, but I may be wrong. I just need to calculate if these values can be safely determined with a full volume square wave sweep which should be easy. If many KSL attennuation values map to identical PCM output values then another waveform must be used and at different frequencies which is more difficult.