Google
 

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!

SNDCTL_DSP_CHANNELS

Set the number of audio channels

Usage

int channels=Number of Channels;
ioctl(fd, SNDCTL_DSP_CHANNELS, &channels);

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.

Description

This ioctl call selects the number of audio channels. For example 1=mono and 2=stereo. Some devices support even more channels such as 4, 6 or 8. The OSS API itself doesn't set any limit to the number of channels. It depends on the device being used. Please see the Using multiple channels with OSS section for more info about using multiple channels formats such as 5.1. The SNDCTL_DSP_CHANNELS call returns the number of channels in the variable pointed by the argument (channels in above). The returned value may be different than the one requested. The application must check the returned value and re-adjust it's operation based on that information. Please see the description of Return information about an audio device for more information about the possible parameters.

Compatibility issues

This call is supported by all OSS versions and implementations. However some freeware implementations may incorrectly return an error if the device doesn't support the requested value. This is clearly a driver bug and there is no need to be prepared to this in the application.

Please look at the When OSS audio ioctl calls can be made section for information about DSP ioctl call ordering.

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

osstest.cThe osstest program shipped with OSS
ossplay.cSources for the ossplay audio player and for the ossrecord
fulldup.cFull duplex sample program using the single device approach.
mmap_duplex.cA simple sample program for doing dull duplex using mmap
mmap_test.cA sample program for using mmap()
singen.cA simple audio playback program that plays continuous 1 kHz sine wave.
audiolevel.cA simple program that does audio recording.
dsp_geterror_demo.cA simple demonstration of
iosync.cMeasuring the hardware level latencies.
sweepdown.cPlays a funny synthetic engine stop sound
multich32.cSource file oss-testing/tutorials/sndkit/tests/multich32.c
sweepup.cA simple program that plays frequency sweep from 10 Hz to fs/2.
multich16.cSource file oss-testing/tutorials/sndkit/tests/multich16.c
ioctl_test.cThis program has been used to verify that some of the ioctl calls work
spdif_in_debug.cA program that prints the S/PDIF receiver status.
softsynth_gtk.cA simple software MIDI synthesizer program with GTK GUI.
softsynth.cA simple software MIDI synthesizer program.


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