smps2mid

Discussion in 'Technical Discussion' started by ValleyBell, May 10, 2011.

  1. ValleyBell

    ValleyBell

    Tech Member
    237
    10
    18
    researching SMPS sound drivers
    As a preparation for mid2smps, I wrote an smps2mid converter.
    Now with source (Visual Basic 6), too.
    Last Update: v0.4.3

    It supports these ROMs:
    - Sonic 1
    - Sonic 2 (Final and Simon Wai Beta)
    - Sonic 3
    - Sonic & Knuckles (seems quite unstable)
    - Sonic 3D
    - Sonic and Crackers
    - Oerg866's SMPS Player
    - Sonic 1 SMS/GG
    - Sonic 2 SMS/GG
    - Sonic Chaos SMS/GG
    - Sonic Triple Trouble
    - Sonic Blast SMS/GG
    A music pointer offset can be specified, so other ROMs are supported, too.
    It's also possible to load raw SMPS bin-files. Offset correction has to be done via user input.
    There's an auto-detection for 68k or Z80 SMPS format, as well as Sonic 1 SMS.

    Most SMPS tricks (global tempo modifier and co.) are supported. It works almost 100%.
    Tempo calculation should be 100% correct. (Sonic 2 Final, Sonic and Crackers and Sonic 1 SMS were verified with vgm logs.)

    Bugs and issues (all non-Sonic-1):
    - currently only the DAC notes for Sonic 1/2 Bass Drum and Snare Drum are mapped to the correct GM sounds
    - the tool may display run time errors or stop commands and will close afterwards - this should happen rarely to never
    - instruments may be out-of-tune because of strange key displacement values

    On my TODO list:
    - instrument mapping editor (for YM2612, PSG and DAC)
    - making S3&K more stable (many music pointers seem wrong)
    - Pitch Bend instead of Portamento Control
    - Pitch Bend for modulation effects

    Thanks to:
    - all the people who contributed to the Music Hacking Guide
    - nineko for the tempo calcuation algorithm
    - saxman for the Sonic 2 music decompression

    Comments and suggestions are welcome.
     
  2. Tweaker

    Tweaker

    Misfit
    12,389
    0
    0
    Fantastic! I've been wanting something like this for a while. :D

    Out of curiosity, do you have any intent to add support for the opposite? A no-frills MIDI2SMPS converter with proper pitch bend support would be a dream come true.
     
  3. Spanner

    Spanner

    The Tool Member
    3,250
    44
    28
    United Kingdom
    Sonic Hacking Contest
    ValleyBell, have you had a look in the exported MIDIs in OpenMPT? Some of the instruments won't work until a few patterns later. Also, I assume it would be piss easy to get all other percussion to work, since my work usually has a lot more than the kick and snare.

    Good work so far, though.
     
  4. nineko

    nineko

    I am the Holy Cat Tech Member
    When will you stop being so awesome? :O

    This is WAY better than the useless proof of concept I made several months ago... I'd send you my source code but I doubt you would have any use of it :v:

    I can help with midi2smps if you'll want, though.
     
  5. PsychoSk8r

    PsychoSk8r

    HighKnights Oldbie
    2,580
    0
    0
    Walsall, UK
    30 Day Project: Revisited.A New Release!
    I would really love to see a MIDI to SMPS program.
    What you've just given us though is great for something I have planned. :D

    Edit: Ah, one thing I notice is that these Midis would be tough to work with, as the notes aren't arranged correctly into bars as they should be, upon inspection. Still a good tool if you want to listen to them though, or use on FL or something. =P
     
  6. nineko

    nineko

    I am the Holy Cat Tech Member
    <!--quoteo(post=585702:date=May 11 2011, 12:05 PM:name=PsychoSk8r)--><div class='quotetop'>QUOTE (PsychoSk8r @ May 11 2011, 12:05 PM) <a href="index.php?act=findpost&pid=585702"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Edit: Ah, one thing I notice is that these Midis would be tough to work with, as the notes aren't arranged correctly into bars as they should be, upon inspection.<!--QuoteEnd--></div><!--QuoteEEnd-->This happens because the existing Sonic songs don't have a standard number of smps time units per quarter note (GHZ uses 16, most other songs use 12 or 24 to be able to use triplets), making it impossible to match note to beats automatically. Furthermore, we have no indication of the time measure(s) used in those songs. Sonic 1 Special Stage is a 3/4; Sonic 2 CNZ has a small measure as intro; etc. Too many variables which would need manual input to be gotten right.
     
  7. ValleyBell

    ValleyBell

    Tech Member
    237
    10
    18
    researching SMPS sound drivers
    Thanks for all the positive feedback.

    <!--quoteo(post=585590:date=May 10 2011, 11:25 PM:name=SOTI)--><div class='quotetop'>QUOTE (SOTI @ May 10 2011, 11:25 PM) <a href="index.php?act=findpost&pid=585590"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->ValleyBell, have you had a look in the exported MIDIs in OpenMPT? Some of the instruments won't work until a few patterns later.<!--QuoteEnd--></div><!--QuoteEEnd-->No, I haven't even touched OpenMPT. About the instruments: an example would be nice.

    <!--quoteo(post=585630:date=May 11 2011, 02:00 AM:name=nineko)--><div class='quotetop'>QUOTE (nineko @ May 11 2011, 02:00 AM) <a href="index.php?act=findpost&pid=585630"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->I'd send you my source code but I doubt you would have any use of it :v:

    I can help with midi2smps if you'll want, though.<!--QuoteEnd--></div><!--QuoteEEnd-->I'd like to read your source. Maybe I'll get some nice ideas.
    I'll PM you about mid2smps when I have questions.

    <!--quoteo(post=585702:date=May 11 2011, 12:05 PM:name=PsychoSk8r)--><div class='quotetop'>QUOTE (PsychoSk8r @ May 11 2011, 12:05 PM) <a href="index.php?act=findpost&pid=585702"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->one thing I notice is that these Midis would be tough to work with, as the notes aren't arranged correctly into bars as they should be, upon inspection.<!--QuoteEnd--></div><!--QuoteEEnd-->That's what the small text box with the title "Midi Res:" is for. Type 12 or 24 (or maybe 16 - just as nineko said) in it and the timing should be correct.
    0 is some sort of auto-detection, but that's also affected by the calculated Tempo.
    e.g. a BPM of 500 would cause it to increase the ticks per quarter so that you have 125 BPM which makes more sense than 500.

    btw: I already have ideas for proper a PitchBend in SMPS files.
     
  8. Tanks

    Tanks

    Member
    1,028
    0
    16
    As someone who loves to compile accurate midis from games... This is sex. I figured there was some roundabout way to do SMPS -> XM -> MIDI, but this just rips out the middle men. You, dear sir, deserve a god damn medal.

    EDIT: If it's any help, I can get the BPM for the songs with the tempo issues. Just fixed up the Sonic 2 Race Results song with 60.9 BPM.
     
  9. ValleyBell

    ValleyBell

    Tech Member
    237
    10
    18
    researching SMPS sound drivers
    Actually the tempo issue is already fixed.
    I'll post an update in a few days.
     
  10. ValleyBell

    ValleyBell

    Tech Member
    237
    10
    18
    researching SMPS sound drivers
    The last few days I worked on smps2mid (not on mid2smps, as you might've expected).

    And these are the new features:
    - correct Tempo calculation for Sonic 2, Sonic 3 and later
    - support for unknown ROMs (by adding a pointers from a custom address)
    - support for extracted Z80 SMPS files with offsets different from zero
    - detection for loop-in-loop with the same index (prevents hanging in Sonic 3D Green Grove 1's DAC channel)
    - Surprise: support for Sonic 1 SMS (thanks to me for reverse-engineering the format :specialed:)

    Thanks to nineko for the icon. (Actually his icon looked like this, with the MIDI below the Sonic head, not the other way.)

    Link is <a href="http://www.mediafire.com/?3p2hz6rfu6woaxx" target="_blank">here</a> or in the <a href="http://forums.sonicretro.org/index.php?showtopic=25219" target="_blank">first post</a>.

    Enjoy!
     
  11. nineko

    nineko

    I am the Holy Cat Tech Member
    <!--quoteo(post=595700:date=Jun 15 2011, 08:43 PM:name=ValleyBell)--><div class='quotetop'>QUOTE (ValleyBell @ Jun 15 2011, 08:43 PM) <a href="index.php?act=findpost&pid=595700"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->support for Sonic 1 SMS<!--QuoteEnd--></div><!--QuoteEEnd-->I just tried this, and I will love you forever :O

    By the way, the 8-bit Sonic games developed by Aspect (Sonic 2, Sonic Chaos, Sonic Triple Trouble) use a modified version of smps, so I wonder if you would be able to support them as well with a minimal effort. More details from <a href="http://forums.sonicretro.org/index.php?showtopic=13236&view=findpost&p=358764" target="_blank">here</a> onwards. Pointers to Sonic 2 songs should be available with the disassembly, and I documented the ones in Sonic Chaos here: <a href="http://info.sonicretro.org/SCHG:Sonic_Chaos/sandbox" target="_blank" style="background: url(http://info.sonicretro.org/images/5/50/Reticon.png) right no-repeat; padding-right: 20px; border-bottom: 1px dotted #3366BB; color: #3366BB; cursor:pointer; text-decoration:none;" class="wiki">SCHG:Sonic_Chaos/sandbox</a>. I can easily do Sonic Triple Trouble as well if you want (maybe I already did but I didn't keep them), I'd be glad to work with you on another project :)

    edit: documented Sonic Triple Trouble for the sake of it: <a href="http://info.sonicretro.org/SCHG:Sonic_Triple_Trouble/sandbox" target="_blank" style="background: url(http://info.sonicretro.org/images/5/50/Reticon.png) right no-repeat; padding-right: 20px; border-bottom: 1px dotted #3366BB; color: #3366BB; cursor:pointer; text-decoration:none;" class="wiki">SCHG:Sonic_Triple_Trouble/sandbox</a>.
     
  12. ValleyBell

    ValleyBell

    Tech Member
    237
    10
    18
    researching SMPS sound drivers
    I guess it shouldn't be too compilicated to support them too.
    I'll have a look later. (I'll work on mid2smps first.)

    Btw: <a href="http://info.sonicretro.org/SCHG:Sonic_the_Hedgehog_(8-bit)#Music_Hacking" target="_blank" style="background: url(http://info.sonicretro.org/images/5/50/Reticon.png) right no-repeat; padding-right: 20px; border-bottom: 1px dotted #3366BB; color: #3366BB; cursor:pointer; text-decoration:none;" class="wiki">SCHG:Sonic_the_Hedgehog_(8-bit)#Music_Hacking</a>
     
  13. ICEknight

    ICEknight

    Researcher Researcher
    I've noticed that some songs in SMS Sonic seem to play a second time without drums, and the "life lost" tune repeats four times, each with less instruments.

    It sounds kind of cool, but I guess it's a bug. Nice update, in any case!
     
  14. ValleyBell

    ValleyBell

    Tech Member
    237
    10
    18
    researching SMPS sound drivers
    It's not a bug that the drums disappear when the second loops begins. It's just that the drum track is shorter/loops earlier than the melody tracks.
    A good example is Green Hill Zone MD: The Noise track stops after a few notes, because the "master loop" is only one note long.

    But the "life lost" tune shouldn't repeat - that's really a bug. (It's the only tune that lacks a loop start command - all other jingles have at least some empty loops.)
     
  15. ICEknight

    ICEknight

    Researcher Researcher
    I see, that makes sense.


    Something I was wondering is that, since MIDIs don't loop, is the general "track loop" info from the original file lost after conversion? Or is it still stored somewhere so converting the MIDI back to SMPS will loop like usual?


    If it's not possible to <I>convert to MIDI</I>, then <I>edit the MIDI</I>, then <I>convert back to SMPS with the looping melody intact</I>, I beg you to add support for other non-MIDI formats like XM. It would make the usefulness of this application multiply by a bunch. Please.
     
  16. Herm the Germ

    Herm the Germ

    Hmm, not bad. Well done, doctor! Member
    1,482
    0
    0
    Dresden, Saxony, Germany
    MIDI-to-SMPS-conversions, mostly. Takin' requests, too.
    I can confirm that Loop points are preserved in a manner that can, in turn, be understood by mid2smps, by placing MIDI Controller 111 set to 0 and 1 at the start and end of loop points, respectively.
     
  17. Hitaxas

    Hitaxas

    Retro 80's themed Paladins Twich streamer Member
    1,438
    0
    16
    Litchfield,CT
    Becoming a Twitch partner, and getting my life back together
    Along with ICEknight's request for XM support, I would also love to see a feature that allows ripping of the voices/samples from the midi, for a perfect conversion. I know it sounds lazy, but there are times when finding the perfect voice for a track can be frustrating.
     
  18. Herm the Germ

    Herm the Germ

    Hmm, not bad. Well done, doctor! Member
    1,482
    0
    0
    Dresden, Saxony, Germany
    MIDI-to-SMPS-conversions, mostly. Takin' requests, too.
    Can't Nineko's 2612 Instrument editor tool, found alongside Mid2smps, already rip voices from various sources? The resulting instrument assembly can then be used in conjunction with that tool to include the voices in the new track created, right?
     
  19. saxman

    saxman

    Oldbie Tech Member
    I used your utility: http://forums.sonicretro.org/index.php?showtopic=26025

    Very VERY useful! Thank you for making it!
     
  20. ValleyBell

    ValleyBell

    Tech Member
    237
    10
    18
    researching SMPS sound drivers
    Bump for smps2mid v0.3. (And today I release the source, too.)
    Aside from a few bugfixes and a now 100% GM-correct volume calculation, I did these few but big updates:

    - implemented Sonic 3 & Knuckles coordination flags
    - added support for the Master System/Game Gear games (including all revisions) Sonic 2, Sonic Chaos, Sonic Triple Trouble and Sonic Blast
    - improved Modulation controllers (they still ignore the vibrato delay, but at least it sounds good with the MS GS midi driver)
    - improved support for Oerg866's SMPS player - it now works with all SMPS player ROMs and not just the one I used

    Note on the Sonic 2 SMS and later SMPS format:
    They're 3 revisions. Sonic 2 (rev 1), Sonic Chaos (rev 2) and Sonic Triple Trouble/Sonic Blast (rev 3). rev2+ has additional coordination flags (D8 to DF) to set the channel volume. D8 is PSG volume 0, DF is PSG volume 7.
    rev3 (rev2 maybe too) has coord. flag FC, which does the same as flag EB in Sonic & Knuckles.
    rev1/2 and rev3 have a different way of calculating their frequencies, so the notes or the key displacement value in rev3 must be 3 octaves lower than in rev1/2.
    All the SMS drums that sound (they're some that don't do anything) and mapped to quite fitting GM drum sounds. (more hardcoded stuff :argh:)

    smps2mid still fails on some of the Sonic & Knuckles songs. The problem is that I seem to have a wrong music pointer list, so some of the music pointers are wrong.

    Happy converting!