How to play multiple wxSound objects at once?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Tapsa
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

How to play multiple wxSound objects at once?

Post by Tapsa » Fri Jan 27, 2017 11:06 am

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.

User avatar
doublemax
Moderator
Moderator
Posts: 15084
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to play multiple wxSound objects at once?

Post by doublemax » Fri Jan 27, 2017 1:57 pm

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.
Use the source, Luke!

Tapsa
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: How to play multiple wxSound objects at once?

Post by Tapsa » Sun Jan 29, 2017 8:58 am

If I understand correctly, I will need separate wxMediaCtrl objects for the simultaneously playing sounds?

User avatar
doublemax
Moderator
Moderator
Posts: 15084
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to play multiple wxSound objects at once?

Post by doublemax » Sun Jan 29, 2017 9:13 am

Yes.
Use the source, Luke!

Tapsa
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: How to play multiple wxSound objects at once?

Post by Tapsa » Mon Jan 30, 2017 8:22 am

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.

User avatar
doublemax
Moderator
Moderator
Posts: 15084
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to play multiple wxSound objects at once?

Post by doublemax » Mon Jan 30, 2017 11:24 am

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.
Use the source, Luke!

Tapsa
Earned some good credits
Earned some good credits
Posts: 144
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: How to play multiple wxSound objects at once?

Post by Tapsa » Tue Jan 31, 2017 8:07 pm

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

Post Reply