Replies: 1 comment 2 replies
-
I got a solution (and an idea at the bottom of the answer) After playing an ma_sound, I'll do:
This way I am using ma_sound_vector as a vector of how the sounds should be, but I am not actually playing them. Idea: Just a suggestion! |
Beta Was this translation helpful? Give feedback.
-
Hey, I'm back again.
I'm building a C++ Audiophysic Library which uses miniaudio as an audio system. This library has a core class (from now on "CORE"), an audio system class (from now on "AUDIO"), and a physic body class (from now on "BODY").
During all this time since today, I developed this library thinking that I can play the same ma_sound twice at the same time, but miniaudio does not work like this, and I want to explain my code as simple as I can in case anyone can suggest another solution.
This is the wrong situation of my code:
User can load different sounds to the CORE library using CORE->LoadSound(const char* path);
These sounds loaded travels inside AUDIO (which CORE has access) and is "emplace_back()" into the ma_sound vector (known as "ma_sound_vector").
BODY's are the classes that generate sounds, so there is a function "BODY->PlaySound(int indexSound);"
"int indexSound" referes to the index of the ma_sound loaded in AUDIO's ma_sound_vector.
PlaySound(int indexSound) stores the "call of playing a sound" into a "query list". This list has information about the index each BODY wants to play in a frame.
Then, at the end of that code iteration, AUDIO updates, reads all the list and plays all the sounds. Example:
now, inside audio->Update() function.
As you might see, the problem with this comes when 2 different BODY's play the same sound at the same frame. As there is just one ma_sound* stored in ma_sound_vector, it is not possible to play it twice the same frame (or as long as it is playing).
In the future, I'll need to use nodes in order to add effects, so a function to directly play the sound from the path won't work.
Do you see a better way to manage the ma_sound* without having to create the same ma_sound per body that wants to play it??
Hopefully this explanation is understandable. Actually I am not able to provide a code example, but if you think is better, I'll try to do one as soon as I can. Meanwhile, any doubt, I'll reply fast.
Beta Was this translation helpful? Give feedback.
All reactions