AntonioND / gbt-player

A music player library for the PSG audio channels of the GB, GBC and GBA.
MIT License
284 stars 20 forks source link

Ch3 vibrato sounds OK in mGBA, but it's broken on hardware #22

Open copyrat90 opened 1 year ago

copyrat90 commented 1 year ago

Issue

Ch3 vibrato sounds OK in mGBA, but it's broken on hardware. The waveform is a simple Triangle, which looks like this: image

Source files

basic - ch3 vibrato.s3m basic - ch3 vibrato.gba

Playback

mGBA Playback (OK)

https://github.com/AntonioND/gbt-player/assets/34793045/b357ca66-d29d-41b1-be1c-f6a1bf57c4e5

Hardware Playback (Broken)

WARNING!! HEAVILY BROKEN NOISE SOUND!! https://github.com/AntonioND/gbt-player/assets/34793045/daed84fd-3deb-4ee5-a8ee-72b64f185cbe

I tried this on 3 different GBAs, but they all have this broken noises.

GValiente commented 1 year ago

VisualBoyAdvance and NanoBoyAdvance sound playback is closer to real hardware, if it helps.

copyrat90 commented 1 year ago

VisualBoyAdvance and NanoBoyAdvance sound playback is closer to real hardware, if it helps.

I just tried NanoBoyAdvance, and it has the same clicking issue. Testing the audio with NanoBoyAdvance would be a good option, thanks for pointing it out.

AntonioND commented 1 year ago

I guess this explains it: https://gbdev.io/pandocs/Audio_details.html#mixer

Avoiding audio pops

Enabling or disabling a DAC (see below), adding or removing it using NR51, or changing the volume in NR50, will cause an audio pop. (All of these actions cause a change in DC offset, which is smoothed out by the HPFs over time, but still creates a pop.)

To avoid this, a sound driver should avoid turning the DACs off; this can be done by writing $08 to NRx2 (silences the channel but keeps the DAC on) then $80 to NRx4 to retrigger the channel and reload NRx2.

The HPF is more aggressive on GBA than on GBC, which itself is more aggressive than on DMG. (The more “aggressive” a HPF, the faster it pulls the signal towards “analog 0”; this tends to also distort waveforms.)

I always remove channels with NR51 (well, the GBA-equivalent register) before changing the volume, frequency, etc.