devkitPro / libnds

C library for Nintendo DS
http://devkitpro.org/viewforum.php?f=38
Other
316 stars 46 forks source link

Audio timer value calculated incorrectly #38

Open Gericom opened 4 years ago

Gericom commented 4 years ago

https://github.com/devkitPro/libnds/blob/89ac6cbbf51b70b7ce5679d3a8bd621b9fb910e6/include/nds/arm7/audio.h#L47

In audio.h a rounded version of the audio timer frequency is used, while it should actually be BUS_CLOCK/2 (16756991). This causes issues with streaming music if you run a timer that should have exactly the same frequency to keep track of blocks in a ring buffer as it will run out of sync. (a tempoarly solution is using this bad calculation on arm9 as well, but that's very lame)

fincs commented 4 years ago

I recall trying to fix this myself ages ago, and ending up with out of tune sample playback. This needs more investigation.

Gericom commented 4 years ago

Maybe adding proper rounding would help a bit. Something like (16756991 + ((rate + 1) >> 1)) / rate. That way it is always the closest value it can be at least.

KonPet commented 1 year ago

Hey, I've recently had this issue as well and want to know if this will ever get fixed? Trying to find the source of the audio glitching was super annoying and without Gericom mentioning this wrongly defined macro I wouldn't have figured it out