Copyright © 2005-2021 MultiMedia Soft

How to work with multiple output devices and speakers

Previous pageReturn to chapter overviewNext page

Inside this tutorial we will see how to manage output devices having a DirectSound compatible sound card driver (WDM); when the WASAPI protocol has been set as an alternative to DirectSound, you can check the How to manage audio flow through WASAPI tutorial. For output devices having an ASIO driver you can check the How to manage ASIO drivers tutorial.

 

 

Output devices

 

If the target system has more than one output device, also known as "sound card", compatible with DirectSound, you can force each of the allocated players to redirect its output to a specific device: the number and friendly description of available output devices can be obtained using the GetOutputDevicesCount and GetOutputDeviceDesc methods: once you have obtained the list of installed devices, you can initialize each player's output through a single call to the InitSoundSystem method, passing the device index to the nOutputX parameters; the output device returned when calling the GetOutputDeviceDesc method with parameter 0 is always the system default device set through the Windows Control Panel: in case the system default output device should be changed through the Control Panel, the container application would be notified of the change through the DeviceChange event.

 

During the container application execution there could be the need to change "on the fly" the output device for a certain player: the current output device can be obtained through a call to the StreamOutputDeviceGet method and the output device change can be performed through the StreamOutputDeviceSet method; the capability of changing the output device on a plying sound is very useful if you need a monitor output for your headphones. It's important to note that the switch of the output device can be performed without problems when the player is in "Playing", "Paused" or "Stopped" state. If the output device is changed successfully, an OutputDeviceChanged event is fired.

 

 

Speakers management

 

Starting from Windows Vista, Microsoft has totally rewritten from the ground up the Windows multimedia subsystem so speakers management depends upon the Windows version in use:

 

Speakers management under Windows XP and older versions of Windows
Speakers management under Windows Vista and newer versions of Windows

 

 

 

Speakers management under Windows XP and older versions of Windows

 

Most sound cards can have more than plain stereo output in order to support surround sound or in order to support multi-player features: this control allows playback of multi-channel sound files (for WAV, AIFF, OGG Vorbis and WMA formats) loaded through the LoadSound method and, at the same time, it can support speakers assignment.

Speakers assignment can be usually set through the Control Panel as seen on the screenshot below:

 

adjstudnet_i000066

 

after pressing the "Advanced..." button you will see the following dialog box:

 

adjstudnet_i000067

 

 

If your application needs to manage speakers assignment, the first thing to do is setting the EnableSpeakers property to TRUE: this property must be set at design-time; setting this property at runtime will not have any effect and will be simply ignored.

 

Once the speakers management has been enabled and the control has been initialized through the InitSoundSystem method, the control can retrieve the actual number of speakers enabled on an output device through the GetOutputSpeakersConfig method and change it through the SetOutputSpeakersConfig method. It's important to note that some specific sound card software (for example the Sound Blaster Audigy 2 NX) could override these settings so you should modify the speakers setup for this sound card using the sound card's proprietary control panel.

 

The current speakers configurations supported by the control are the following:

 

Sound cards with 1 plain stereo output (2 speakers)

adjstudnet_i000068

 

This configuration allows 1 single player to play 1 stereo sound.

In alternative, this configuration allows 2 different players to play 2 different mono sounds on the following speakers:

1. Left speaker

2. Right speaker

 

Sound cards with 2 stereo outputs (4 speakers), also known as Quadraphonic

 

adjstudnet_i000069

 

This configuration allows 2 different players to play 2 stereo sounds on the following speakers:

1. Front speakers

2. Rear speakers

 

In alternative, this configuration allows 4 different players to play 4 different mono sounds on the following speakers:

1. Front-Left speaker

2. Front-Right speaker

3. Rear-Left speaker

4. Rear-Right speaker

 

Sound cards with 3 stereo outputs (6 speakers), also known as 5.1

 

adjstudnet_i00006a

 

This configuration allows 3 different players to play 3 stereo sounds on the following speakers:

1. Front speakers

2. Rear speakers

3. Center speakers

 

In alternative, this configuration allows 6 different players to play 6 different mono sounds on the following speakers:

1. Front-Left speaker

2. Front-Right speaker

3. Rear-Left speaker

4. Rear-Right speaker

5. Center speaker

6. LFE speaker that, usually, is attached to a subwoofer

 

Sound cards with 4 stereo outputs (8 speakers), also known as 7.1

 

adjstudnet_i00006b

 

This configuration allows 4 different players to play 4 stereo sounds on the following speakers:

1. Front speakers

2. Rear speakers

3. Center speakers

4. Rear-center speakers

 

