Fixed audio issues#3702
Merged
Merged
Conversation
…rt duration audio clips on high sample rate devices.
…ning that audio data is processed at the device sample rate.
…ead of device sample rate when constructing processing filters.
eXpl0it3r
approved these changes
Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This changeset fixes 2 minor issues:
Miniaudio organizes sounds into a node graph. Data is recursively pulled from the sink (the audio device) back to the sources traversing the graph node by node. Because we are using the miniaudio engine for special effects (surround, doppler, etc.) the nodes are engine nodes as well. The engine is initialized to process data at the same sample rate as the device it is attached to. This means that as soon as data is read from the source e.g. an audio file it is converted into the engine/device format before it is sent through the graph.
SFML's support for audio effects processing via callback is implemented by a custom node we insert into the node graph right after the sound source. This means that audio data passing through our effects processing node will already be in the device format since conversion was performed in the source node. Before this change, the sound effects example was incorrectly using the sample rate of the source data instead of the device sample rate to perform filtering leading to incorrect processing taking place.
This becomes noticeable the more the audio playback device sample rate deviates from the audio file that is being played. To reproduce the problem, run the sound effects example using a playback device that is set to a higher than typical sample rate e.g. 384KHz and activate any of the processing filters e.g. echo or low/high-pass filters.
This fix changes the processing filters to use the device sample rate instead.
When running the tennis example with my audio device set to 384KHz sample rate I noticed that the first ball bounce sound was not playing. Subsequent ball bounce sounds played.
Through debugging I found out this was due to the allocated audio frame buffer for high sample rate devices being so large that the entirety of the ball bounce samples was not enough to fill it leading to the first play of the sound not outputting any audio. When creating a device, miniaudio allows specifying
periodSizeInFrames. This value is used as a hint when allocating the device buffer, it is clamped between a minimum and maximum buffer size supported by the device. This value is also used as the size of the buffer used to pull audio data through the miniaudio node graph.In order to prevent the entirety of a sound's samples not filling up the buffer used to pull audio, we simply reduce the size of the buffer used to pull audio data. The smaller the buffer the more frequent miniaudio has to pull audio data since each buffer will contain a smaller duration of data which means that CPU load increases, thus we don't want to set the value lower than it has to be. From testing it seems like setting
periodSizeInFramesto 64 allows us to play very short audio clips even on high sample rate devices without the first plays of the audio going missing. If it turns out this value has to be adjusted in the future or a possibility has to be provided for the user to set it through the public API the discussion can continue in another issue.