Basic Questions and Answers Thread

Discussion in 'Discussion & Q&A' started by Malevolence, Jul 7, 2009.

  1. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    374
    Location:
    Russia
    Speaking of PCM samples, they are stored in banks, which, in turn, appear as SNCBNK*.bin files on game's image. Each bank includes header, "sampled" instruments for SMPS PCM used in "past" versions of the songs and standard voices ("Future!", "Past!", a few Sonic's lines etc).
    Sample format is somewhat different from conventional 8-bit PCM (both signed and unsigned). Sega CD's own sound chip uses really weird and unique 8-bit sample format, where the first half of sample values (0-127) perfectly maps to 8-bit signed PCM, but the second half (128-255) is inverted. The conversion is really simple though.

    I cannot tell any more details, unfortunately; it's been years since I last touched Sonic CD and I never really explored it past basic filesystem.
    I just played a tiny bit with its sample banks once. I quickly wrote conversion tool from Sega CD's weird sample format to your ordinary 8-bit unsigned PCM, I also created a modification of Mega PCM to play this format natively, just for the fun of it (I doubt anyone would need this, since conversion is much simpler choice).
    Luckily, I still have this old stuff on my PC~

    Sonic CD's sample banks player ROM (uses modified Mega PCM to play Sega CD's sample format natively):
    https://www.dropbox.com/s/wrebttg3ij8jkiu/MegaPCM_SonicCD.gen?dl=0

    Mega CD PCM converter (+ source code):
    https://www.dropbox.com/s/v60swkkms2kfj47/SegaCD_PCM_Conv.7z?dl=0

    I didn't really have time to decode sample banks header format back then, so all banks play as one continuous sample with a bit of a noise in the beginning (which is obviously the header being played as sound). But samples can be easily separated in any sound editor, so...

    Hope this helps~
     
    Last edited: Feb 5, 2018
  2. MarkeyJester

    MarkeyJester Do you remember? Member

    Joined:
    Jun 27, 2009
    Messages:
    2,588
    Just to add a bit of boost of help. I needed to rip some samples when I made the Startdust Speedway Past tune, so I also wrote a tool to extract.

    http://mrjester.hapisan.com/01_Public/Sonic CD Samples.7z

    Again, just like Vlad's, it doesn't do a 100% top notch job, doesn't include the looping of samples, and cannot predict the sample rate, but it'll rip the samples as is, and extract them into .wav RIFF format for playback and use. The samples have already been ripped and are in that 7z file, but if the sample rate isn't to your liking, you can open up "List.txt", and change the first number (which is currently 22050), this is the Hz rate.

    Just run Program.exe, and it'll handle the rest.
     
    vladikcomper, ProjectFM and Pacguy like this.
  3. ValleyBell

    ValleyBell Well-Known Member Member

    Joined:
    Dec 23, 2011
    Messages:
    130
    Well then, I guess I'll join.

    I also made a tool to extract Sonic CD sounds (back in 2012).
    http://www.mediafire.com/file/zedzib8o6w01v99/SCD_Extract.zip (If you want to compile the source, you'll need to download stdtype.h, because I forgot to include it.)

    You drop one of the SNCBNK files on it and it will extract the samples as .wav at 16 KHz. It even adds loop information, though I can't remember whether or not it works properly. It was the only time I tried making looping WAVs.
    It also extracts a bunch of other data from the sound driver that you won't need, so don't be surprised.

    EDIT: Sorry, but I need to rectify myself. Writing loop information is currently disabled. In order to enable it, you need to edit the source code at line 449. Just change the 0 to a 1 and it should write the "smpl" chunk. (Nevertheless, it may or may not work correctly.)
     
    Last edited: Feb 5, 2018
  4. Pacguy

    Pacguy Testing the waters... Member

    Joined:
    Jul 5, 2014
    Messages:
    973
    Location:
    SOMEWHERE!!! OVER THE RAINBOW!!!
    Thanks for all the help! I have all the PCM samples I need from SCD now (It's awesome hearing them in high quality for the first time :))!
    I'm also trying to get the regular, non-PCM SFX too, like jump/skid/etc. ValleyBells' tool dumps them, but I can't quite convert them properly; smps2asm seems to recognize the file, but fails to port it properly. The closest thing I've found in my searches for porting these regular SFX is this old thread, but all it tells me is that its' probably using a bank relative offset like S2beta/S3/S&Ks drivers use. However, I don't know where to find the offsets. Usually, when porting music/sfx thats' read from an offset, I use this page to find where the offsets are saved in the rom and work from there, but there's no relevant info for SCD...
     
  5. Clownacy

    Clownacy UP - ON - CPU Staff

    Joined:
    Aug 15, 2014
    Messages:
    775
    Location:
    Englandland
    You need more than offsets. SCD's driver has a different set of coordination flags, which will make SMPS2ASM freak out. Some are just swapped around, but others outright don't exist in any other Sonic SMPS driver.
     
    Last edited: Feb 5, 2018
    Pacguy likes this.
  6. Pacguy

    Pacguy Testing the waters... Member

    Joined:
    Jul 5, 2014
    Messages:
    973
    Location:
    SOMEWHERE!!! OVER THE RAINBOW!!!
    Where can I find documentation on them? I can do my best to swap them out in a hex editor. I don't need perfect ports, and I don't need all of the SFX, so I might be able to live without those missing flags.
     
  7. Clownacy

    Clownacy UP - ON - CPU Staff

    Joined:
    Aug 15, 2014
    Messages:
    775
    Location:
    Englandland
    I just go by disassemblies. ValleyBell's SMPS Research Pack has SCD's driver in it.
     
  8. Pacguy

    Pacguy Testing the waters... Member

    Joined:
    Jul 5, 2014
    Messages:
    973
    Location:
    SOMEWHERE!!! OVER THE RAINBOW!!!
    Welp... The thread hosting the pack appears to have gone down at some point, and even if I had the code, I doubt I'd be able to figure out where the coordination flags are read/defined/etc., let alone what they do (I have absolutely no experience with sound driver coding). Its' a shame that they aren't on the SCHG SMPS page. I appreciate the help, though.

    EDIT: Actually, I have some previously converted SFX on hand. Maybe I can compare them, and find some equivalent flags myself...

    EDIT2: On further inspection, the SFX dumped by ValleyBells' tool appear to have no voice data... I think I've hit my limits here.
     
    Last edited: Feb 6, 2018
  9. CreeperGaming

    CreeperGaming Newcomer Trialist

    Joined:
    Oct 20, 2017
    Messages:
    9
    The Sonic CD stuff has been ripped before, in Valley Bell's SMPS Research:

    https://forums.sonicretro.org/index.php?showtopic=32473

    Not only does it have Sonic CD, it has a lot of other games too, like Knuckles' Chaotix.

    Edit: Nevermind, Clownacy already explained it, I saw the wrong comment.
     
  10. Pacguy

    Pacguy Testing the waters... Member

    Joined:
    Jul 5, 2014
    Messages:
    973
    Location:
    SOMEWHERE!!! OVER THE RAINBOW!!!
    What does this syntax do? I've been dealing with it a lot lately, but I've had to use nothing but guess work and working around it. I'd look up what it does, but I don't even know what its' called...
    Code:
     move.l (a0,d0.l),d0
     lea (a0,d0.l),a0
     
  11. Clownacy

    Clownacy UP - ON - CPU Staff

    Joined:
    Aug 15, 2014
    Messages:
    775
    Location:
    Englandland
    It adds a longword of whatever's in d0 to what's in a0...? They're called 'addressing modes', if you ever want to look them up.
     
    Last edited: Feb 9, 2018
    Pacguy likes this.
  12. StephenUK

    StephenUK Working on a Quackshot disassembly Administrator

    Joined:
    Aug 5, 2007
    Messages:
    922
    What you've posted there is basically code to read from within an offset table. The way it works is as follows:

    Before we start, let's throw some theoretical values for a0 and d0. Let's say a0 is 0x10000 and d0 is $4, just for example.

    The first line will add the value in d0 to the address at a0 and move the longword contained there to d0. So, in this example it'll read from 0x10004, because d0 was $4 and a0 was 0x10000. In an offset table, the value it pulls will be the offset of where the data is located relative to the base address in a0. In the Sonic games, a good example is that a0 could be the level layouts offset table, and d0 could be the value of the current zone. From here, it knows which line of the table to read to retrive the offset to where the data is stored. After the first line is processed, the offset value will be stored in d0. Let's say that value is $2000 for arguments sake. That brings me onto the next bit.

    The second line will add the new value in d0 to the address in a0 (so in this case 0x10000 + $2000) and save this new location in a0. Therefore, following our example, a0 now contains an address of 0x12000. If we take the level layout offset table as an example again, this address would be the location of the actual data to be read, therefore the layout data for the zone requested by the initial d0 value.

    It's used quite a lot around the Sonic disassemblies so it's a good idea to have a good look at where it's used to get a better understanding of it. Hopefully this helps you get started though.
     
    MarkeyJester, ProjectFM and Pacguy like this.
  13. NoneofyourBusiness

    NoneofyourBusiness Bag of plums. Member

    Joined:
    Apr 27, 2016
    Messages:
    122
    Location:
    The start
    How do you create level differences between levels? For example, how could you load a pallete for GHZ Act 1, and a different palette for Act 2?
     
  14. TheInvisibleSun

    TheInvisibleSun Visible Member

    Joined:
    Jul 2, 2013
    Messages:
    249
    Location:
    Buffalo, NY, USA
    Last edited: Feb 10, 2018
  15. Pacguy

    Pacguy Testing the waters... Member

    Joined:
    Jul 5, 2014
    Messages:
    973
    Location:
    SOMEWHERE!!! OVER THE RAINBOW!!!
    Alternatively, you can make copies of the "Main Level Load Block" for act 1 and 2 (and 3 and 4, for Sonic 1), and replace every reference to the main level load block with a jsr to a custom routine that loads the correct block depending on which act your in. It takes a little more work, but allows you to make acts with different palettes, artwork, block mappings, chunks, and more depending on what that data holds for that game. I did it in Robotnik Returns 2, and with a handful of other features (title cards and music per act), I was able to make each act feel like a completely different zone. I believe S3K does something similar.
     
    Last edited: Feb 11, 2018
  16. LuigiXHero

    LuigiXHero Pain Director Member

    Joined:
    Mar 22, 2014
    Messages:
    269
    Location:
    Somewhere, Someplace
    [​IMG]

    I actually had a slightly edited version of this as my wallpaper for ages at one point:

    [​IMG]

    I know it's sorta off and on topic but I figured I might as well share it. Good luck with Mode 1 pacguy.

    Edit: Weird that this post wasn't split off as well but oh well.
     
    Last edited: Feb 18, 2018 at 12:22 AM