←back to thread

208 points ibobev | 1 comments | | HN request time: 0.223s | source
Show context
droolboy ◴[] No.44464386[source]
I know it’s a long shot, but does anyone know of a tutorial for the sound of a game boy emulator? Most of these tutorials never cover that piece and when I try it on my own I find it hard to properly implement or even understand the reference material well enough to implement on my own.
replies(3): >>44464541 #>>44464548 #>>44464587 #
1. t0mek ◴[] No.44464587[source]
Not a tutorial per-se, but here are 2 slides describing how I've done it:

https://www.slideshare.net/slideshow/emulating-game-boy-in-j...

Essentially, there are 4 channels, each providing a number 0-15 on every tick. Emulator should mix them together (arithmetic average), scale up to 0-255 and feed to the sound buffer, adjusting the tick rate (4.19MHz) to the sound output rate (e.g.: 22 kHz) - taking every ~190 value (4.19MHz / 22 kHz) is a good start.

Now the 0..15 value that should be produced by each channel depends on its characteristics, but it's well documented:

https://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware

Channels 1 and 2 produce square waves, so a bunch of low (0) and high (15) values, with optional volume envelope (gradually going down from 15 to 0 on the "high" part of the square) and frequency sweep (alternating 0s and 15s slower or faster).

Channel 3 allows an arbitrary waveform, read from the memory.

Channel 4 is a random noise, generated by the LSFR.

See SoundModeX.java for the reference:

https://github.com/trekawek/coffee-gb/tree/master/src/main/j...