don't click here

SMPS in Sonic & Knuckles Collection

Discussion in 'Engineering & Reverse Engineering' started by MainMemory, May 4, 2014.

  1. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    The S&KC Mod Loader now has integrated music playback, making this mod obsolete.

    The HQ music hack is great, but I've wondered if it would be possible to play the original SMPS music. A few days ago, ValleyBell pointed me to the source code of SMPSPlay and over the course of several days we were able to hack together something that played only S3K's music and worked with S&KC.

    You can download SMPSOUT.DLL here. To use it, simply extract it to Sonic & Knuckles Collection's install folder, and rename it to MIDIOUT.DLL (or MIDIOUTX.DLL to use it as a fallback for the HQ music hack).

    Features:
    • SMPS playback by ValleyBell
    • Plays Sonic 3's midboss theme in Sonic 3 mode
    • Speed shoes and special stage speedups work perfectly
    • Doesn't make S&KC run faster than it's supposed to

    The source code is up on Sonic Retro's GitHub, and I may add support for an INI file specifying whether to play the S3 or S&K version of applicable songs.

    Requires Visual C++ 2013 Runtime.
     
  2. Tiddles

    Tiddles

    Diamond Dust Tech Member
    471
    0
    0
    Leicester, England
    Get in an accident and wake up in 1973
    Aha, brilliant. Love the SMPSPlay sample clarity. I'd say it's nice to play S&KC with the proper instruments, but it's actually never nice to play S&KC. This certainly improves the experience though!

    A couple of observations you may already be aware of:

    • S&K Knuckles' theme seems to be using the drum clap from S3 Knuckles/Miniboss instead of sample that replaced it in S&K.
    • There's the odd dropped note here and there, most obviously at the beginning of Sky Sanctuary. I don't know if it's exactly the same issue, but it sounds very similar to what happens in v1-v2 of flamewing's improved S&K driver due to a fix to make certain note/rest/duration sequences work like S1/S2, when some S3 music actually relies on the S3 behaviour.
    I don't suppose there's any practical way to make fading work in S&KC? That would make things sound quite a lot better I think. I guess it'd somewhat depend where the code for that sits - I'm hoping they were lazy enough to still send E1/E5 to the sound engine and have midiout do something appropriate.

    Those default sound effects sound especially rough compared to the music now, too! I seem to recall there are tools to improve this. I wonder if SMPSPlay could be used to pre-generate high quality SFX to be packed into the right format to replace the existing ones.

    But anyway - fantastic stuff! If you wanted to do a version of this with the SMPS conversions of the unique PC tracks ValleyBell did for S3C, I'd be happy for that to happen if he is.
     
  3. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    I was missing a couple of configuration settings that were making Sky Sanctuary play incorrectly, which have now been fixed. As for Knuckles' theme, it should be switching that sample whenever it switches between S3 and S&K tracks, and the S&K version is default, so unless I got them switched, it shouldn't be playing the S3 sample in the S&K track.

    The game does check for track E1 and stop the music, so it may be possible to add a fade out command.

    You recall correctly, my SKCsnd tool has options to change the sound effect format.

    Having SMPS versions of the S&KC music sounds like a fun option for the next major release.
     
  4. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,188
    398
    63
    Japan
    Fantastic work guys! I was idling in the channel watching you guys have at this, you've put a great deal of work into it!

    Is there a possibility you could post a few say; YouTube videos(?) of how the music sounds with this new driver? I'm interested, but don't really have the time to go digging through for my copy of S&KC, just to hear what you guys have accomplished.
     
  5. Tiddles

    Tiddles

    Diamond Dust Tech Member
    471
    0
    0
    Leicester, England
    Get in an accident and wake up in 1973
    I had been using the sound test, but I just did some more testing. It definitely works properly if you start S&K as Knuckles and listen to it there, but if you go into the sound test, play 00 (S3 opening theme) and then play that track again, it will have gone back to the S3 DAC, and it always seemed to use the S3 DAC if I started S3&K at AIZ (from a saved game, for what it's worth). So it seems like it might be switching itself to S3 mode a bit too readily and never coming back. flamewing's driver simply remaps the S3 versions onto new sample IDs (D8/D9 I believe?) and that's always worked well for S3C, so that's one possible route; in the olden days of poking at the binary sound driver, I used to just remap the DAC pointers each time one of the affected tracks was requested.

    Along with that, the INI file you suggest for swapping S3/S&K tracks would obviously be something I'd personally enjoy - I guess all of these options could probably be consolidated in such a file.
     
  6. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    I've updated the DLL with two new features: track selection via INI, and fadeouts.

    The INI file should be named SMPSOUT.ini, and may contain the following entries:
    TitleScreenTrack=S3 or S&K
    MidbossTrack=S3 or S&K
    KnucklesTrack=S3 or S&K
    1UpTrack=S3 or S&K
    InvincibilityTrack=S3 or S&K
    AllClearTrack=S3 or S&K
    CreditsTrack=S3 or S&K

    http://youtu.be/_4i1UORKo50
     
  7. Tiddles

    Tiddles

    Diamond Dust Tech Member
    471
    0
    0
    Leicester, England
    Get in an accident and wake up in 1973
    Ah, beautiful job on the fading! I always thought that was one of the clunkiest things about the music in S&KC, so that's a great fix.

    (As it happens, the video does demonstrate the Knuckles' theme DAC issue - compare that to how it sounds if you start up S&K mode and listen to Knuckles' opening.)
     
  8. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    Turns out, I had forgotten to set the flag indicating which sample was in use. I added one line and it's all fixed.

    Now I just need those S&KC music files you use.
     
  9. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    Thanks to Tiddles, I have added SMPS versions of the S&KC music, and the credits song from the Sonic 3C prototype. As it is now, the SMPSOUT.ini file format looks like this:
    Code (Text):
    1. TitleScreenTrack=S3 or S&K
    2. CarnivalNight1Track=MD or PC
    3. CarnivalNight2Track=MD or PC
    4. IceCap1Track=MD or PC
    5. IceCap2Track=MD or PC
    6. LaunchBase1Track=MD or PC
    7. LaunchBase2Track=MD or PC
    8. MidbossTrack=S3 or S&K
    9. KnucklesTrack=S3, S&K or PC
    10. ContinueTrack=S3 or S&K
    11. CompetitionMenuTrack=MD or PC
    12. 1UpTrack=S3 or S&K
    13. InvincibilityTrack=S3, S&K or PC (uses unused track)
    14. AllClearTrack=S3 or S&K
    15. CreditsTrack=S3, S&K, S3C or PC
    I have also added per-game settings. Any settings in a section named [S3K], [S&K] or [S3] will only be in effect when playing those games, and all settings in the root section will always be in effect unless overridden by a per-game setting.

    The S&KC tracks have been left out of the source code on GitHub at Tiddles' request.

    Edit: I've fixed IceCap 2's track selection and added the S3 Continue theme at Tiddles' request.
     
  10. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    ValleyBell has done a bit of work recently which has resulted in a new feature: by setting the BGM mode to FM Synthesizer in RUNSONIC.EXE and adding the line FMDrums=True in SMPSOUT.ini, you will get FM drums instead of DAC drums.
    Additionally he has added some new tracks:
    • A version of S3's invincibility based on S&KC's version of that track, available with InvincibilityTrack=S3PC.
    • The credits music from the 0525 S&K prototype, available with CreditsTrack=S&K0525.
    • The all clear music from the 0525 S&K prototype, available with AllClearTrack=S&K0525.
    • The title screen music from the 0525 S&K prototype, available with TitleScreenTrack=S&K0525.
    Additionally, I have added a feature myself: for any track, you can specify Random to have it play a random track from the available options.
     
  11. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    One last feature from me: for any track (including ones that previously had no options) you can specify MIDI to have it fall back on the original MIDI track, as long as the original MIDIOUT.DLL is named MIDIOUTY.DLL. This makes it possible to have the HQ music mod fall back on the SMPS music mod, which itself falls back on the original MIDI tracks.
     
  12. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    Since the contest is nearly over, I suppose I should make an update post.
    When I entered this in the contest, I figured I should add a new feature for it, and chose to go for Sonic 3D music, because it's the same SMPS version as S3K with a few different DAC samples. So ValleyBell got the coding set up and I added in the tracks where I felt appropriate.
    I also added a new feature to the config tool: song previews.
    [​IMG]
    With this feature, it's now possible for people without S&KC to download the mod and just listen via the config tool, and it's possible for any program that supports C interop to use SMPSOUT.DLL to play music.
    I also recorded a couple new videos:
    http://www.youtube.com/watch?v=6K80n7Jyezw
    http://www.youtube.com/watch?v=-L7w6km4Zso
     
  13. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    Early today, ValleyBell made a commit that enabled the player to play S1 and S2 music. As I went about adding the new music in, I realized that the method for adding a song was really dumb, requiring editing no less than five places in the code. So I wrote a program to parse a couple of INI files for song info and generate the necessary data structures, then added in all the music from S1, S2 and S2Beta. Then I updated SMPSCFG to use the ini files too. Unfortunately it appears there is a bug that causes S2Beta songs to crash S&KC, but not SMPSCFG (or the SMPSPlay program), and since ValleyBell just left for a two week vacation, I had to remove them by way of commenting them out. I fixed it, and now they work fine.

    TL;DR S&KC SMPS Player can now play all the music from Sonic 1 and Sonic 2.

    Potential future features:
    • Music resume after 1-Up (current SMPSPlay supports it, SMPSOUT's driver will need updating)
    • SMPS sound effects (again, driver will need updating)
     
  14. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,188
    398
    63
    Japan
    Hah, this just gets better and better guys, fantastic work! It's really enjoyable seeing this go above and beyond expectations!

    Just curious here. Is there a chance we could have the SFX looked at for improvement?

    I'm aware they're samples at a low quality rate, but perhaps it'd be interesting to have those SFX played by the SMPS driver itself like they initially were, maybe even altering the software for the SMPS driver to extend and in-place additional FM and PSG channels specifically for SFX to avoid music interruption, perhaps an option to allow the player to select between; SFX interrupting standard channels, or using their the additional in-placed channels.

    Or if that seems like quite a steep task not worth doing, then at least rerecording the SFX from the original title at a higher rate?
     
  15. nineko

    nineko

    I am the Holy Cat Tech Member
    6,296
    475
    63
    italy
    MainMemory himself said that SMPS sound effects are a possible future improvement.

    For now you can indeed replace the recorded ones with higher quality ones, both MainMemory and I released programs to do so, just keep in mind that the PCM format is hardcoded inside the executable and affects the whole game; it's easy to change that format of course, it's a known byte, but then you'll have to replace all the sfxs with higher quality ones. I did try to do that years ago, but the game gave me some problems with 44100Hz waves, not sure why, maybe I did something wrong (I wouldn't be surprised), some sfxs "clicked" at the end, even if my recordings were good.
     
  16. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    One other thing that was discussed was having it play individual wav files for each sound effect, which would allow for any sfx and not interrupt the music. I just have to figure out how to play a wav file and where to inject my code.

    Edit: I fixed the bug and added S2Beta music.

    Edit 2: I fixed a bug with Spring Yard, thanks to ValleyBell.
     
  17. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
    New Features:
    • Separate Super Sonic track
    • Custom songs


    For custom songs, simply create a file named songs_cust.ini in the S&KC folder with the same format as songs.ini, and every song specified in that INI will be available as an option for every track.
    Example:
    Code (Text):
    1. [mysong] ; this will be the name it uses in the config tool/file
    2. Type=S1 ; or S2, S2B, S3, SK, S3D
    3. Offset=0000 ; hex number, S1 format songs are always 0, others depend on the song's location in ROM/RAM
    4. File=mysong.bin ; must be uncompressed, songs with nonexistent files are skipped
    Edit: I forgot to update the INIs for the Super Sonic track.
     
  18. Puto

    Puto

    Shin'ichi Kudō, detective. Tech Member
    2,013
    0
    16
    Portugal, Oeiras
    Part of Team Megamix, but haven't done any actual work in ages.
    Random question: Would it be possible to add in the SEGA sound?
     
  19. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,734
    330
    63
    SonLVL
  20. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,188
    398
    63
    Japan
    ...I was just going to suggest using the one from Mega Collection, it's the highest quality recording of the SEGA sound as far as I know... Nice work regardless!