In alternative, this configuration allows 8 different players to play 8 different mono sounds on the following speakers:

1. Front-Left speaker

2. Front-Right speaker

3. Rear-Left speaker

4. Rear-Right speaker

5. Center speaker

6. LFE speaker that, usually, is attached to a subwoofer

7. Rear Center-Left speaker

8. Rear Center-Right speaker

 

 

 

When the container application is started the control will automatically enumerate the available speakers for each installed output device and the container application will be able retrieving the number of available speakers through the GetOutputSpeakersCount method or, in alternative, through the GetPlayerSpeakersCount method. Some specific output device (for example the Maya EX7 sound card) will always return 2 speakers also if it supports up to 8 mono speakers: in this case the container application can force the speakers assignment through a call to the ForceSpeakersAssignment method.

 

Some specific output device (again the Maya EX7 sound card) will invert the Rear and Center speakers assignment: you can get rid of this situation through the StreamOutputSpeakersRearAndCenterSwap method.

 

The StreamOutputSpeakerGet and StreamOutputSpeakerSet methods allow a given player to obtain/redirect its output to a specific speaker of the current output device; if two allocated players are currently using two different speakers on the same output device, you can swap their speakers assignment through a call to the StreamOutputSpeakerSwap method: note that it's not allowed swapping speakers of players currently redirecting their output to different output devices.

 

Note on subwoofer assignment: the control maps the Center mono speaker as a Left channel and the Subwoofer mono speaker as a Right channel: some commercial Home Theatre system inverts these speakers: the control cannot manage this situation so, when using the control with these kind of systems, the final user will have to swap cables for Center and Subwoofer speakers.

 

 

 

Speakers management under Windows Vista and newer versions of Windows

 

Most sound cards can have more than plain stereo output in order to support surround sound or in order to support multi-player features: this control allows playback of multi-channel sound files (for WAV, AIFF, OGG Vorbis and WMA formats) loaded through the LoadSound method and, at the same time, it can support speakers assignment.

 

Speakers configuration is not available through CoreAudio APIs so it cannot be modified programmatically but only through the Sounds applets of the Windows control panel as seen on the screenshot below:

 

 

after pressing the "Configure..." button you will see the following dialog box:

 

 

By default the sound card should have "Stereo" enabled so, if you want enable speakers management depending upon the capabilities of the sound card in use, you will have to change a different option under the "Audio channels" listbox. If for example you should need to enable all of the 8 speakers available inside a 7.1 sound card, you will have to select the "7.1 Surround" option as seen on the screenshot below:

 

 

When the container application is started the control will automatically enumerate the available speakers for each installed output device and the container application will be able retrieving the number of available speakers through the GetOutputSpeakersCount method or, in alternative, through the GetPlayerSpeakersCount method.  It's important to note that, if the default "Stereo" option should be selected from the Control Panel, the system will always return 2 speakers also if the sound card has 8 physical speakers: under Windows Vista and higher versions there is no documented way to force changing the speakers configuration programmatically (meaning that calls to the SetOutputSpeakersConfig method will have no effect) so the final user will have to be instructed about changing the speaker settings inside the Control Panel as described above in order to be able exploiting all of the available physical speakers.

 

It's important to note that not all sound card drivers implement the "Configure" feature as seen on the screenshot above: in certain cases, for example with the M-Audio Delta 1010LT sound card, you will have to enable multi-channel by selecting the appropriate playback format; this feature can be achieved as seen on the screenshot below:

 

 

after pressing the "Properties" button select the "Advanced" tab:

 

 

and select the appropriate playback format: as you can see, in this case you don't have much options for multi-channel.

 

Some specific output device will invert the Rear and Center speakers assignment: you can get rid of this situation through the StreamOutputSpeakersRearAndCenterSwap method.

 

The StreamOutputSpeakerGet and StreamOutputSpeakerSet methods allow a given player to obtain/redirect its output to a specific speaker of the current output device; if two allocated players are currently using two different speakers on the same output device, you can swap their speakers assignment through a call to the StreamOutputSpeakerSwap method: note that it's not allowed swapping speakers of players currently redirecting their output to different output devices.

 

Note on subwoofer assignment: the control maps the Center mono speaker as a Left channel and the Subwoofer mono speaker as a Right channel: some commercial Home Theatre system inverts these speakers: the control cannot manage this situation so, when using the control with these kind of systems, the final user will have to swap cables for Center and Subwoofer speakers.

 

 

Samples of use of speakers and output devices management in Visual C#.NET and Visual Basic.NET can be found inside the following samples installed with the product's setup package:

- OutputDevices

- SpeakersManager