This is a sample of how to use raylib's LoadSoundAlias() function to play a sound that overlaps without loading the sound data multiple times.
There are two methods in this example:
Method 1 loads a sound into an array, where address 0 is the original sound and the rest of the slots are aliases, and then play sound from the array in sequence with an index variable that increments and wraps each time the sound is played
the sounds are loaded before the game loop, played during the loop and then unloaded before cleanup routine upon exiting the game loop.
Pros: simple, clean implementation
Tradeoff: multiple copies of overlapping sound staying in memory even when not being played, each one with it's own array.
Method 2 loads a sound to a single variable as usual and upon playing the sound in the game loop, an alias is created in a dynamic array and then played right away
at the end of each frame, every slot in the dynamic array is traversed for sounds that are no longer playing and unloads them before doing an unordered remove of that sound
In most games, the max number of sounds playing at any given time is small enough that array traversal should be pretty quick
Pros:
Only one array needed for all sounds, can overlap theoretically an unlimited number of times
Can skip cleanup frames with no real penalty, allowing to split up unloading to multiple frames
Tradeoff: complexity in setup, maybe slower than Method 1
The X key samples method 1
The V key samples method 2
The C key plays the sound directly, demonstrating the default play sound behavior which doesn't overlap.
https://odin-lang.org/docs/overview/
https://www.raylib.com/
NOTE
Sound file not included for copyright reasons. Just drop a sound file in the res folder and change the string in the path variable