Sonic and Sega Retro Message Board: Demo of entirely C-based SMPS Playback Engine NOW WITH SOURCE - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
  • 3 Pages +
  • 1
  • 2
  • 3
    Locked
    Locked Forum

Demo of entirely C-based SMPS Playback Engine NOW WITH SOURCE SOURCE CODE RELEASE 1/08/09

#1 User is offline Rob Jinnai 

  Posted 06 November 2008 - 12:29 AM

  • Not really master of theory debunking anymore
  • Posts: 215
  • Joined: 17-April 03
  • Gender:Male
  • Project:Custom Game Engine Prototypes
  • Wiki edits:1
Source release 1/08/2009:

http://www.el-hazard...PSDemoFinal.zip

Have fun, read the README.txt, don't bother me for feature requests. :)

Fixes a lot of bugs, does not improve the core or Sonic 1 tempo. You guys can take care of that, I have other things to tend to. :)

OLD POST TO FOLLOW:
--------------------------
Okay, so here's the basic premise -- I spent some time to learn and understand the almost entirely undocumented (as of s2dasm2007) Sonic 2 Z80 playback engine. This resulted in a heavily commented and relabeled edition of the assembler currently held only privately on my side. And really the only reason for that is I did a few test hacks to disable Saxman compression and have it read from ROM in bank form (more or less S2B style, but I hadn't actually known that's what S2B did before I did it.)

But anyway, after successfully figuring out about 95% of the disassembly, I then decided to reprogram it in C, in hopes to maybe make it clearer to others plus possibly provide "preview" functionality to music editors. The YM2612 and SN76496 emulation sources (each a single C file) were pulled from an old DOS GYM player (MSP anyone?), so they're probably not top of the line, but they were easy to integrate. The DAC decoding is a direct C implementation of jman2050's decoder logic (even performed in realtime so it stays in sync properly), the Saxman decoder is a fresh version mostly based on the Z80 code with just a little help from KENS, and the main SMPS guts are my own reproduction from the Z80. Using a little load-time logic, it successfully plays almost all Sonic 1 and Sonic 2 tunes very well, though not quite flawlessly yet.

Download SMPS Demo

This includes direct-from-disassembly Sonic 1 and Sonic 2 SMPS songs. I have not tried 3rd party music yet. If you have some laying around, let me know how it goes. You will need to give it the proper file extension (listed below) because the player does NOT autodetect yet and WILL crash on a bad read. :P Press UP/DOWN to select, ENTER to play, ESCAPE to quit.

Known problems:
  • Periodically, I seem to lose a track somewhere; Super Sonic for example is missing a base or something
  • Sonic 1's tempo is NOT right yet; the Ending song is the most dramatic example of it going waaay wrong!
Now onto the fun techy stuff: :)

I have not yet thought of a foolproof autodetection system, so the player currently uses the file extension to determine the SMPS data variant, and supports the following without modification:
  • ".smp" -- Sonic 1 68K relative-addressing SMPS
  • ".sax" -- Sonic 2 Saxman compressed music (assumes the 1380h fixed starting position)
  • ".rom" -- Music pulled from ROM bank (a few Sonic 2 Final songs use this; automatically finds their original bank offset and 'relativizes' them.)
(For anyone with ideas -- Saxman is easy to autodetect because byte 02 is always FFh which wouldn't make sense in the other formats; any ideas for differentiating Sonic 2 banked vs Sonic 1?)

I have implemented the full coordination flag set from the Music Hacking page, including the Sonic 3 ones. I believe this will be able to play Sonic 3 tunes with little additional work (the larger DAC set and the universal table would need to be implemented, obviously.) Speaking of which, just a few CF notes from my journey that I'd like verified or something:
  • E1 -- "Alter note values by xx???"; specifically, this adds a raw signed value to the frequency of the FM or PSG, sort of a pitch bend
  • E2 -- ALSO exists in Sonic 1/2 and does take a parameter; in S2, it sets zComRange+6 based on the supplied parameter, though I don't see any purpose for it? Possibly used for timing? (E.g. it appears in the Ending music and might be used to sync it) This explains why Sonic 3 supplies E2 FF probably; it's still a flag write, but I guess 'FF' means fade-in for Sonic 3 only.
  • E7 -- listed, likely by mistake, to take a parameter; it does not
  • EC --"Change channel volume to xx; xx is signed"; this is not quite correct. This actually only adds to (not "change it to") the volume like E6, but won't take effect until the next FM voice change (it sets the internal volume level but does not apply it to the TL registers)
  • EE -- listed with a vauge "something to do with voice selection", which I'm not sure where that came from? In reality it's unimplemented in Sonic 2... in fact, erroneously implemented such that using it would skip the next command byte!
Now, finally, a couple things I'd like help with:
  • Does anyone know what Sonic 1's tempo value means? Sonic 2's is simply a ratio of the 60Hz clock, with 0x40 = 15Hz, 0x80=30Hz, 0xC0 = 45Hz, 0xFF = ~60Hz; right now I'm using a guessed "sounds good" equation to convert it, but it's obviously wrong in a few cases (the "Drowning" song and the "Credits" song are the most clear examples... listen to the latter just take off!)
  • My DAC is a little fast... I was trying to coordinate it with the clock of the SN76496 since the Z80 engine busy-waits to slow down the playback rate, but it does seem to have a little more control than that somewhere. Anyone know exactly how it's timed? Failing that, anyone know the normal base rate (in Hertz) of the full-speed (rate 0) DAC playback?
I'm withholding source code pending cleanup and bug fixes... unless anyone demands it right this minute and wishes to fix the bugs for me. :) Ultimately I plan to make it available. It's mostly ANSI C except for the sound stream buffering and lame GUI, which is currently written using Allegro. However it is not really relying on it and you could easily convert it to dump to disk or write a buffer to play it through or whatever else you might want to do. I'll be glad to help rip that part off if anyone gets into it.
This post has been edited by Rob Jinnai: 08 January 2009 - 10:29 PM

#2 User is offline Quexinos 

Posted 06 November 2008 - 12:34 AM

  • Since 1997
  • Posts: 1672
  • Joined: 24-April 03
  • Gender:Female
  • Wiki edits:11

View PostRob Jinnai, on Nov 5 2008, 11:29 PM, said:

Known problems:
  • Periodically, I seem to lose a track somewhere; Super Sonic for example is missing a base or something
  • Sonic 1's tempo is NOT right yet; the Ending song is the most dramatic example of it going waaay wrong!

But give it a listen anyway because it sounds awesome I think :)

