don't click here

Porting Music to Sonic 1; What causes the Sega sound?

Discussion in 'Engineering & Reverse Engineering' started by WatuD2, Jan 23, 2017.

  1. Hello all,
    I'm currently doing some research into Sonic 1's sound driver.; you know, porting songs between other SMPS 68K games, using Esrael's Sound Importer, etc. One problem I've ran into consistently is that certain bad bytes within the DAC section of the hexadecimal codes set off the Sega sound. Now, I have two questions about this.

    1.) How does anything related to drums have the ability to set off a PCM sample? (The Sega Sound)

    2.) I know that the byte "0C" sets it off, but there are others and I can't pinpoint them. Does anyone have any input on this situation?

    I've looked around and wasn't able to find any topics or posts relating to this manner, though if anyone knows of some giant thread all about this, link it up and I'll do my best to scavenge for an answer.

    EDIT: By Byte "0C", I'm referring to the music binaries that come with the disassembly.
     
  2. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,192
    405
    63
    Japan
    The drum samples to Sonic 1 are stored as 4-bit DPCM samples and are stored inside the Z80 driver itself. The SEGA sample on the other hand is stored in the ROM, uncompressed as an 8-bit unsigned PCM sample, the Z80 driver sets the bank switch of the upper 8000 bytes (8000 - FFFF) to point to the 68k address of the SEGA sample, this is done right at the beginning as the driver is started. This allows the driver to just read data from the window, and immediately know it's the SEGA sample.

    Now, the DPCM samples have a table of Z80 pointers, pointing to the DPCM samples in Z80 RAM. This table only has three entries, accessing any entries outside of the three will access words from the DPCM samples themselves, of which are not pointers, but are being treated as such. Majority of the words being read just happen to either point to 8000+ (where the window is), or the size is larger enough for the Z80 to spill over into the 8000+ region. Which is why the SEGA sample just happens to play.

    As for 2. you're gonna have to be more specific by what you mean when you say 'byte "0C"'. Byte 0C of what? The SMPS DAC tracker value, a byte/offset in the Z80 driver?

    EDIT: To brief aside about Sonic 1's samples that are available:

    81 = Kick
    82 = Snare
    83 = Timpani (Just a placeholder of the table)
    84 = Invalid
    85 = Invalid
    86 = SEGA Sample
    87 = Invalid
    88 = Timpani (high)
    89 = Timpani (Mid)
    8A = Timpani (Low)
    8B = Timpani (Lower)
    8C+ = Invalid

    So I assume by 0C you mean sample ID 0C. In which case, yeah, that's why. It's an invalid entry in the table.
     
  3. Thanks for your reply!

    I'm sorry, should've elaborated more. By Byte "0C", I was referencing to the sample ID 0C. So, if there's any Sample ID that isn't between 81 & 8B, it loads in garbage that may just happen to be the Sega sound?
     
  4. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,192
    405
    63
    Japan
    Alright.

    Well, the trouble is, Sonic 1 only has three samples, of which one of them (the timpani) is playable through four different pitches. Sonic 2 has more samples, I believe there are toms, scratches, and so forth, and those do not exist in Sonic 1. You're options are either, to modify the drum tracker channel so that is uses whatever samples Sonic 1 has, and improvise. Or, you'll have to port over the drum samples themselves and setup the table accordingly, this isn't going to be an easy task though, since Sonic 1's samples are stored in the Z80 itself, it's almost nearly impossible to fit more samples in. Unless you removed the SEGA sample, and put your samples where the SEGA sample is, and read it that way, but I'm degressing a stupid option here. Your alternative solution would be to change the Z80 driver such that it uses a "different" PCM/DPCM playback driver, one with more flexibility.

    I would strongly recommend Mega PCM by vladikcomper http://forums.sonicretro.org/?showtopic=29057 This would be best suited to your needs. There's also Dual PCM https://forums.sonicretro.org/index.php?showtopic=36223

    However, some of it is a little technical. It depends on how far up to the challenge you are at ripping out and putting in new drivers, just to port music between games flawlessly.

    EDIT: There may also be a port for Sonic 3 & Knuckles' sound driver, but, I've not been interested enough to know the details, maybe someone else could help you out there...
     
  5. That would explain why porting the music from Mystic Cave 2P gives me no drums (except for an occasional kick, though I'm certain that's just a happy accident).

    So, just to make sure that I'm understanding this correctly, changing drivers will allow PCMs to take less space on the Z80 / store them somewhere else all together so that more samples can fit essentially support all of the sounds that are "missing" from Sonic 2?
     
  6. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,192
    405
    63
    Japan
    More or less, yes.

    The drivers I linked above work in a different principle. The most noteable one, is that the samples will be stored on the ROM itself, and the Z80 will access those through the bank window, this will allow you to have larger samples, and more of them.
     
  7. AURORA☆FIELDS

    AURORA☆FIELDS

    The cute one here Tech Member
    216
    24
    18
    Finland
    AMPS
    I want to give a recommendation to you; Do not use any pre-made importer tools to port music. Although they *will* work to some degree, it usually, if not always, leads to sloppy ports that do not sound good. And as a community we have evolved past this point, and I would suggest if you are up for the challenge, follow suit. I have made a toolkit to allow for easier porting between theoretically any two SMPS games. Now, porting between two games is not as easy task as it may seem. The trouble is, is that SMPS is kind of a shitty format. You see, there is no standardization, and this is why you need to ensure the SMPS files are compatible before you plop them from one game to another. This task is made easier with my version of SMPS2ASM, but you need to spend some time to prepare scripts, and then to manually edit out any missing DAC, PSG, and commands.

    The bottom line is, that it is gonna require way more effort, but as an end result you can get conversions that sounds miles better, and will have very minimal issues (So, nothing like that SEGA sound mess you have to deal with now :V). Of course, I can also offer some help if you get lost or confused, the best way you can reach me is SSRG IRC or Discord.