gbt_pause does not completely pause the track
douglasd3 opened this issue · 11 comments
Hello, i'm having some issues when my track has continuous notes. When gbt_pause is called it pauses the song but keep continuous notes going in a lesser volume. I'm using RGBDS.
Am i missing something?
Thanks!
That's a bit weird, because the gbt_pause
function writes 0 to NR50
, so that should turn off all the channels.
Can you upload a minimal sample ROM that triggers the bug?
Sure! After starting the game press start to pause, in that moment i call gbt_pause and you can hear a low noise even if the audio is paused. The problem remains in the real hardware as well.
This is my pause logic, where i pause and unpause the sound:
PauseLoop:
push af
xor a
call gbt_pause
pop af
halt
nop
ld c, a ; Save last key inputed
call ReadKeys
and KEY_START
cp 0
jr nz, .unpause
jr PauseLoop
.unpause:
; Check hit:
bit 7, c
jr nz, PauseLoop
ld a, 1
call gbt_pause
ret
Just a little update:
I figured that the problem is that the sound volume is never completely off, even with 0 value at NR50. if a call gbt_update and do not set gbt_playing to 0 the music plays at the same low volume. The continuous pitch noise appears because i do not call gbt_update.
I believe that this is a possible hardware limitation. Am i still missing something or there is a possible work around?
Yeah, that seems to be the issue. I actually don't know if there is a workaround, I'll ask...
I guess one workaround would be to write 0 to NR51.
Yes, turns out that a value of 0 is actually 1/8th: https://github.com/LIJI32/SameBoy/blob/886363b398e739303be8d8133387fe0648b4d70b/Core/apu.c#L76
Sorry the delay, i was able to fix by setting NR51
and NR52
as well, here how my gbt_pause looks like:
gbt_pause:: ; a = pause/unpause
ld [gbt_playing],a
or a,a
jr nz,.gbt_pause_unmute
ld [rNR50],a ; Mute sound: set L & R sound levels to Off
ld [rNR52],a ; Turn sound off
ret
.gbt_pause_unmute: ; Unmute sound if playback is resumed
ld a,$80
ld [rNR52],a ; Restore L & R sound levels to 100%
ld a,$FF
ld [rNR51], a
ld a,$77
ld [rNR50],a
ret
If these changes are interesting i can create a pull request. I'm asking because i have very little experience programming asm :)
Sorry for the delay, I think I cleared all notifications and forgot about this! :( Yes, it would be great to have this in a PR!
Thank you @AntonioND! I Completely forgot about the PR.
In case you are interested I have finished my project: https://douglasd3.itch.io/space-princess
@douglasd3 oh, nice, and with RGBDS!