gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Extending the MOD period table

#13013 - poslundc - Wed Dec 03, 2003 6:14 pm

I've run into a problem tracking MODs... all of the MOD documents I've found have a period table for only three octaves, but some of the MODs I am working with deal with periods for octaves above or below the standard Amiga period table range.

Is there an extended version of the period table out there for dealing with octaves outside of the default three used in MOD?

Thanks,

Dan.

#13015 - Burton Radons - Wed Dec 03, 2003 6:37 pm

The MOD file format description at Wotsit's Format (here, which might not like the referral link) has a full set of octaves.

#13016 - DekuTree64 - Wed Dec 03, 2003 6:53 pm

Yeah, you can do pretty much anything you want in your own music player, it doesn't have to be exact standard MOD. Besides, the period values just tell how long to wait between each sample (in related to the Amiga, you have to do calculate it around some to convert to Hz), and the notes in the patterns are just stored as period values, so all you have to do is deal with larger/smaller periods than the main 3 octaves, and to do that you just extend the tables. Since the period values just divide by 2 each octave up, and multiply by 2 each down, it's dead easy to do.
Then just compare the period with all your octave values until you find the closest one, and that's your note. What I did when I was writing a MOD player a while back was just take a table of the middle C octave and just shift the periods left/right to get the other octaves. Then you store the notes as byte values instead of periods to save space. You can just look up the frequency for that note in a table instead of having to convert the period value first, but you kind of have to use periods for portamento/vibrato effects anyway, and with a little algebra on paper you can work things down to where you just do a few multiplications and one divide to convert the note period to your increment value to feed to the mixer.
For the note values, you could do like Impulse Tracker and use 10 octaves, so notes are 0-120 (12 notes/octave), or use 4 bits for the note value and the other 4 for the octave, or say middle C is 0, and use signed values so the notes go up/down from there, however you want to do it, as long as it works, it works (personally I'd go with the first one, since it's simple and leaves one free bit, which packs nicely with the rest of the row data (you can use the free bit with the 4 free bits from the effect column to make a 5 bit value for the sample))
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#13021 - poslundc - Wed Dec 03, 2003 8:00 pm

Sweet, that file is even better than the one I've been using.

Dan.