Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multi channel sound with winmm, many WaveOutOpen?

I am trying to play a sound on Windows XP in multi-channel (parallel) manner. I had read somewhere that playing parallel sounds with WinMM is maybe not possible, but here is what I observe:

When I call WaveOutOpen() once, and then call many WaveOutWrite() many times then sounds are not parallel - they are queued.

But when I call WaveOutOpen say nine times (and then store nine handles to it) and then call nine times WaveOutWrite() with nine different sounds they are played in parallel (multi-channel) - that is they are mixed.

It seems to work but I am not sure if it is okay because I don't find it stated clearly in any tutorial or documentation.

It is okay to play sound in such 'many WaveOutOpen' way??

like image 579
grunge fightr Avatar asked Oct 10 '22 20:10

grunge fightr


2 Answers

When I call WaveOutOpen() once, and then call many WaveOutWrite() many times then sounds are not parallel - they are queued.

That's exactly what is supposed to happen. WaveOutWrite queues the next buffer. It allows you to send the audio you want to play in small chunks.

But when I call WaveOutOpen say nine times (and then store nine handles to it) and then call nine times WaveOutWrite() with nine different sounds they are played in parallel (multi-channel) - that is they are mixed.

Again, this is correct and expected. This is the simplest way to play back many simultaneous sounds. If you want sample accurate mixing however, you should mix the audio samples yourself into one stream of samples and play that through a single WaveOut device.

like image 137
Mark Heath Avatar answered Oct 19 '22 04:10

Mark Heath


I stand corrected with ability of waveOut* API to play sounds simultaneously and mixed.

Here is test code for the curious: http://www.alax.info/trac/public/browser/trunk/Utilities/WaveOutMultiPlay An application started with arguments abc plays on different threads sounds at 1, 5 and 15 kHz respectively and they mix well.

At the same time DirectShow Audio Renderer (WaveOut) Filter built on top of the same API is unable to play anything more that a single stream, for no visible reason.

FYI waveOutOpen API is retired since long ago and currently is wrapper on top of newer APIs. waveOutOpen assumes that audio output device is opened for exclusive use so there is no guarantee that multiply opened devices simultanesouly would produce mixed audio output. To achieve such behavior you would be better off with a newer audio API: DirectSound, DirectShow on top of DirectSound or WASAPI.

like image 1
Roman R. Avatar answered Oct 19 '22 02:10

Roman R.