Hello,
I'm working on an application that is essentially a network chat system, but I need to support multiple users talking at the same time. After some trial and error, I came up with a method that seems to be working well, but I feel like there is probably a better way, and I'm running into a small issue with different sound cards.
Here's how I have it working now: When the client starts up, it creates a pool of WaveOut instances, each with their own BufferedWaveProvider. The client currently creates a pool of 10 of these. These 10 WaveOuts are all assigned to the same audio device.
When sending audio, each client tags the encoded audio data with a unique client ID and sends it to the server. The server forwards this data to each other user in the chat. The client maintains a mapping of each client ID to one of the 10 BufferedWaveProviders. When the client receives audio data, it looks at the sender's client ID, looks it up in the map, and then feeds the samples to the associated BufferedWaveProvider. This way, if two remote clients are talking at once, their audio does not get intermingled.
Now for the problem ... this has been working great on my development machine, but when I installed the client on another computer (a netbook) an exception was thrown when it tried to create the 10 WaveOuts. The exception happened when it tried to Init() the WaveOut. The error was that it was "already allocated." If I reduced the number of WaveOuts to 5, the problem went away. I assume this is a sound driver limitation.
So, I'm wondering if there's a better way to handle this situation where there are multiple streams from distinct sources that need to be fed to the sound card independently. If not, I think I would at least need a way to determine the maximum number of WaveOuts that can be assigned to a single audio device. I see that the GetCapabilities() method can tell me the number of channels, but it doesn't seem to return a maximum number of wave streams the card can mix.
I know I could just keep constructing WaveOuts until I get the exception, but that seems rather hacky.
Any insight or pointers would be greatly appreciated!