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!

The mmap() system call

All OSS system calls follow the familiar Posix/Unix semantics. Please look at the standard manual page (man mmap) for more informtion. This section will only explain some OSS related details. The error codes returned by OSS as well as their meaning will be described in the Possible error codes (errno) returned by OSS calls section.

mmap() is not available under all operating systems supported by OSS. This means that applications using it may not be portable to all operating systems.

While it's possible to use mmap with audio devices this method is not recommended. In this way most functionality of OSS will be bypassed which means that the application is on it's own. There are no sample rate or sample format conversions so the application must be able to support any sampling rates (8 kHz to 192 kHz at least), any number of channels (1 to 16 or even more) and every possible sample format (at leas 8, 16, 24 and 32 bits with all possible endianess and signed/unsigned combinations). Otherwise it's almost certain that the application will fail with many devices. In particular with the high end devices designed for professional purposes.

Some programmers seem to think that mmap is some kind of super weapon that makes everything to rock. This is just an urban legend. In the current workstations use of mmap may make the application 0.01% faster than with the normal read/write method. It doesn't have any effect on latencies. So does it make any sense to using it?

The mmap approach should not be used in applications like games that are intended to the mass market. It can be used in custom applications for scientific or technical purposes when it's possible to select a sound device that supports this access method properly.

In controlled environments it may be possible to get practically zero latencies by using this method. However this really means that the whole environment is hand crafted. The computer needs to be dedicated to this purpose and there must not be anything else running in the same computer. The hardware being used must be specially designed for this. Practically all devices use all kind of internal FIFOs that make precise timing impossible.

Consumer applications don't require anything like this. For example all that games and video players need is lip sync. This means something like 1/24 seconds (40 milliseconds) latency requirements. Getting this kind of timing accuracy is piece of cake and doesn't require any rocket science such as use of mmap.

There is no documentation available for using mmap with OSS at this moment. You can use the mmap_test.c sample program as a template. It's included in the OSS package.

Sample programs

mmap_duplex.cA simple sample program for doing dull duplex using mmap
mmap_test.cA sample program for using mmap()

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