This project has moved and is read-only. For the latest updates, please go here.

Playing Audio on several soundcards

Mar 10, 2016 at 1:55 AM
Edited Mar 10, 2016 at 2:28 AM
Hi, is there any way to play a WaveStream on many soundcards at the same time?

I actually use code like this, but it introduces some delay I´d wish to remove:
Private Sub PlayOnAllSoundcards(Byval FilePath as String, Byval CardIDs() as Integer)
     For Each SoundcardID as Integer in CardIDs
         Dim SourceReader as new AudioFileReader(FilePath)
         Dim WaveOut as new WaveOutEvent() with {.DeviceNumber = SoundcardID}
         WaveOut.Init(SourceReader)
         WaveOut.Play()
     Next
End Sub
Creating multiple Reader and Output objects introduces obv. some latency. All inputs are in the Wformat (44100,2,16).

I´ve looked at your MultiplexingWaveProvider source as you wrote in your article, it would send output to several soundcards, but it still has only one Read method - therefore not usable to Init in many WaveOut objects. Right?

My questions in detail:

So how to play audio professionally on several soundcards?

And how to set channel matrices (for virtual surround sound) like CSCore does?

Thanks in advance, it would pretty much boost my Media Player!

PS: I love NAudio architecture. And still reading your blog for NAudio news :)
Mar 11, 2016 at 10:10 PM
To play the same file on multiple soundcards the easiest way is actually still to create multiple readers and output devices. But there is no easy way to keep them in sync. It might be possible to have a bunch of BufferedWaveProviders, one for each output device, and when one runs out, we read from the single audio file reader and put the audio into all the bufferedwaveproviders.

Ideally for multi-channel audio you'd open a single audio device and play a multi-channel stream to it, rather than open more than one soundcard. I've not tried this myself with anything other than ASIO though.
Mar 12, 2016 at 12:49 AM
Hmm, but that buffering wouldn´t sync them if I understand correctly. They would have to start perfectly parallel and process with exactly the same speed to make that work, right?

If you could figure out a sample that would be great.