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_POLICY

Sets the timing policy of an audio device

Usage

int policy=The policy value;
ioctl(fd, SNDCTL_DSP_POLICY, &policy);

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 is an easier to use version of SNDCTL_DSP_SETFRAGMENT. With it the application can specify the timing policy (between 0 and 10) it wants. The timing policy determines how the driver should allocate the buffers.

Argument value of 5 will give the default policy that is suitable in most cases.

Value of 10 will select a buffering mode that minimizes the resource usage by the driver. This is ideal in applications that don't have any latency requirements (see the Audio timing considerations section for more info).

Argument value of 0 gives a buffering policy with agressively low latencies. However the drawback is that that the interrupt rate and the CPU usage caused by the application will increase very significantly. Also the timing requirements will be very difficult to handle without extreme real time programming techniques. In general policy values below 2 are not recommended because they may not work properly in normal general purpose computer environments.

Values below 5 will give lower and lower latencies with slightly increased CPU usage. Values above 5 will give lower CPU usage with increased latencies.

This call will return with errno=EIO if the driver cannot handle the requested policy. errno=EINVAL means that the driver doesn't support this ioctl call. The application must be carefull in handling the error returns of this call. Usually the application will work just fine even this call fails.

The application using this call should not care about the exact buffer sizes. They will be automatically selected by OSS depending on the device and the other system characteristics.

Related ioctl calls

Compatibility issues

This is a new ioctl call in OSS 4.0 and not supported by any earlier implementations. If this call is not supported then ioctl will report an EINVAL error. In this situation the application may call SNDCTL_DSP_SETFRAGMENT to get suitable timing policy.

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

No sample programs available

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