Fix for BRSTM with Fewer Audio Tracks [stebler]
#1
Fix for BRSTM with Fewer Audio Tracks [stebler]

This code prevents the bgm from stopping due to the low number of tracks in BRSTM.

Original code was written by stebler as a part of mkw-sp.

I ported it to gecko code.

It is recommended to use with this code.

NTSC-K is not tested.

(NTSC-U)
c20a4f10 0000001e
7cac2b78 558c463e
718c0080 2c0c0080
40820014 3d807fff
618cffff 7ca56038
480000c4 9421ff80
7c0802a6 90010084
bc610008 48000021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 3d608000
9421ff80 7c0802a6
90010084 bc610008
7ca55b78 3d80800a
618c4f10 7d8803a6
4e800021 9061fffc
b8610008 80010084
7c0803a6 38210080
8181ff7c 2c0c0000
4182000c 38600001
4e800020 3ca08000
9421ff80 7c0802a6
90010084 bc610008
3d80800a 618c4f10
7d8803a6 4e800021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 9421ffe0
60000000 00000000
0409ebd0 38000000


(PAL)
c20a4fb0 0000001e
7cac2b78 558c463e
718c0080 2c0c0080
40820014 3d807fff
618cffff 7ca56038
480000c4 9421ff80
7c0802a6 90010084
bc610008 48000021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 3d608000
9421ff80 7c0802a6
90010084 bc610008
7ca55b78 3d80800a
618c4fb0 7d8803a6
4e800021 9061fffc
b8610008 80010084
7c0803a6 38210080
8181ff7c 2c0c0000
4182000c 38600001
4e800020 3ca08000
9421ff80 7c0802a6
90010084 bc610008
3d80800a 618c4fb0
7d8803a6 4e800021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 9421ffe0
60000000 00000000
0409ec70 38000000


(NTSC-J)
c20a4ed0 0000001e
7cac2b78 558c463e
718c0080 2c0c0080
40820014 3d807fff
618cffff 7ca56038
480000c4 9421ff80
7c0802a6 90010084
bc610008 48000021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 3d608000
9421ff80 7c0802a6
90010084 bc610008
7ca55b78 3d80800a
618c4ed0 7d8803a6
4e800021 9061fffc
b8610008 80010084
7c0803a6 38210080
8181ff7c 2c0c0000
4182000c 38600001
4e800020 3ca08000
9421ff80 7c0802a6
90010084 bc610008
3d80800a 618c4ed0
7d8803a6 4e800021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 9421ffe0
60000000 00000000
0409EB90 38000000


(NTSC-K)
c20a5010 0000001e
7cac2b78 558c463e
718c0080 2c0c0080
40820014 3d807fff
618cffff 7ca56038
480000c4 9421ff80
7c0802a6 90010084
bc610008 48000021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 3d608000
9421ff80 7c0802a6
90010084 bc610008
7ca55b78 3d80800a
618c5010 7d8803a6
4e800021 9061fffc
b8610008 80010084
7c0803a6 38210080
8181ff7c 2c0c0000
4182000c 38600001
4e800020 3ca08000
9421ff80 7c0802a6
90010084 bc610008
3d80800a 618c5010
7d8803a6 4e800021
9061fffc b8610008
80010084 7c0803a6
38210080 8061ff7c
4e800020 9421ffe0
60000000 00000000
0409ecd0 38000000


Code:
#Source

#First ASM

#inject at 0x800a4f10 (NTSC-U)
#inject at 0x800a4fb0 (PAL)
#inject at 0x800a4ed0 (NTSC-J)
#inject at 0x800a5010 (NTSC-K)

.macro call_link address
lis r12, \address@h
ori r12, r12, \address@l
mtlr r12
blrl
.endm

.macro pushStack
    stwu sp, -0x80 (sp)
    mflr r0
    stw r0, 0x84 (sp)
    stmw r3, 8 (sp)
.endm

.macro popStack
    lmw r3, 8 (sp)
    lwz r0, 0x84 (sp)
    mtlr r0
    addi sp, sp, 0x80
.endm

.set region, 'K'

.if (region == 'P')
    .set nw4r__snd__StrmFileReader__readStrmTrackInfo, 0x800a4fb0
