GBA Audio: Fix sample position issues when rate changes (fixes #3006)

This commit is contained in:
Vicki Pfau 2023-08-23 14:35:16 -07:00
parent 16fe12cc97
commit 0acc8c2af2
2 changed files with 5 additions and 3 deletions

View File

@ -17,6 +17,7 @@ Emulation fixes:
- GBA: Unhandled bkpt should be treated as an undefined exception
- GBA Audio: Fix sample timing drifting when changing sample interval
- GBA Audio: Fix initial channel 3 wave RAM (fixes mgba.io/i/2947)
- GBA Audio: Fix sample position issues when rate changes (fixes mgba.io/i/3006)
- GBA GPIO: Fix tilt scale and orientation (fixes mgba.io/i/2703)
- GBA BIOS: Fix clobbering registers with word-sized CpuSet
- GBA SIO: Fix normal mode SI/SO semantics (fixes mgba.io/i/2925)

View File

@ -253,13 +253,14 @@ void GBAAudioWriteSOUNDCNT_X(struct GBAAudio* audio, uint16_t value) {
}
void GBAAudioWriteSOUNDBIAS(struct GBAAudio* audio, uint16_t value) {
GBAAudioSample(audio, mTimingCurrentTime(&audio->p->timing));
int32_t timestamp = mTimingCurrentTime(&audio->p->timing);
GBAAudioSample(audio, timestamp);
audio->soundbias = value;
int32_t oldSampleInterval = audio->sampleInterval;
audio->sampleInterval = 0x200 >> GBARegisterSOUNDBIASGetResolution(value);
if (oldSampleInterval != audio->sampleInterval) {
audio->lastSample += oldSampleInterval * audio->sampleIndex;
audio->sampleIndex = 0;
timestamp -= audio->lastSample;
audio->sampleIndex = timestamp >> (9 - GBARegisterSOUNDBIASGetResolution(value));
if (audio->p->stream && audio->p->stream->audioRateChanged) {
audio->p->stream->audioRateChanged(audio->p->stream, GBA_ARM7TDMI_FREQUENCY / audio->sampleInterval);
}