Closed paulross80 closed 2 years ago
had the same or related issue earlier and this is quite common, you should use ma_sound_seek_to_pcm_frame
and set it to 0 to repeat the same sound resource without creating new ones. https://github.com/mackron/miniaudio/issues/516
Moving this to the discussion section.
You need a separate ma_sound
object for every instance of the sound you want to play simultaneously. The resource manager will ensure the sound data is only loaded once, but keep in mind the reference counting system that automatically unloads sounds (section 6.2.2 in the documentation): https://miniaud.io/docs/manual/#ResourceManagement
A common technique is to load all of your sounds initially at load time and store a cache of ma_sound
objects. Then whenever you need to play a sound, use ma_sound_init_copy()
.
Hello, I'm making a C++ game under Linux, kernel 5.15 LTS Everything is initialized correctly. I've noticed that when the player fires the gun, the sound plays, but if the enemy is also shooting, the sound of their gun is not heard (it is the same ma_sound object). The sound is played by both entities, but the new sound starts only when the previous finished playing. I'm reading the documentation again, and the reddit, but I cannot find an example of repeating sounds. Here is my initialization code:
` // Initialize the audio context // Use default backend priorities audioContextInitResult = ma_context_init(nullptr, 0U, nullptr, &audioContext);
// for (ma_uint32 device = 0U; device < playbackDevicesCount; device++) // fmt::print(" - audio device: {}, name: ${}$, default? {}\n", device, playbackDevicesInfo[device].name, playbackDevicesInfo[device].isDefault);
` Is it possible to repeat sounds?