#3 User is offline Irixion 

Posted 06 November 2008 - 01:14 AM

  • Posts: 1414
  • Joined: 30-December 04
  • Gender:Male
  • Location:Ontario, Canada
  • Project:Life
  • Wiki edits:152
...Holy shit?

You + Nineko = win. Please team up and make an xm3smps remake! :D:D:D:D

#4 User is offline nineko 

Posted 06 November 2008 - 01:17 AM

  • I am the Holy Cat
  • Posts: 5341
  • Joined: 17-August 06
  • Gender:Male
  • Location:italy
  • Project:I... don't even know anymore :U
  • Wiki edits:5,251
:O

View PostRob Jinnai, on Nov 6 2008, 06:29 AM, said:

E1 -- "Alter note values by xx???"; specifically, this adds a raw signed value to the frequency of the FM or PSG, sort of a pitch bend
There are no words that can describe my feelings right now.
I love you in the best possible non-gay way.

#5 User is offline Oerg866 

Posted 06 November 2008 - 06:12 AM

  • Posts: 1735
  • Joined: 07-September 06
  • Gender:Male
  • Location:Frankfurt, Germany
  • Wiki edits:3
^This

FUCK this is so unbelievably awesome, you win every single pixel of this forum

Hats off to you, sir :D

also, I agree, Nineko should make a preview option for XM3SMPS. Umm... Please? :P For example, make it call SMPSDemo.exe %file% and make it run in the background :D

This is unbeleivably awesome. I can't get over it. We're not worthy :D :D :D
This post has been edited by Oerg866: 06 November 2008 - 06:18 AM

#6 User is offline roxahris 

Posted 06 November 2008 - 06:24 AM

  • Everyone's a hypocrite. Take my word for it.
  • Posts: 1221
  • Joined: 24-January 07
  • Gender:Male
  • Project:Doing anything at all
  • Wiki edits:30
I should have commented before! This is amazing!

Will you add support for the other coordination flags from later SMPS games, though? There are various flags that Sonic 1/2 don't support, but they are there in songs I've ported.
This post has been edited by roxahris: 06 November 2008 - 06:25 AM

#7 User is offline Puto 

Posted 06 November 2008 - 06:24 AM

  • Shin'ichi Kudō, detective.
  • Posts: 2007
  • Joined: 31-July 05
  • Gender:Male
  • Location:Portugal, Oeiras
  • Project:Part of Team Megamix, but haven't done any actual work in ages.
  • Wiki edits:51

View PostRob Jinnai, on Nov 6 2008, 05:29 AM, said:

[*]My DAC is a little fast... I was trying to coordinate it with the clock of the SN76496 since the Z80 engine busy-waits to slow down the playback rate, but it does seem to have a little more control than that somewhere. Anyone know exactly how it's timed? Failing that, anyone know the normal base rate (in Hertz) of the full-speed (rate 0) DAC playback?

There is no rate 0 (the driver takes that as 256 instead). Rate 1 is somewhere in the 32khz area, though not sure of the exact frequency.

#8 User is offline Tweaker 

Posted 06 November 2008 - 06:30 AM

  • Posts: 12389
  • Joined: 27-June 04
  • Gender:Male
As I said when you showed it to me before, excellent work! My highest form of criticism right now would be the inaccuracy of the YM2612 core you've used, but everything else is practically spot on.

