From 1ca75446c6f4f3c26c4593c03ff4a8f26330fa42 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 7 May 2024 22:32:58 -0700 Subject: [PATCH] Libretro: Fix audio resampling after GBA fix --- src/platform/libretro/libretro.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/platform/libretro/libretro.c b/src/platform/libretro/libretro.c index d2565a42b..8191d4868 100644 --- a/src/platform/libretro/libretro.c +++ b/src/platform/libretro/libretro.c @@ -53,6 +53,7 @@ static retro_set_sensor_state_t sensorStateCallback; static void GBARetroLog(struct mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args); static void _postAudioBuffer(struct mAVStream*, struct mAudioBuffer*); +static void _audioRateChanged(struct mAVStream*, unsigned rate); static void _setRumble(struct mRumble* rumble, int enable); static uint8_t _readLux(struct GBALuminanceSource* lux); static void _updateLux(struct GBALuminanceSource* lux); @@ -498,10 +499,11 @@ void retro_init(void) { logger.log = GBARetroLog; mLogSetDefaultLogger(&logger); - stream.videoDimensionsChanged = 0; - stream.postAudioFrame = 0; - stream.postAudioBuffer = _postAudioBuffer; - stream.postVideoFrame = 0; + stream.videoDimensionsChanged = NULL; + stream.postAudioFrame = NULL; + stream.postAudioBuffer = NULL; + stream.postVideoFrame = NULL; + stream.audioRateChanged = _audioRateChanged; imageSource.startRequestImage = _startImage; imageSource.stopRequestImage = _stopImage; @@ -913,13 +915,14 @@ bool retro_load_game(const struct retro_game_info* game) { * using the regular stream-set _postAudioBuffer() * callback with a fixed buffer size, which seems * (historically) to produce adequate results */ - core->setAVStream(core, &stream); + stream.postAudioBuffer = _postAudioBuffer; audioSampleBufferSize = GB_SAMPLES * 2; audioSampleBuffer = malloc(audioSampleBufferSize * sizeof(int16_t)); audioSamplesPerFrameAvg = GB_SAMPLES; core->setAudioBufferSize(core, GB_SAMPLES); } + core->setAVStream(core, &stream); core->setPeripheral(core, mPERIPH_RUMBLE, &rumble); core->setPeripheral(core, mPERIPH_ROTATION, &rotation); @@ -1250,6 +1253,13 @@ static void _postAudioBuffer(struct mAVStream* stream, struct mAudioBuffer* buff } } +static void _audioRateChanged(struct mAVStream* stream, unsigned rate) { + UNUSED(stream); + struct retro_system_av_info info; + retro_get_system_av_info(&info); + environCallback(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &info); +} + static void _setRumble(struct mRumble* rumble, int enable) { UNUSED(rumble); if (!rumbleInitDone) {