Open Sound System
OSS 4.x Programmer's Guide

Do you have problems with sound/audio application development? Don't panic! Click here for help!


Get the channel ordering of a multi channel device


unsigned long long map;
ioctl(fd, SNDCTL_DSP_GET_CHNORDER, &map);

The above code fragment lacks all error checks for clarity. Real world applications must always check for the errors and handle them as described below. Also most OSS ioctl calls will return information in the argument variable and it's usually necessary to check it too.


This ioctl call is currently under constructions. The following description is just an initial draft. It's likely that the implementation may change during the initial testing. In particular the meanings of the slot numbers may change.

This ioctl call returns the "interleaving" order of a multi channel audio stream. The SNDCTL_DSP_SET_CHNORDER call is defined for changing the order but at this moment it's not implemented (may get implemented in selected drivers in the future).

This ioctl call is optional and not all drivers support it. For this reason it's normal that this call returns errno=EINVAL. This is not an error. The device may support multiple channels. It just can't tell what the channel assignment is.

This ioctl call is not valid with bitstream oriented formats such as MP3 or MPEG. Such formats don't use channel interleaving.

The argument is a 64 bit unsigned integer (unsigned long long). It consists of 16 bit fields of 4 bits each. The bit fields tell which "speaker" matches the corresponding slot of the audio stream. Bits 0 to 3 corespond to the first slot of the stream and the last field (bits 60 to 63) belong to the 16th channel. If there is no binding defined for the slot then the corresponding bit field is set to 0.

If the device supports more than 16 devices this call returns the information only for the first 16 ones. However it probably doesn't make any sense to use this call with such devices.

Another interpretation is that the whole 64 bit integer is a channel mode identifier. Both methods can be used in parallel. There are two predefined values (at this moment).

The numeric value of CHNORDER_NORMAL is 0x0000000087654321ULL.

The returned value may have defined values for more speakers than the device actually supports. So the application must also know the number of channels the device is currently set to use. The bit fields for the channels higher than that must be ignored.

The SNDCTL_AUDIOINFO call can be used to find out how many channels the device can support. The SNDCTL_DSP_CHANNELS ioctl is used to set the number of channels of the audio stream. The Using multiple channels with OSS section gives more information about using multiple audio channels with OSS.

Compatibility issues

This ioctl call is new in OSS 4.0 and not supported by the freeware implementations based on older OSS versions. If this call returns errno=EINVAL then channel ordering information is not available. In such case the application can assume 1:1 mapping.

OSS ioctl return values

The return value from the OSS ioctl calls will be -1 if a fatal error occurred. Other values mean that the ioctl call was more or less successful. However in most cases the application must check the value returned in the argument to see what was the accepted value.

Please see the Possible error codes (errno) returned by OSS calls section for more info about the error codes returned by OSS.

Sample programs

No sample programs available

Copyright (C) 4Front Technologies, 2007. All rights reserved.
Back to index OSS web site