Page 1 of 1

How to play multiple wxSound objects at once?

Posted: Fri Jan 27, 2017 11:06 am
by Tapsa
In my program I need to play up to four sound files simultaneously.
First problem I found is that wxSound is noncopyable, but I got over it only to find out that the documentation correctly says
If another sound is playing, it will be interrupted.
in the description of wxSound::Play, which I sadly noticed while testing my app.

Re: How to play multiple wxSound objects at once?

Posted: Fri Jan 27, 2017 1:57 pm
by doublemax
I haven't tried it, but if the documentation says so and your tests confirm it, i guess there is nothing you can do.

You could try to use a (hidden) wxMediaCtrl to play the sounds, although it sounds like overkill.

Re: How to play multiple wxSound objects at once?

Posted: Sun Jan 29, 2017 8:58 am
by Tapsa
If I understand correctly, I will need separate wxMediaCtrl objects for the simultaneously playing sounds?

Re: How to play multiple wxSound objects at once?

Posted: Sun Jan 29, 2017 9:13 am
by doublemax
Yes.

Re: How to play multiple wxSound objects at once?

Posted: Mon Jan 30, 2017 8:22 am
by Tapsa
wxMediaCtrl seems to have no method to load media from memory.
I need a function similar to this:

Code: Select all

wxSound (size_t size, const void *data)
It looks like I am left to seek for alternative libraries outside of wx.
It turned out that I need mp3 support too, so mixing wave forms would not be enough.

Re: How to play multiple wxSound objects at once?

Posted: Mon Jan 30, 2017 11:24 am
by doublemax
For playing WAV data you can use PortAudio: http://www.portaudio.com

It doesn't contain any decoders though, so you'll need another library for that.

Re: How to play multiple wxSound objects at once?

Posted: Tue Jan 31, 2017 8:07 pm
by Tapsa
TY. That lib (along with some decoders) seems to be a good way to go.

It's ridiculous that there is no one-liner library out there for such a simple thing as playing multiple sounds simultaneously.
Like this

Code: Select all

#include "one_liner_sound_library.h"
...
SoundLib::Play(/* some settings */);
SoundLib::Play(/* some settings */); // Both sounds can be heard
Something is wrong when you can write OpenGL program to show some nice graphics with less lines than write a program to play sound files.
/rant