From 9d41a2a65b423654e87c5f484099e15384c4fdb2 Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 25 Mar 2025 11:35:02 +0100 Subject: [PATCH] fix: move the S->MS conversion to the total bytesize, instead of it being the last operation. due to if small audio fragments are divided trough integer division, they'll evaluate to 0 miliseconds, which is inaccurate. --- src/window/audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window/audio.c b/src/window/audio.c index c39d448..2c6eaae 100644 --- a/src/window/audio.c +++ b/src/window/audio.c @@ -185,9 +185,9 @@ audiodata audio_wav_load(audiodevice const* dev, char const* fpath) { return (audiodata){0}; } - audio.ms = 1000 * (((audio.len) / (SDL_AUDIO_BITSIZE(dev->fmt) / 8)) / spec.channels / dev->freq); // calculate the time in milliseconds of the audio fragment // by dividing the audio bytelength by the format's bitsize, by the audio device's channels and the audio device's frequency + audio.ms = (((1000 * audio.len) / (SDL_AUDIO_BITSIZE(dev->fmt) / 8)) / spec.channels / dev->freq); return audio; }