Note: this page has not been reviewed, and may contain errors.

Configuring and Compiling PortAudio

You can build PortAudio in Linux Environments using the standard configure/make tools:

./configure && make

That will build PortAudio using Jack, ALSA and OSS in whatever combination they are found on your system. For example, if you have Jack and OSS but not ALSA, it will build using Jack and OSS but not ALSA. This step also builds a number of tests, which can be found in the bin directory of PortAudio. It's a good idea to run some of these tests to make sure PortAudio is working correctly.

Using PortAudio in your Projects

To use PortAudio in your apps, you can simply install the .so files:

make install

Projects built this way will expect PortAudio to be installed on target systems in order to run. If you want to build a more self-contained binary, you may use the libportaudio.a file:

cp lib/.libs/libportaudio.a /YOUR/PROJECT/DIR

You may also need to copy portaudio.h, located in the include/ directory of PortAudio into your project. Note that you will usually need to link with the approriate libraries that you used, such as ALSA and JACK, as well as with librt and libpthread. For example:

gcc -lrt -lasound -ljack -lpthread -o YOUR_BINARY main.c libportaudio.a

Linux Extensions

Note that the ALSA PortAudio back-end adds a few extensions to the standard API that you may take advantage of. To use these functions be sure to include the pa_linux_alsa.h file found in the include file in the PortAudio folder. This file contains further documentation on the following functions:

PaAlsaStreamInfo/PaAlsa?_InitializeStreamInfo
Objects of the PaAlsaStreamInfo type may be used for the !hostApiSpecificStreamInfo attribute of a PaStreamParameters object, in order to specify the name of an ALSA device to open directly. Specify the device via PaAlsaStreamInfo.deviceString, after initializing the object with PaAlsa?_InitializeStreamInfo.
PaAlsa?_EnableRealtimeScheduling
PA ALSA supports real-time scheduling of the audio callback thread (using the FIFO pthread scheduling policy), via the extension PaAlsa?_EnableRealtimeScheduling. Call this on the stream before starting it with the enableScheduling parameter set to true or false, to enable or disable this behaviour respectively.
PaAlsa?_GetStreamInputCard
Use this function to get the ALSA-lib card index of the stream's input device.
PaAlsa?_GetStreamOutputCard
Use this function to get the ALSA-lib card index of the stream's output device.

Of particular importance is PaAlsa?_EnableRealtimeScheduling, which allows ALSA to run at a high priority to prevent ordinary processes on the system from preempting audio playback. Without this, low latency audio playback will be irregular and will contain frequent drop-outs.

Linux Debugging

Eliot Blennerhassett writes:

On linux build, use e.g. "libtool gdb bin/patest_sine" to debug that program. This is because on linux bin/patest_sine is a libtool shell script that wraps bin/.libs/patest_sine and allows it to find the appropriate libraries within the build tree.