# PortAudio Tutorial

## Overview of PortAudio

> PortAudio is a library that provides streaming audio input and output. It is a cross-platform API (Application Programming Interface) that works on Windows, Macintosh, Unix running OSS, SGI, BeOS, and perhaps other platforms by the time you read this. This means that you can write a simple 'C' program to process or generate an audio signal, and that program can run on several different types of computer just by recompiling the source code.

> Here are the steps to writing a PortAudio application:

> 1. Write a callback function that will be called by PortAudio when audio processing is needed.
> 2. Initialize the PA library and open a stream for audio I/O.
> 3. Start the stream. Your callback function will be now be called repeatedly by PA in the background.
> 4. In your callback you can read audio data from the inputBuffer and/or write data to the outputBuffer.
> 5. Stop the stream by returning 1 from your callback, or by calling a stop function.
> 6. Close the stream and terminate the library.

> There is also another interface provided that allows you to generate audio in the foreground. You then simply write data to the stream and the tool will not return until it is ready to accept more data. This interface is simpler to use but is usually not preferred for large applications because it requires that you launch a thread to perform the synthesis. Launching a thread may be difficult on non-multi-tasking systems such as the Macintosh prior to MacOS X.

> Let's continue by building a simple application that will play a sawtooth wave.

> Please select the page for the specific implementation you would like to use:

> - Windows (WMME or DirectSound)
> - Macintosh SoundManager for OS 7,8,9
> - Macintosh CoreAudio for OS X
> - ASIO on Windows or Macintosh
> - Unix OSS
> or continue with the next page of the programming tutorial.

home | contents | previous