don't click here

Sonic 2 Clone Driver v2

Discussion in 'Engineering & Reverse Engineering' started by Clownacy, Mar 31, 2014.

  1. redquebec

    redquebec

    Member
    39
    0
    6
    Once again, thanks Clownacy for the hard work. Been using your driver in personal projects, love it.

    I have a question for you. I've been trying to create accurate sample to use with your driver. But I have a hard time getting the sample rate right, I'm usually near, but it's far from correct. In "MegaPCM - DAC Table.asm", there are the samples pitch declared, am I right? I'd like to know if there is a formula that could translate easily from sample (Hz) into S2CDv2 pitch accurately. Thank you.
     
  2. kazblox

    kazblox

    Member
    178
    26
    28
    Diassemblies and decompilations.
    Relax, relax, I wasn't trying to anger nor blame anything on anyone. I could manually convert it, but I don't know if there would be any nuisances that require a change of the syntax. Though I could look at the current AS conversion myself to see what needs to be changed, so why am I still talking about this right now?
     
  3. Clownacy

    Clownacy

    Tech Member
    966
    338
    63
    According to a formula ValleyBell gave me, the way to get a playback speed from a pitch value is (3579545*2)/(244+(26*(X-1))), with X being the pitch value. That said, to get a pitch from a playback speed in Hz, you'd do ((((3579545*2)/Hz)-244)/26)+1. Note that these values are specific to my driver's custom Mega PCM driver, in DPCM mode.

    Edit: https://github.com/Clownacy/Sonic-2-Clone-Driver-v2/commit/43ef5c928ddf1cb42c4188827a11bf7692aa2147 ;)
     
  4. redquebec

    redquebec

    Member
    39
    0
    6
    My man! :)
     
  5. Clownacy

    Clownacy

    Tech Member
    966
    338
    63
    I've recently been working on this driver again. Things have slowed down for now, with no new changes being made in the last month, so I figure that this is a good time to release an update - v2.8 v2.8.0.1.

    The major highlight of this update is that Mega PCM has been replaced with my own custom DAC driver, which is capable of playing two DAC samples at once. Yes, I am aware that Dual PCM exists - more on that later.

    Features of the new DAC driver include...
    • 17kHz output
    • support for samples in unsigned 8-bit PCM format, at basically any sample rate, at any location in the ROM, at any length (no DPCM support though - sorry)
    • proper 8-bit clamping in the mixer
    • 16 non-linear levels of volume control
    • sample pausing and unpausing
    Like Dual PCM, samples are required to be in a special format where they do not contain any bytes that are set to 00. A tool to convert samples to this format can be found in the 'extra/DAC converter' directory.

    The sound driver has not been extended to actually make use of the second DAC channel: songs are still limited to only one drum track. Rather, the second channel is intended for DAC SFX. More info here.

    Another noteworthy change is that support for FM modulation envelopes has been ported from SMPS 68k Type 2, finally allowing this driver to play the themes of Carnival Night Zone and Launch Base Zone.

    Another user-facing change is that, when music is fading-in after a 1UP jingle finishes, SFX are faded too. Previously, they would just be muted until the fade is finished.

    Finally, documentation has been moved to a GitHub wiki. This is nice because it means that the documentation is all in one place now instead of duplicated across two forums. The wiki is where you'll now find the installation guides.

    A more-detailed changelog for this update (and the unreleased one that came before it) can be found below:
    v2.7+
    • Changed FM voice format, like what S2's driver did, for optimised reading
    • Split DAC table from Mega PCM Z80 .asm file
    • Rearranged file/folder structure, so files meant for the user to edit (like DAC samples and PSG envelopes) are in the root folder, the off-limits engine is in the 'engine' folder, and the optional/only-useful-during-installation files are kept in an 'extra' folder
    • Added SMPS2ASM equates for Chaotix' PWM samples (these equates were also applied to the included Chaotix dump)
    • Fixed typo in smpsHeaderVoiceUVB, causing errors
    • Restored music/SFX/Special SFX FM voice pointer to relative 16-bit value
    • Changed some labels and symbols to suit ValleyBell's suggestions (https://vgmrips.net/misc/SMPS_Disasm_Terms.txt)
    • Added PWMSilenceAll, so PWM is silenced with the rest of the driver
    • Changed internal branch tables to offset tables (requires modifications to user file 'Sound IDs.asm')
    • Removed 68k-based Sega chant playback support (fewer dependencies)
    • Removed v_playsnd0 and f_voice_selector, after making them redundant
    • Renamed UpdateMusic, so old S1 code that accidentally still called the driver should correctly flag an error now
    • In-driver track RAM addresses are now relative (this is in preparation of possible binary-blob)
    • Changed PauseMusic to not "resume" DAC channel (this should be pointless, since that track doesn't use voices, and Mega PCM handles panning)
    • Removed a redundant bugfix (sorry, Markey)
    • Removed PlaybackControlBackup from track RAM/SMPS_Track (relevant data is stored in unused bit of PlaybackControl)
    • Fixed bug introduced in v2.7, where the extra life jingle would cause the level's music to have a delayed DAC track
    • Made PWM be silenced on song start (consider PWM SFX extremely experimental; use with caution)
    • Added support for disabling noise mode on PSG 3 (this is done in the same way as SMPS Z80)
    • Adjusted PSG fading, so it's more in-line with FM and DAC (fades in roughly $20 frames, rather than $10)
    • Changed cfChangeFMVolume to not run at all on PSG channels (the SMPS Z80 way)
    • Added bugfix for PSG fading (volume updates would conflict with volume envelopes)
    • Fixed held volume envelops only updating the volume every other frame (silly SMPS 68k Type 2)
    • Added support for negative FM voice pointers in Special SFX
    • Changed DAC_Entry pitch value so it's the playback speed in Hz instead of a djnz loop counter

    v2.8
    • Added FM volume attenuation clamping, to prevent overflow (this bug would cause Sonic 2's final boss music to have an extremely loud instrument while fading-in after a 1-UP jingle finishes playing)
    • Inconsistent DAC/FM6 panning behaviour has been corrected
    • Ported SMPS Z80-style frequency modulation, fixing several issues in SMPS Z80 songs (such as broken pitch bends at the start of Sonic & Knuckles' credits music)
    • Bugs in the 'smpsSetVol' coordination flag have been corrected (fixes missing PSG notes in the Sonic & Knuckles credits music)
    • Ported FM frequency modulation from SMPS 68k Type 2, so that Carnival Night Zone's and Launch Base Zone's music are finally compatible with this driver
    • Fix note timeout being performed on first frame of playback
    • The sound queue processing logic has been completely remade, hopefully fixing a number of subtle bugs (the old code was *very* bad)
    • Assorted optimisations
    • TempoWait can no longer delay tracks on their first frame of playback (this is a proper fix to the hanging-note bug that Sonic 2's driver used a work-around for, which can sometimes be heard at the start of Sonic 2's Death Egg Zone music)
    • Mega PCM has been replaced with a custom two-channel DAC driver: the first channel is used by music, while the second channel can be used by DAC SFX
    • Fix SFX and Special SFX tracks not being updated on the same frame that a music track uses the 'fade to prevous song' coordination flag
    • Fading-in has been overhauled, so that SFX are no longer muted while fading is performed: rather, SFX are now faded along with everything else
    • Bugs relating to PSG volume values have been corrected
    • The dependency on the 'Graphics_Flags'/'v_megadrive' variable has been removed, easing the process of integrating this driver into homebrew

    Of course, you might be wondering why I made a custom DAC driver when Dual PCM exists, or why I even updated this sound driver in the first place when AMPS exists. And my reason is... I prefer stuff that I made over stuff that other people made. :V I mean hey, who knows, maybe I'll come up with something that MarkeyJester and Aurora Fields didn't think of!

    With that said, unless AMPS has some kind of crazy shortcoming that I'm unaware of, I don't really see a reason to use this driver. I'm just working on it because it's my project and I like working on it sometimes.
     
    Last edited: Jul 6, 2021
  6. XPointZPoint

    XPointZPoint

    That's no good! Member
    53
    13
    8
    So, I got the clone driver to work but now every time I collect a ring, my lives counter goes up by 1. Funny, I wasn't planning to have my S2 hack have rings anyway, so there really isn't a need to fix the bug since no one will collect rings (unless they use debug mode, of course.)

    I even got the lives counter to overflow.

    (EDIT 7.5.22: Bug fixed!)
     
    Last edited: Jul 6, 2022
  7. Hexinator

    Hexinator

    Hex Member
    I used the guide for the sonic 1 github disassembly and there were so many op code / unexpected character errors, i had set optimisesound to 0, i wish as was compatible with this disassembly
     
  8. Clownacy

    Clownacy

    Tech Member
    966
    338
    63
    There's an AS version of the disassembly here.
     
  9. Hexinator

    Hexinator

    Hex Member
    Thanks, are there any changes within the asm file of the entire game? because i don't want to restart all of the work i've put
     
  10. Clownacy

    Clownacy

    Tech Member
    966
    338
    63
    The AS version changes many parts of the main ASM file, so I'm afraid you'd have to restart. AMPS seems to support asm68k, so maybe you could try that instead.