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:
    415
    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
    Pacca, MarkeyJester, AkumaYin and 3 others like this.
  2. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    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 Pacca like this.
  3. ValleyBell

    ValleyBell Well-Known Member Member

    Joined:
    Dec 23, 2011
    Messages:
    166
    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. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    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 Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,016
    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
    Pacca likes this.
  6. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    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 Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,016
    I just go by disassemblies. ValleyBell's SMPS Research Pack has SCD's driver in it.
     
  8. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    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. CreepyMystery

    CreepyMystery Reminiscence and Semblance Member

    Joined:
    Oct 20, 2017
    Messages:
    36
    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. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    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 Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,016
    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
    Pacca likes this.
  12. StephenUK

    StephenUK Working on a Quackshot disassembly Member

    Joined:
    Aug 5, 2007
    Messages:
    1,026
    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 Pacca like this.
  13. NoneofyourBusiness

    NoneofyourBusiness Bag of plums. Member

    Joined:
    Apr 27, 2016
    Messages:
    126
    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:
    424
    Location:
    Western New York, USA
    Last edited: Feb 10, 2018
  15. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    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. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    How would I go about debugging vram problems? I'm having an issue where a level, when loaded in a certain way, floods vram with garbage after properly loading the level graphics. The palettes go black temporarily, and all graphics that aren't dynamically reloaded remain scrambled. I of course checked if PLCs', animated level art, objects, and the main level art was the culprit, but disabling them or replacing those things with vanilla assets didn't help.

    Normally, this is where I'd go dissect the issue with Regens 68k debugger, but I don't really have anything I can use to trigger the debugger when the garbage graphics are loaded. Since the palette lines black out (all of them, including Sonics' palette line), I tried to check when Sonics' palette line in ram was written to (Normal_palette in the S2 git disasm). While that triggered the debugger when fading in or fading out, this particular issue seems to bypass that ram value...
     
  17. TheStoneBanana

    TheStoneBanana banana Member

    Joined:
    Nov 27, 2013
    Messages:
    602
    Location:
    The Milky Way Galaxy
    Regen's debugger has the option to set breakpoints for reads and writes to VRAM addresses as well, which could potentially be used to figure out your issue.
     
  18. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    I've been toying with those options, but I can't seem to get them to work at all. I've tried putting multiple addresses in there, and checking for both read and write access, but nothing pulls up the regen debugger, not even when the game is initializing or is loading lots of artwork.
     
  19. EditChris

    EditChris STH:DB - Someday... Member

    Joined:
    Jul 31, 2013
    Messages:
    41
    Location:
    somewhere
    I'm trying to port the 128x128 tile system used on MarkeyJester's Two-Eight Disassembly to my hack (Hivebrain ASM68k).
    I ported the REV01 BG Effects years ago, and knowing that, I followed the necessary steps to make it REV01-Friendly.
    If I compare my adaptation with MarkeyJester's code... well, it's practically like to see it on a mirror.
    And, yes, I'm using the correct files for levels, collide, etc... I know it because it's literally a copy from the Two-Eight Disassembly.

    Well, after explaining all of that, what could possibly go wrong!? :D
    Well, this.

    Could someone please help me? Because I tried to port this several times, and I'm getting always the same results... And I don't know what to do.

    EDIT: Ignore this topic, already fixed. The problem was that I'm too blind.
     
    Last edited: Mar 9, 2018
    EMK-20218 likes this.
  20. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867