PortAudio - an Open Source Cross Platform Audio API Ross Bencina, Phil Burk email: [email protected], [email protected] website: http: //www.portaudio. com/ Abstract This paper describes a new open-source cross-platform 'C' 'C' Application library for audio input and output. It is designed to simplify the porting of audio applications between various platforms, and also to simplify the development of audio programs inPortAudio general by hiding the complexities of device interfacing. The API was worked out through community discussions on the music-dsp mailing list. A number of people have contributed to the development of the API and are listed on the web-site. WMME OSS Implementations of PortAudio for Windows MME and oth DirectSound, the Macintosh Sound Manager, and Unix OSS DX aud API have been developed and are freely available on the web. Support for other platforms is being planned. The paper describes the use of PortAudio and discusses the issues Audio Hardware involved in its development including the design philosophy, latency, callbacks versus blocking read/write calls, and effi- Figure 1, PortAudio generally uses ciency. audio APIs to access the audio har existing dware. 1. Introduction Suppose you want to write a real-time audio application and you want it to run on more than just one kind of computer. That could mean that you have to learn how to use several different audio APIs like DirectSoundTM on Microsoft WindowsTM, and the MacintoshTM Sound Manager, and OSS on Linux. And then you would have to write interfaces between your program and each of those host-specific APIs. Wouldn't it be nice to just write one simple audio interface for your program and to have it work on the majority of computers. PortAudio is designed to help you do just that. PortAudio is also useful if you are only writing for one platform because PortAudio is often much simpler to use than the native audio APIs. Thus PortAudio could be useful for pedagogical purposes by allowing beginning students to quickly obtain real-time audio input and output. PortAudio provides a platform neutral interface to realtime audio streaming services in the form of a 'C' language API. PortAudio has been implemented for a number of platforms by wrapping native audio services - these implementations are publicly available under a BSD style Open Source license. PortAudio was selected as the audio component of a larger initiative called PortMusic that combines audio, MIDI, and audio file I/O. 2. The PortAudio Architecture The PortAudio architecture includes two main abstractions: Audio Devices and Audio Streams. Audio devices represent audio input and/or output ports on the host platform. The PortAudio API provides functions for enumerating available devices and querying them for properties such as available sampling rates, number of supported channels and supported sample formats. Audio streams manage active audio input and output through at most one input device and one output device - streams may be full duplex or half duplex. A PortAudio implementation manages buffers internally and requests audio processing from the client application via a callback that is associated with a stream when it is opened. A variety of sample formats are supported by PortAudio including 16 and 32 bit integer and 32 bit floating point. Where necessary PortAudio manages conversion between the requested buffer formats and those available natively. If requested, PortAudio can clamp out of range samples and/or dither samples to a native format. 3. API Overview This section presents an informal overview of the C language functions and structures that make up the PortAudio
Top of page Top of page