Mod Archive Forums

Community => Project / Coder's Corner => Topic started by: Sayman on May 26, 2021, 08:52:39

Title: MOD files BPM and Temp parameters/commands
Post by: Sayman on May 26, 2021, 08:52:39
Hello All! I have some 8 bit machine based on Z80 CPU. I try to write MOD player, but confront wirh a problem.
This 8 bit machine not have DMA and not have CIA or similar device. So, i need to work with samples and speed and bpm parameters in realrtime (or with tables). I need to convert BMP and speed to bytes per tick/row. I know about standart formula - speed/(BPM*2), but this is in milliseconds (or in Hz). But, i need to calculate - how many byutes i need to send in sound device per speed tick (or row). Can somebody help me?
Title: Re: MOD files BPM and Temp parameters/commands
Post by: Saga Musix on May 26, 2021, 22:48:22
With milliseconds, you're almost there, you just need one more calculation. First, you need to know the sample rate at which you're mixing. For example, if your sample rate is 48000 Hz, then 1 second (or 1000 milliseconds) will be 48000 samples long. So if your sound signal has 8-bit quality, that would be 48000 bytes, if it-s 16-bit quality then 96000 bytes and so on. So if your tick duration is 10ms, that would be 48000*10/1000=480 samples.
Title: Re: MOD files BPM and Temp parameters/commands
Post by: Sayman on July 15, 2021, 07:58:56
Hello again. Ok, about BPM and tempo, I seem to have understood and figured it out.
But another question i have: when playing, periods are used. How can these
periods be converted to sample movement? let's say, the note A-4 is encountered,
it has some period. To reproduce the sample at this note (frequency), this
period must be converted to a certain value that will indicate the offset in the
sample.
Title: Re: MOD files BPM and Temp parameters/commands
Post by: Saga Musix on July 15, 2021, 18:43:58
Periods are divisions of the Amiga's CPU clock, so the frequency is derived from the formula 3546895 / period. If you have the possibility to use a custom MOD format for your player, I would recommend against using the Amiga pattern data as-is, because in particular the period values make it harder to use than necessary. On the earliest Amiga trackers this made sense when there was no finetune (you could just send the period, as it was written in the pattern data, to the hardware) but as soon as finetune comes into play, even on Amiga this optimization doesn't make sense anymore. So to save some cycles, you may want to either put note values in converted pattern data, or directly whatever numeric value your mixer needs to determine at which speed to advance the sample data.