8 ms·
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-java/83928182#21 https://w
by t0mek 1y ago
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-java/83928182#21 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 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/java/eu/rekawek/coffeegb/sound https://github.com/trekawek/coffee-gb/tree/master/src/main/j...