GBA Audio: Fix crash in audio subsampling if timing lockstep breaks

This commit is contained in:
Vicki Pfau 2024-06-25 04:08:47 -07:00
parent a4c2571d98
commit 79193b914b
3 changed files with 5 additions and 1 deletions

View File

@ -24,6 +24,7 @@ Other fixes:
- Debugger: Fix writing to specific segment in command-line debugger
- GB: Fix uninitialized save data when loading undersized temporary saves
- GBA Audio: Fix crash if audio FIFOs and timers get out of sync
- GBA Audio: Fix crash in audio subsampling if timing lockstep breaks
- GBA Memory: Let raw access read high MMIO addresses
- Qt: Fix savestate preview sizes with different scales (fixes mgba.io/i/2560)
- Qt: Fix potential crash when configuring shortcuts

View File

@ -80,7 +80,7 @@ struct GBAAudio {
int32_t sampleInterval;
int32_t lastSample;
int sampleIndex;
unsigned sampleIndex;
struct mStereoSample currentSamples[GBA_MAX_SAMPLES];
bool forceDisableChA;

View File

@ -232,6 +232,9 @@ void GBAAudioWriteSOUNDBIAS(struct GBAAudio* audio, uint16_t value) {
if (oldSampleInterval != audio->sampleInterval) {
timestamp -= audio->lastSample;
audio->sampleIndex = timestamp >> (9 - GBARegisterSOUNDBIASGetResolution(value));
if (audio->sampleIndex >= GBA_MAX_SAMPLES) {
audio->sampleIndex = 0;
}
if (audio->p->stream && audio->p->stream->audioRateChanged) {
audio->p->stream->audioRateChanged(audio->p->stream, GBA_ARM7TDMI_FREQUENCY / audio->sampleInterval);
}