don't click here

Explain to me how tempo modifiers work in SMPS

Discussion in 'Technical Discussion' started by wazkatango, Mar 4, 2011.

  1. Okay, I really need some help on this one, see title. Green Hill Zone, for example, has 03 for the tempo, and 01 for the divider, but what does that mean exactly? 03/01 = 3 beats per minute? Beats per second? Rows per millisecond?

    Basically, what I'm trying to figure out is a way to read those two bytes and come up with a conversion to plain bpm. I'm assuming that one beat is just one smps time unit at this point.
     
  2. Thorn

    Thorn

    Tech Member
    335
    19
    18
    Home
    Sonic 2 Retro Remix
    I don't know about "plain bpm" (forgive my musical ignorance), but given a tempo and divider A B, you can compare it to other tempos with the formula (B-1)/(AB). Note that A is read as is while B wraps around: calculations on it that reach 0 or lesser values wrap back to 256 (hex 100).
     
  3. nineko

    nineko

    I am the Holy Cat Tech Member
    6,308
    486
    63
    italy
    This question pops up from time to time, the answer should be put on the wiki. What Thorn said is correct for Sonic 1 only, as Sonic 2 and Sonic 3 & Knuckles use other timing methods.
    Let me expand upon Sonic 1's as it's the one I am more familiar with. First of all, a link to a post by Puto: http://forums.sonicretro.org/index.php?sho...st&p=249026 (I can't quote it because that thread is locked).
    Basically the fastest tempo you can achieve in smps is 0100 (read: run the sound engine for 255 frames out of 256. Keep in mind that a frame in NTSC is 1/60th of second, and a frame in PAL is 1/50th of second). As you can see it's easy to give a duration in (milli)seconds to an smps unit. How many smps units there are in a quarter note, half note, full note, ..., depends from song to song. Many of the official songs use 12 or 24 smps time units per quarter note ("beat"), but this isn't a rule and there are several exceptions, first but not least Green Hill Zone itself (16 smps time units per beat). If you plan to convert your own songs to smps you can decide to use as many smps time units per beat as you want, even 37 or other weird numbers. Just decide how much resolution do you need (a multiple of 2 AND 3 is a good idea if you want to have triplets), calculate how (milli)seconds per smps time units there are, and you're ready to go.
    For example, if your song runs at 150 bpm, and you want to use 4 smps time units per beat, you can use an smps tempo of 0302, 0403, or 0506. Because:
    150 beats per minute = 2.5 beats ("quarter notes") per second
    4 smps time units per beat = 10 smps time units per second
    By using a tempo of 0506, 1 smps time unit will be processed every (1/(((6-1)/6)/5)) frames, so 1 smps time unit = 6 frames. Since there are 60 frames per seconds (in NTSC mode), 10 smps time units will be processed every second. And so on.

    Green Hill Zone as you said is a 0103 which means that 1 smps time unit is processed every (1/(((3-1)/3)/1)) frames, so 1 smps time unit = 1.5 frames (of course this isn't possible, but the human ear can't notice that). As I said Green Hill Zone uses 16 smps time units per beat, so a beat lasts for 24 frames, or 0.4 seconds. Which -- once again -- means 150 bpm.

    tl;dr you can't convert smps time units to bpm if you don't know how many smps times units per beat were used to begin with.

    In my smps2midi converter I cheated by always writing the same midi data and editing the midi resolution in the header, but I had to prepare a table with the values for all the songs.