Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
Lately I've been playing with audio on the Game Boy, and I've successfully gotten a little audio engine working that works with the two square channels and noise channel to play music.
Now I'm working with the wave channel, trying to play recorded sound effects. But I'm struggling with a constant loud buzzing sound, comparable in volume to the sound effect itself.
Depending on the wave pattern I'm using, I either get buzzing on my GBA or my GBC, but never both, and never neither. The situations that produce buzzing on my GBC also produce buzzing in BGB.
If I have the 16-byte wave table filled with nothing but $00, I get buzzing on GBC/BGB, but not GBA. If I fill the table with $77/$88, I get buzzing on GBA, but not GBC/BGB. I would think $77/$88 is what "silence" should be, since each nibble is about halfway in the 4-bit range, and 8-bit unsigned PCM data has silence as $7F/$80.
It might be possible that the buzzing is not being caused by the audio data, but rather how I'm controlling the sound system. If it would help to post actual audio data or code, I will, but for now I'll describe the process I'm going through.
I have the timer interrupt enabled and configured to trigger the timer interrupt at a rate that I'm pretty sure is 256HZ (I write %00000110 to $FF07). Every time the timer interrupt triggers, I first disable the wave channel by setting bit 7 of $FF1A to 0. Then, I write 16 bytes of wave data to the wave table starting at $FF30. Then I re-enable the wave channel by setting bit 7 of $FF1A to 1. Then I write %00100000 to $FF1C to set wave volume to 100%. Then I write %00000000 to $FF1D and %10000111 to $FF1E to set the frequency to 1792, disable length counter, and trigger the wave. The frequency values may be set wrong, but they sound correct when I try playing actual converted audio files, also they don't make a difference to whether or not I get buzzing.
Also, one final detail: I held a frequency detector up to my GBA while it was buzzing and it showed frequency spikes at 1024HZ, 1280HZ, 1536HZ, and 2048HZ. All multiples of my 256HZ timer rate.
Based on what I've written here, is there anything I'm clearly missing? A step I don't realize I need to take or that I'm doing in the wrong order? A difference between GBC and GBA I'm not aware of? Something different I need to do with the PCM data? Am I writing to any of the wave registers incorrectly?
Any help would be much appreciated!
Offline
From what I know, each GameBoy sound differently, check a look at this :
http://www.herbertweixelbaum.com/comparison.htm
I don't know if that could explain your problem though.
Offline
What's causing the buzzing is just the fact that you're disabling and re-enabling the wave channel. When you disable the wave channel, the voltage will try to stabilize to some value, which differs between the different Gameboy models, which creates a small spike. But you still have to stop the wave channel playback ($FF1A) or you can't write new data to the register. But I figured out a way to fix this, which I call the antispike trick. It's included in LSDj since version 4.7.0 and I also made a patch for Pocket Music. Pocket Music originally locked you out from using the program on GBA, probably for this very reason. Sample playback sounds completely horrible on GBA without this fix.
The trick consists of disabling the wave channel in the $FF25 register before stopping it and immediately restoring as soon as the channel has been re-enabled.
So all you do is this:
ldh A,[$FF25] and $bb ldh [$FF25],A
...before writing $00 to $FF1D and...
ldh A,[$FF25] or $44 ldh [$FF25],A
...after restarting the channel. Or whatever makes sense in your program.
Offline
nitro2k01 wrote:
The trick consists of disabling the wave channel in the $FF25 register before stopping it and immediately restoring as soon as the channel has been re-enabled.
Boom! That was exactly what I needed! Thank you! I simply wasn't going to be able to move forward with wave audio without this fix!
Thank you for sharing that article, Xephyr, and while it does confirm that sound is produced differently on different models, it didn't really have a solution to my particular problem (the buzzing I experienced wasn't just a somewhat lower-quality wave form, but rather a loud, distinct tone). It does make mention of the anti-spike fix nitro2k01 posted, though. And it really is a fascinating article.
Offline