Closed joncampbell123 closed 8 years ago
Thank you for the clear and interesting description of the bug. I can sufficiently follow along so I could imagine the effects of a change to that code. :)
Does the GUS have generalized computer chips to do the sound processing and the above error exists in software written to permanent onboard memory?
I'm not sure how the GF1 chip is wired. I'm assuming so far that it's some sort of specialized DSP core with no branching (since each audio sample output takes a fixed amount of time) and an equally specialized DSP microcode of some kind that has access to ALU units optimized for multipy+add and a memory controller optimized for fetching two sequential samples. Especially for hardware at that era, I'm guessing it's more VLSI than generic CPU.
Then again, I probably don't know what the hell I'm talking about. It's all guessing right now.
Appreciate the overview of how the hardware was generally organized. I've been testing and the gus audio is definitely improved, the sounds seem lower in frequency which matches well to the sb emulation (although I think the GUS emulation sounds better, perhaps more dynamic).
Exactly. DOSBox's emulation upsampled everything to 44.1KHz (or to your gusrate= setting). The real hardware renders at a sample rate inversely proportional to the number of active channels. Something using 14 active channels @ 44.1KHz should sound better than something using all 32 channels at ~19KHz because that's what the actual hardware does.
Anyway, this bug-for-bug emulation is now done.
What this means is: If a voice is playing backwards, and the start position is close enough to 0 or IS 0 such that the voice position could step past it into a negative position value, the GUS will fail to stop or loop at the start position because the hardware acts as if the card then does an unsigned compare against start.
To put this into perspective:
Imagine a voice is playing fast enough that the FC register is 0x40 (step 4 samples per audio sample), and playing backwards. The start position is less than 0x40. The current position is moving backwards as directed and getting closer to 0. Here's what happens:
If the start position is far enough from 0 that (current_position -= frequency_counter) <= start, then the GUS will stop at the start position as expected:
This bug does not happen moving forward, only backwards:
This is one way that the GUS emulation could be misleading to developers wishing to target retro hardware. In the interest of hardware, it is recommended that DOSBox-X emulate this unsigned step + compare bug observed on real hardware.