Sonic Adventure Music in Sonic 1

Discussion in 'Engineering & Reverse Engineering' started by Sonic 65, Oct 7, 2007.

Thread Status:
Not open for further replies.
  1. Sonic 65

    Sonic 65

    Tech Member
    prepare for a tl;dr post guys.

    As you may or may not know, I've been experimenting with different ways to play full PCMs over the past few weeks, and came up with a new S1 PCM driver based on the one that came with drx's code template which can support a 3-byte length, variable pitch, and looping (based on a looping flag). The driver doesn't work perfectly in S1 yet, there's still some distorted sound. Tweaker says the DAC works best when the 68K is frozen, but I don't know how to do that without slowing down/stopping the game, so some music sounds distorted and crappy.

    Anyway, here's the ROM. Music choices are:

    GHZ = Emerald Coast (Azure Blue Sky)
    MZ = Red Mountain (Mt. Red - A Symbol Of Pride)
    SYZ = Casinopolis (The Dreamy Stage)
    LZ = Lost World (DANGER - Chased By A Rock!)
    SLZ = Speed Highway (whatever the first song's name is)
    SBZ = Final Egg (Mechanical Resonance)
    Boss = SCD Jap. Boss Theme (yes, I know this isn't from Sonic Adventure)
    FZ = Perfect Chaos

    GHZ and LZ sound a little distorted, but they still sound like the original song.





    I'll also take this topic to release the new driver, with instructions on how to integrate it into the ROM. Here's the new sound driver. It doesn't replace the old one, but instead works as a second driver for the PCM songs. To make this driver work with the S1 ROM, first put this at the end of the ROM:

    [codebox]PCMDriverLoad: ; XREF: GameClrRAM; TitleScreen
    move.w #0,($A11200).l
    move.w #$100,($A11100).l
    move.w #$100,($A11200).l

    WaitForZ80_2:
    btst #0,($A11100).l
    bne WaitForZ80_2

    lea (Kos_Z80_2),a0
    lea ($A00000).l,a1
    move.W #KosZ802End-Kos_Z80_2,d1

    LoadDriver:
    move.b (a0)+,(a1)+
    dbf d1,LoadDriver
    rts[/codebox]

    That's the subroutine that loads the PCM Driver. You'll also need to insert the second sound driver after that, which would be like this:

    [codebox]Kos_Z80_2:
    incbin sound\PCMD.bin
    KosZ802End:[/codebox]

    PCM playing is handled at the beginning of the subroutine Sound_81to9F. At the beginning of Sound_81To9F, put a jump to SoundDriverLoad, which loads the original DAC sound driver for regular songs. To actually play a PCM song, put this before the jump to SoundDriverLoad:

    [codebox] cmpi.b #$81,d7
    beq.l PlayMusic81
    jmp Continue8129F[/codebox]

    Replace the #$81 and PlayMusic81 with the respective values (e.g. #$82 and PlayMusic82) for respective songs. After that code, we need to put the actual code that plays the song, which would look like this:

    [codebox]; ---------------------------------------------------------------------------
    PlayMusic81:

    jsr Sound_E4

    move.w #$100,($A11100).l ;Stop the Z80

    WaitZ80_81:
    btst #0,($A11100).l
    bne WaitZ80_81 ;Wait for z80 to halt

    jsr PCMDriverLoad



    move.b #1,($a00039).l ;Turn PCM Playing Flag ON


    move.b #((Music81&0xFF0000)>>16),($a0003c).l ;addr - $__xxxx
    move.b #((Music81&0xFF00)>>8),($a0003b).l ;addr - $xx__xx
    move.b #(Music81&0xFF),($a0003a).l ;addr - $xxxx__


    move.b #(((Music82-Music81)&0xFF0000)>>16),($a0003f).l ;addr - $__xxxx
    move.b #(((Music82-Music81)&0xFF00)>>8),($a0003e).l ;addr - $xx__xx
    move.b #((Music82-Music81)&0xFF),($a0003d).l ;addr - $xxxx__


    move.b #$06,($a00046).l ;sample rate (06=8000KHz)

    move.b #$01,($a00048).l ;looping flag ($00=no,$01=yes)

    move.w #$0,($A11100).l ;Start the Z80

    rts

    ; ---------------------------------------------------------------------------[/codebox]

    Again, replace all respective values. The Music82-Music81 is signifying the length; Music82 starts at the end of Music81, so Music82-Music81 is the length of the song Music81.

    Make more subroutines just like that and do more compares for more PCMs you want to play. After the end of the subroutine PlayMusic81, just put the label Continue8129F. And you're done. The whole thing should look like this:

    [codebox]Sound_81to9F: ; XREF: Sound_ChkValue
    cmpi.b #$81,d7
    beq.l PlayMusic81
    jmp Continue8129F

    ; ---------------------------------------------------------------------------
    PlayMusic81:

    jsr Sound_E4

    move.w #$100,($A11100).l ;Stop the Z80

    WaitZ80_81:
    btst #0,($A11100).l
    bne WaitZ80_81 ;Wait for z80 to halt

    jsr PCMDriverLoad



    move.b #1,($a00039).l ;Turn PCM Playing Flag ON


    move.b #((Music81&0xFF0000)>>16),($a0003c).l ;addr - $__xxxx
    move.b #((Music81&0xFF00)>>8),($a0003b).l ;addr - $xx__xx
    move.b #(Music81&0xFF),($a0003a).l ;addr - $xxxx__


    move.b #(((Music82-Music81)&0xFF0000)>>16),($a0003f).l ;addr - $__xxxx
    move.b #(((Music82-Music81)&0xFF00)>>8),($a0003e).l ;addr - $xx__xx
    move.b #((Music82-Music81)&0xFF),($a0003d).l ;addr - $xxxx__


    move.b #$06,($a00046).l ;sample rate (06=8000KHz)

    move.b #$01,($a00048).l ;looping flag ($00=no,$01=yes)

    move.w #$0,($A11100).l ;Start the Z80

    rts

    ; ---------------------------------------------------------------------------

    Continue8129F:
    jsr SoundDriverLoad
    cmpi.b #$88,d7 ; is "extra life" music played?
    bne.s loc_72024 ; if not, branch
    tst.b $27(a6)[/codebox]

    It should be fairly obvious how to add more songs. I hope you understood what to do, because I suck at explaining things =P

    Hopefully this will open up the gates to much more awesome-sounding music in Sonic games.
     
  2. Tweaker

    Tweaker

    Misfit
    12,389
    1
    0
    It's a neat concept, but... this sounds horrible. XD

    Good job getting it in, though.
     
  3. JoseTB

    JoseTB

    Tech Member
    709
    54
    28
    Wow, sounds almost like if it was made for it!

    Okay, besides the irony, nice job with it. I always though something like this would be possible, but never got into sound stuff enough to achieve it, so yeah, it's nice to see this concept can be actually implemented.
     
  4. Sonic 65

    Sonic 65

    Tech Member
    I know, but I have no idea how to get it to be better quality. I'm not that experienced with the S1 sound driver =P

    As I said before, you said something about freezing the 68K to get better DAC quality. Is there any other way to get better quality? I still want the game to be playable =P
     
  5. Lostgame

    Lostgame

    turntablist, dinosaur goddess Oldbie
    4,111
    32
    28
    Toronto, ON
    The O.I.C.
    Good concept but yeah, the quality is too poor for this to be a realistic option for people.
     
  6. 87th

    87th

    FOX HOUNDER Member
    The Sonic CD boss music doesn't sound too bad compared to everything else. I wonder why that is?
     
  7. Tweaker

    Tweaker

    Misfit
    12,389
    1
    0
    It's mostly percussion-based, and the DAC delivers good quality bass frequencies compared to everything else. If you used the DAC primarily for bass or something, it'd probably sound pretty awesome. That's why it was generally used by many games to play the drum tracks in music.

    You could also probably stream drum loops during songs and use that, sort of like what Palmtree Panic's past music did on the SCD PCM chip. That's a pretty awesome idea, actually - needs more amen break! XD
     
  8. Sonic 65

    Sonic 65

    Tech Member
    HAY GUYZ

    Sonic Rush music doesn't really fit with Sonic 1 levels though =P

    And I can't really do much about the quality, sadly.
     
  9. Varion Icaria

    Varion Icaria

    He's waiting.... Tech Member
    1,014
    3
    18
    S4: Cybernetic Outbreak
    Try using Goldwave to convert it to 12000hz 8bit unsigned mono or something it may help the quality.
     
  10. SMTP

    SMTP

    Tech Member
    It probably already is... :P
     
  11. 87th

    87th

    FOX HOUNDER Member
    ...I like it...
     
  12. Ritz

    Ritz

    Subhedgehog Member
    Doesn't mean it fits.
     
  13. Covarr

    Covarr

    Sentient Cash Register Member
    4,233
    3
    18
    Trapped in my own thoughts.
    Two stageplays, a screenplay, and an album
    I'm not sure which of these bugs you are or aren't aware of.
    • Sega logo sounds way wrong
    • Music disappears on pause, but doesn't come back on unpause
    • Looping sounds unnatural.
    • Music doesn't speed up when wearing shoes.
     
  14. Sonic 65

    Sonic 65

    Tech Member
    1 is because of the shifting of the logo data, and it's very minor and probably won't be fixed anytime soon (even though it would probably be really easy to fix with this new driver). The pause bug is the result of the pausing stopping the Z80, which writes data to the DAC in this driver, and not starting it again when unpaused. I'll fix that soon. Looping sounds unnatural because Sonic Adventure songs don't have very many songs that have spots where it can loop back to the beginning perfectly (it's a data bug, not a driver bug). And I don't really know how to fix the speed bug, but you can 'fix' it by giving the speed sneakers its own music.
     
  15. muteKi

    muteKi

    Fuck it Member
    7,617
    20
    18
    Does it have to loop all the way to the beginning? There are certainly loop points in SA1, but not usually at the beginning.
     
  16. Metal Man88

    Metal Man88

    Time Traveller Oldbie
    2,138
    0
    0
    Pardon my DAC ignorance—is the sound horrible because that's about the best the DAC can do, or is there some way to make the DAC perform at an acceptable level when playing raw PCM data?

    And, if that is not possible... could you outsource sound functions to a more capable part of the system to make it sound better?

    (I'm not terribly knowledgable about the chips themselves and how they interact, but I'm mostly curious—if you can get half-way there with the DAC as-is, I'd think there might be some way to make it play right—even at the expense of the gameplay.)
     
  17. ICEknight

    ICEknight

    Researcher Researcher
    Heh, nice experiment. The boss music sounds pretty cool.
     
  18. Sonic 65

    Sonic 65

    Tech Member
    I figured out how to fix the crappy sound without any (noticeable =P) slowdown in gameplay.

    Fixed ROM

    New Music Choices:

    GHZ - Palmtree Panic Present Jap.
    LZ - Lost World (Chased By a Rock!"
    MZ - Sand Ocean
    SLZ - Stardust Speedway Good Future Jap.
    SYZ - Collision Chaos Present Jap.
    SBZ - Metallic Madness PResent Jap.
    Boss - SCD Boss
    FZ - Perfect Chaos

    If you want, you can compare the LZ, Boss, and FZ music from the original to this to see how the quality's improved. =P I'll put up the instructions for the fix tomorrow, I'm sleepy now, so sorry.
     
  19. Tweaker

    Tweaker

    Misfit
    12,389
    1
    0
    It doesn't really sound that much better to me... All it seems you were able to do is stop the insane pitch fluctuation, which, while a good start, still makes this pretty impractical.
     
  20. Chimpo

    Chimpo

    Member
    7,310
    2
    18
    Atomic Sonic Part II
    I think it actually ended up sounding worse.
     
Thread Status:
Not open for further replies.