From 089ac4b2083bb99731c80229973d1a6d4ec39f99 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 21 Feb 2026 11:11:05 +1000 Subject: [PATCH] Audio: Make the period size (latency) configurable. The default period size is 10ms, but this is inappropriate for certain platforms so it is useful to be able to allow those platforms to configure the period size as required. --- src/config.h | 1 + src/raudio.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/config.h b/src/config.h index 5e7c6f1d2..3beaeeceb 100644 --- a/src/config.h +++ b/src/config.h @@ -303,6 +303,7 @@ #define AUDIO_DEVICE_FORMAT ma_format_f32 // Device output format (miniaudio: float-32bit) #define AUDIO_DEVICE_CHANNELS 2 // Device output channels: stereo #define AUDIO_DEVICE_SAMPLE_RATE 0 // Device sample rate (device default) +#define AUDIO_DEVICE_PERIOD_SIZE_IN_FRAMES 0 // Device period size (controls latency, 0 defaults to 10ms) #define MAX_AUDIO_BUFFER_POOL_CHANNELS 16 // Maximum number of audio pool channels diff --git a/src/raudio.c b/src/raudio.c index 021b65016..91fc03acf 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -290,6 +290,9 @@ typedef struct tagBITMAPINFOHEADER { #ifndef AUDIO_DEVICE_SAMPLE_RATE #define AUDIO_DEVICE_SAMPLE_RATE 0 // Device output sample rate #endif +#ifndef AUDIO_DEVICE_PERIOD_SIZE_IN_FRAMES + #define AUDIO_DEVICE_PERIOD_SIZE_IN_FRAMES 0 // Device latency. 0 defaults to 10ms +#endif #ifndef MAX_AUDIO_BUFFER_POOL_CHANNELS #define MAX_AUDIO_BUFFER_POOL_CHANNELS 16 // Audio pool channels @@ -478,6 +481,7 @@ void InitAudioDevice(void) config.playback.format = AUDIO_DEVICE_FORMAT; config.playback.channels = AUDIO_DEVICE_CHANNELS; config.sampleRate = AUDIO_DEVICE_SAMPLE_RATE; + config.periodSizeInFrames = AUDIO_DEVICE_PERIOD_SIZE_IN_FRAMES; config.dataCallback = OnSendAudioDataToDevice; config.pUserData = NULL; config.noPreSilencedOutputBuffer = true; // raylib pre-silences the output buffer manually