As for the issue with the DAC, I believe that the highest speed the Z80 can stream to it uncompressed is somewhere around 22khz; using the DAC compression that the samples use in-game, it appears to stream at about roughly 12-16khz, which some natural quality loss as a result of decompression.

Does this support 6 FM channels at once, yet? The Sonic 1 Special Stage music doesn't appear to play all 6 FM channels as it should.

Sonic 1's tempo works on a scale of $01-$0F, $00 being the max speed you can have. The range is, as such, not as wide as Sonic 2's... I don't know the exact frequency ratio there, but maybe that can help you work it out.

Anyway, great stuff! I hope this can eventually turn into an all-purpose library from which people will be able to play SMPS music. :)

View Postroxahris, on Nov 6 2008, 06:24 AM, said:

I should have commented before! This is amazing!

Will you add support for the other coordination flags from later SMPS games, though? There are various flags that Sonic 1/2 don't support, but they are there in songs I've ported.

Those flags differ from game-to-game, and as such would not be possible to support with entirely disassembling those versions of SMPS, adding an extra player subsection in the code to support them, and then giving it another file extension. I think it's good that this supports "basic" SMPS (even if basic SMPS uses the Sonic 3 coordination flag setup).

#9 User is offline Oerg866 

Posted 06 November 2008 - 06:32 AM

  • Posts: 1735
  • Joined: 07-September 06
  • Gender:Male
  • Location:Frankfurt, Germany
  • Wiki edits:3
Could this be ported to DOS?

I mean, it was a DOS VGM Player, and Allegro can be compiled for DOS with DJGPP after all
This post has been edited by Oerg866: 06 November 2008 - 06:35 AM

#10 User is offline Puto 

Posted 06 November 2008 - 06:38 AM

  • Shin'ichi Kudō, detective.
  • Posts: 2007
  • Joined: 31-July 05
  • Gender:Male
  • Location:Portugal, Oeiras
  • Project:Part of Team Megamix, but haven't done any actual work in ages.
  • Wiki edits:51

View PostTweaker, on Nov 6 2008, 11:30 AM, said:

As for the issue with the DAC, I believe that the highest speed the Z80 can stream to it uncompressed is somewhere around 22khz; using the DAC compression that the samples use in-game, it appears to stream at about roughly 12-16khz, which some natural quality loss as a result of decompression.

Hell no, I know I've used higher sampling rates than that at least at one point.

#11 User is offline roxahris 

Posted 06 November 2008 - 06:57 AM

  • Everyone's a hypocrite. Take my word for it.
  • Posts: 1221
  • Joined: 24-January 07
  • Gender:Male
  • Project:Doing anything at all
  • Wiki edits:30
I really should edit my post for this, but... eh.
I've been testing various conversions, and they sound mostly okay... with the exception of the PSG, which in various occasions randomly beeps until it's actually used in the song.

Also... SMPS games have different extra flags? That's odd...

#12 User is offline Oerg866 

Posted 06 November 2008 - 07:06 AM

  • Posts: 1735
  • Joined: 07-September 06
  • Gender:Male
  • Location:Frankfurt, Germany
  • Wiki edits:3
Hi-Hats on XM3SMPS Sonic 1 Songs only give garbled mess.

http://oerg866.oe.fu...e/Unbenannt.wma <-- listen

Also this might be a bug in I dunno Xm3smps or the MD hardware because when I load a vgm of a XM3SMPS Song into MOD2PSG2, I have to play a note before the hats, so that they work correctly, otherwise it will sound like in the wma.

#13 User is offline Puto 

Posted 06 November 2008 - 07:36 AM

  • Shin'ichi Kudō, detective.
  • Posts: 2007
  • Joined: 31-July 05
  • Gender:Male
  • Location:Portugal, Oeiras
  • Project:Part of Team Megamix, but haven't done any actual work in ages.
  • Wiki edits:51
To fix the hi-hats just change their pitch to $F5 instead of $23. Yeah, it's weird, but it works.

#14 User is offline Hitaxas 

Posted 06 November 2008 - 08:05 AM

  • SEGA: Sorry Classic Sonic, we are sending you back to 1994
  • Posts: 1432
  • Joined: 30-September 07
  • Gender:Male
  • Location:Back in Litchfield,CT
  • Project:Sonic: Super Deformed (head director) - Slowly working on it.
  • Wiki edits:196
XM4SMPS plz?

This is truely epic. :)

#15 User is offline nineko 

Posted 06 November 2008 - 10:00 AM

  • I am the Holy Cat
  • Posts: 5341
  • Joined: 17-August 06
  • Gender:Male
  • Location:italy
  • Project:I... don't even know anymore :U
  • Wiki edits:5,251
The next time I see either "nineko" or "xm3smps" in this thread I'm going to murder someone.
This is Rob Jinnai's project. Let's not derail.

  • 3 Pages +
  • 1
  • 2
  • 3
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users