#40923 - Quirky - Sat Apr 23, 2005 3:54 pm
I've implemented a basic XM player that does mostly what I need - play some MIDI files converted to XM using modplug tracker - but I have a couple of doubts regarding samples and instruments...
In Mods, the samples are stored at the default rate of 8363 Hz for C4 (or C2, or "middle C"). In the XM format, things are a bit more complex; you have an 'instrument' that contains samples. For example you have instrument 1 - "Strings" - that may have the samples "String.1" "String.2" etc. Each sample has a signed byte finetune value and relative note value. Then in the pattern, you have an entry that would be "note 64, instrument 1".
In order for the track to sound correct, I have to offset the given pattern note by the sample's relative note - I only seem to need sample 1 in each instrument (??). But occasionaly it sounds wonky and I imagine it's because of the one sample fudge.
For example, note 64 (E 4)comes up in the pattern, the sample has a relative note of 10, so I play note 64+10 = 74 (or 'D 5'). I have a LUT that uses equal temperament semitones (C4 = 261.1Hz) converted to the increment value for the mixer.
The table is built externally using:
where mixer_freq = 18157
middle_C = 261.6
default_sample_freq = 8363
note_in_hz = the frequency of this note (0-127 on the midi scale)
My question is: why are there multiple samples in each instrument? And how does the finetune value fit in? I imagine that it's something like "If the note is in the range of a sample, then play that sample, else play the next higher up sample" and so on - so rather than offsetting the pattern note by 10, I would play the sample that covers that range. But I haven't found any docs that really explain it. Can anyone shed some light on the subject?
EDIT: Well it seems that Modplug Tracker adds in extra samples that aren't actually used - it groups them together in the Windows program and just outputs the group to the XM file whether the samples are used or not. Fair enough.
And the finetune is straightforward too: I saw Deku's post lower down where he interpolates between 2 notes, copied the idea, and BAM! everything sounds spot on. Wonderful.
In Mods, the samples are stored at the default rate of 8363 Hz for C4 (or C2, or "middle C"). In the XM format, things are a bit more complex; you have an 'instrument' that contains samples. For example you have instrument 1 - "Strings" - that may have the samples "String.1" "String.2" etc. Each sample has a signed byte finetune value and relative note value. Then in the pattern, you have an entry that would be "note 64, instrument 1".
In order for the track to sound correct, I have to offset the given pattern note by the sample's relative note - I only seem to need sample 1 in each instrument (??). But occasionaly it sounds wonky and I imagine it's because of the one sample fudge.
For example, note 64 (E 4)comes up in the pattern, the sample has a relative note of 10, so I play note 64+10 = 74 (or 'D 5'). I have a LUT that uses equal temperament semitones (C4 = 261.1Hz) converted to the increment value for the mixer.
The table is built externally using:
Code: |
table[i] = ((note_in_hz*default_sample_freq/middle_C_in_hz)<<12 ) / mixer_freq |
where mixer_freq = 18157
middle_C = 261.6
default_sample_freq = 8363
note_in_hz = the frequency of this note (0-127 on the midi scale)
My question is: why are there multiple samples in each instrument? And how does the finetune value fit in? I imagine that it's something like "If the note is in the range of a sample, then play that sample, else play the next higher up sample" and so on - so rather than offsetting the pattern note by 10, I would play the sample that covers that range. But I haven't found any docs that really explain it. Can anyone shed some light on the subject?
EDIT: Well it seems that Modplug Tracker adds in extra samples that aren't actually used - it groups them together in the Windows program and just outputs the group to the XM file whether the samples are used or not. Fair enough.
And the finetune is straightforward too: I saw Deku's post lower down where he interpolates between 2 notes, copied the idea, and BAM! everything sounds spot on. Wonderful.