taylus / gbdotnet

An incomplete Game Boy emulator written in .NET Core
3 stars 0 forks source link

Implement Audio Processing Unit #2

Open taylus opened 4 years ago

taylus commented 4 years ago

Game Boy sound hardware:

Sound in MonoGame

Boot ROM sound initialization code starting at $000c:

    ld hl, $ff26
    ld c, $11
    ld a, $80
    ld (hl-), a        ; $ff26 = $80 (turn on sound by setting bit 7 sound on/off register)
    ld ($ff00+c), a    ; $ff11 = $80 (set pulse channel 1 to 50% duty cycle, aka square wave)
    inc c
    ld a, $f3
    ld ($ff00+c), a    ; $ff12 = $f3 (tweak channel 1's envelope to decrease in volume (I think?))
    ld (hl-), a        ; $ff25 = $f3 (output sound channels 1 and 2)
    ld a, $77
    ld (hl), a         ; $ff24 = $77 (set both sound outputs to max volume)

And the code that later plays the da-ding sound:

addr_0080:
    ld a, e
    ld ($ff00+c), a    ; $ff13 = $83 (set channel 1 frequency low bits)
    inc c
    ld a, $87
    ld ($ff00+c), a    ; $ff14 = $87 (set channel 1 frequency high bits + etc)
taylus commented 4 years ago

Info from The Ultimate Game Boy Talk (33c3)

The $FF00 - $FFFF address space, look at all those sound registers (21:54)

image

image

Sound controller info starts at 24:10:

4 voices x 5 registers each (roughly):

image

image

Wave channel can play "any" sound wave. The 16 bytes in registers W0-W15 are 32 entries of 4-bit samples (values 0-F):

image

Pulse wave duty cycle options:

image

Volume sweep effect (going down sounds like normal instruments, going up sounds dreamy?) Frequency sweep (sound effects use this more than music)

https://www.littlesounddj.com/lsd/index.php for composing music on the GB itself