.elseif (region == 'E')
    .set nw4r__snd__StrmFileReader__readStrmTrackInfo, 0x800a4f10
.elseif (region == 'J')
    .set nw4r__snd__StrmFileReader__readStrmTrackInfo, 0x800a4ed0
.elseif (region == 'K')
    .set nw4r__snd__StrmFileReader__readStrmTrackInfo, 0x800a5010
.else
        .err
.endif

    mr r12, r5
    rlwinm  r12, r12, 8, 24, 31
    andi. r12, r12, 0x80
    cmpwi r12, 0x80
    bne not_default_behave
    lis r12, 0x7FFF
    ori r12, r12, 0xFFFF
    and r5, r5, r12
    b skip_all
    not_default_behave:
    pushStack
    bl strmTrackInfoReadHook
    stw r3, -4 (sp)
    popStack
    lwz r3, -0x84 (sp)
    blr
strmTrackInfoReadHook:
    lis r11, 0x8000
    pushStack
    #r3 = this pointer (nw4r::snd::StrmFileReader)
    #r4 = pointer to soundInfo
    #r5 = trackId
    or r5, r5, r11
    call_link nw4r__snd__StrmFileReader__readStrmTrackInfo
    stw r3, -4 (sp)
    popStack
    lwz r12, -0x84 (sp)
    cmpwi r12, 0
    beq read_track_0
    li r3, 1
    blr
    read_track_0:
    lis r5, 0x8000
    pushStack
    call_link nw4r__snd__StrmFileReader__readStrmTrackInfo
    stw r3, -4 (sp)
    popStack
    lwz r3, -0x84 (sp)
    blr
skip_all:
    stwu sp, -0x20 (sp) #default instruction

Code:
#Source

#Second ASM
#fix STRM params alloc channel count for brsar to 0

#replace at 0x8009ebd0 (NTSC-U)
#replace at 0x8009ec70 (PAL)
#replace at 0x8009eb90 (NTSC-J)
#replace at 0x8009ecd0 (NTSC-K)

li r0, 0
Reply
#2
Edit: Whoops I commented on the wrong thread. Not sure how to delete a comment.

Edit: Actually I did comment on the right thread, sorry about that confusion.

This code has a bug. In Koopa Cape, when a brstm is provided that has fewer than 4 stereo tracks, the music volume is doubled. Meanwhile a brstm that has exactly 4 stereo tracks has normal volume. I suspect that this is because in vanilla MKW, in Koopa Cape, the 1st and 4th stereo tracks to play on top of each other at the same time. In order to avoid having double volume when designing a multi track brstm for Koopa Cape, you must leave the 4th track silent.

I suspect what this code does is that when a brstm is found to have fewer than 4 stereo tracks on Koopa Cape, it copies the stereo tracks into any missing channels. This works for Toad's Factory, Wario's Gold Mine, Dry Dry Ruins, Moonview Highway, and Bowser's Castle. But it doesn't work for Koopa Cape. Because the 4th stereo track plays at the same time as the 1st, resulting in double volume when those tracks are playing.

The fix for the developer would be to make a special case for Koopa Cape, which creates a 4th stereo track for the brstm, but fills it with silence instead of a duplicate of the 1st stereo track.

A temporary fix for users is that you can make any single-channel brstms that you intend to use on the KC slot half volume. However, this is not ideal if you have lots of brstms for a custom track distribution and you may end up changing the slot that a brstm plays on. If you decide to switch a brstm to another slot, then you will have to make its volume normal. Another side effect is that the brstm volume will be half when you collide with sound triggers that normally switch to the 2nd or 3rd stereo tracks.

Another fix is to edit the brsar and cut the volume of the KC slot in half. Now any brstms you place on the KC slot will automatically have their volume un-doubled without you needing to edit each and every one of them. However, this still isn't ideal because now any multi-channel brstms that you want on the KC slot will be at half volume. You can either make your multi channel brstms for KC twice as loud when you are making them in Audacity (which isn't ideal, there will be sound clipping, even if you use the Limiter instead of regular amplify) or you can use the "Music Volume can be set via BRSTM" code that is used in CTGP to double the volume without sound clipping. However, that code isn't public, so good luck getting ahold of it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)