SMPS Optimizer

Discussion in 'Utilities' started by ValleyBell, Dec 1, 2012.

  1. ValleyBell

    ValleyBell Well-Known Member Member

    Joined:
    Dec 23, 2011
    Messages:
    126
    SMPS Optimizer is a small commandline tool that helps you to reduce the size of SMPS files.

    In order to make very small SMPS files, it processes the SMPS file 3 times:
    Pass 1: During this pass it does some general optimizations. (omit note/delay commands where possible, remove volume changes that are overridden at the tick)
    Pass 2: Small consecutive delays (likely to happen with mid2smps) are turned into one larger delay.
    Pass 3: This is probably the most efficient pass. The tool searches for repeating commands and turns them into F7 loops.

    I wrote this tool to reduce of the size of the large SMPS files mid2smps creates, but it also works well with xm?smps conversions.
    It is still no replacement for manual optimization.

    SMPS Optimizer fully supports the SMPS formats of Sonic 1, Sonic 3 & Knuckles. There's also support for generic SMPS 68k formats and Ristar, but I haven't tested these two.

    This version features a few bugfixes and improvements (like nested loops), compared to the version I included with the mid2smps 0.3 beta.

    Also you can use the -p parameter to choose, which passes the tool should execute. (all passes are enabled, if you omit the parameter)
    If you notice any bugs, please don't hesitate to report them.

    Download (Source)

    Enjoy!

    EDIT: Added source code.
    EDIT2: Updated the tool (some bugfixes, added -p parameter)
    EDIT3: Updated the tool (finally fixed the loop detection bug)
     
    Last edited: Jul 13, 2016
    HackGame, Robot Echidna and Clownacy like this.
  2. MarkeyJester

    MarkeyJester Sono una Lontra a Londra Member

    Joined:
    Jun 27, 2009
    Messages:
    2,499
    Location:
    Miss Fox's heart~
    Very cool stuffs, someone I know had recently used this and managed to shave off a lot of data, well done!
     
  3. redhotsonic

    redhotsonic Also known as RHS Staff

    Joined:
    Aug 10, 2007
    Messages:
    2,895
    Location:
    England
    Glad you got this program out. This will be extremely useful for anyone looking to shrink their ROM size. Does this also free up some processor speed if it's getting optimised?


    Awesome job.
     
  4. ValleyBell

    ValleyBell Well-Known Member Member

    Joined:
    Dec 23, 2011
    Messages:
    126
    Sorry, I'm terribly late with my reply, but I was busy with some projects and RL stuff.

    Anyway, thanks.

    I just updated the tool to fix a few bugs.

    One bug made a loop possible that starts in the middle of the E0 coord. flag, so the offset calculation failed and it generated an invalid loop.

    Also there was a bug related to nested loops.

    Finally I fixed the handling of the note-duration-delay-delay sequency for S3K SMPS files.

    And there's a new feature: the -p parameter, which allows you to select, which passes will be executed

    rhs: It mainly reduces the size of the SMPS files. The first two passes can save some CPU cycles, but loops need additional processing time, of course.
     
  5. Ivan YO

    Ivan YO Well-Known Member Member

    Joined:
    Jan 23, 2012
    Messages:
    56
    Wow, excellent program. Very good job, well done. :)
     
  6. ValleyBell

    ValleyBell Well-Known Member Member

    Joined:
    Dec 23, 2011
    Messages:
    126
  7. Bejitto

    Bejitto Newcomer Trialist

    Joined:
    Sep 29, 2013
    Messages:
    15
    Location:
    Land of the KFCs
    Hello, I'm having trouble using SMPS Optimizer, it just starts and shuts down, do I run it in command and if I do, what commands?
     
  8. Cris

    Cris Well-Known Member Member

    Joined:
    Jul 25, 2013
    Messages:
    52
    You have to open the smps optimizer in cmd.exe.Cmd it's on C:WindowsSystem32 folder in your pc.
     
  9. Bejitto

    Bejitto Newcomer Trialist

    Joined:
    Sep 29, 2013
    Messages:
    15
    Location:
    Land of the KFCs
    Yes I've done that but when I open it even in cmd the exe opens and just basically blinks.

    Any other commands?
     
  10. nineko

    nineko I am the Holy Cat Member

    Joined:
    Mar 24, 2008
    Messages:
    1,683
    Location:
    italy
    (note to other moderators: Bejitto didn't bump this topic, as it was autolocked. He posted in another topic, and I moved here the 3 posts above to keep them sorted)

    That said, I shouldn't really answer your question since smpsopt comes with a help. However:

    Code:
    smpsopt.exe s1 input.bin output.bin
     
    Last edited by a moderator: Sep 30, 2013
  11. Bejitto

    Bejitto Newcomer Trialist

    Joined:
    Sep 29, 2013
    Messages:
    15
    Location:
    Land of the KFCs
    Thank you so much, nineko, now I can continue with my hack!

    On the side note, ValleyBell, Both mid2smps and SMPS Optimizer are amazing!

    Sorry for bumping the other topic though...
     
  12. nineko

    nineko I am the Holy Cat Member

    Joined:
    Mar 24, 2008
    Messages:
    1,683
    Location:
    italy
    You didn't bump any topic. This one was locked, the other one wasn't, so you could post in it as much as you wanted. I moved your posts here because it makes more sense. I was actually informing the other moderators that you didn't break any rule, it was a good thing :)
     
    Last edited by a moderator: Oct 1, 2013
  13. ValleyBell

    ValleyBell Well-Known Member Member

    Joined:
    Dec 23, 2011
    Messages:
    126
    I just updated the tool - this should finally fix the annoying loop detection bug that breaks SMPS files under certain conditions.
    It should also remove the invalid FM instrument command from DAC channels now.
    The download is in the OP.


    If you want an example of the previously failing loop detection, here is an example from the Shantae: Burning Town SMPS I submitted to the SMPS competition recently:
    Code:
    SBT_Loop14:
        dc.b    nRst
    SBT_Loop15:
        dc.b    nC5, nRst, nC5, nRst, nC5, $06, $06, nRst, $0C, nC5
        smpsLoop    $00, $02, SBT_Loop14
    SBT_Loop16:
        dc.b    nRst, $0C
        smpsLoop    $01, $02, SBT_Loop15 ; <--- loops into a part of Loop14, so it does Loop14 again
        dc.b    nBb4, nRst, nBb4, nRst, nBb4, $06, $06, nRst, $0C, nBb4, nRst, nC5
        dc.b    nRst, nC5, nRst, nC5, $06, $06, nRst, $0C, nC5
        smpsLoop    $00, $02, SBT_Loop16 ; <--- loops into the end of Loop15, which results in doing Loop14 AGAIN implicitly
        ;            ^^ This should've been a $02, but the overlap detection fails, because Loop16 isn't overlapping Loop14 directly
     
    MarkeyJester likes this.
  14. PsychoMMS

    PsychoMMS Newcomer In Limbo

    Joined:
    Aug 26, 2016
    Messages:
    21
    Location:
    Argentina
    Thanks ValleyBell, i have a question, why when try to optimising a song for example Introduction theme from AWS Pro Moves Soccer in a point the instruments sounds out of place? I was put the loop with Midiorchestrator plus and programed the instruments with Mid2smps, When i save the song i optimize and when listen the instruments sounds out of place any idea?
     
  15. ValleyBell

    ValleyBell Well-Known Member Member

    Joined:
    Dec 23, 2011
    Messages:
    126
    The better question is actually: Did it sound correct before optimizing the song?
    The chance of SMPSOpt itself breaking the song during optimization should be really low by now.
    If it should be the case, try using the "-p12" parameter to skip the loop detection.

    In any case, before-after examples are the only way to really tell what happens and where something goes wrong.
     
  16. Ralakimus

    Ralakimus Walk in silence, don't walk away in silence Member

    Joined:
    Aug 26, 2013
    Messages:
    614
    Location:
    Hell
    I found a minor issue with this program. It seems that when I convert a file, it resets the initial PSG envelope IDs to 0. Like, for instance, in the header, a PSG channel was assigned to start off with PSG envelope 1, but in the optimized version of it, it got changed to 0.
     
  17. ValleyBell

    ValleyBell Well-Known Member Member

    Joined:
    Dec 23, 2011
    Messages:
    126
    This never happened to me. It should keep the PSG envelope defined in the header.
    Can you send me an example file and the command line you used?
     
  18. Ralakimus

    Ralakimus Walk in silence, don't walk away in silence Member

    Joined:
    Aug 26, 2013
    Messages:
    614
    Location:
    Hell
    Nevermind, I found the issue. I was converter from ASM to BIN so I could optimize it, but I forgot to update thes1smps2asm header file to use the same parameters as the current smps2asm header. It's all good now.

    Tip: Never do hacking at 2 AM.
     
    Last edited: May 19, 2017 at 3:59 PM
    Robot Echidna likes this.