PortAudio

From EMC Electronic Music Coders
Jump to navigation Jump to search

PortAudio Tutorials[edit]

These tutorials takes you through a hands-on example of using PortAudio to make sound. If you'd prefer to start with a top-down overview of the PortAudio API, check out the PortAudio API Overview

Downloading[edit]

Compiling[edit]

Once you've downloaded PortAudio you'll need to compile it, which of course, depends on your environment:

Windows[edit]

Mac OS X[edit]

POSIX[edit]

You can also use CMake to generate project files for PortAudio on Windows, OS X or Linux or include PortAudio easily in your own CMake project. See PortAudio on Windows, OS X or Linux via. CMake.

Many platforms with GCC/make can use the simple ./configure && make combination and simply use the resulting libraries in their code.

Programming with PortAudio[edit]

Below are the steps to writing a PortAudio application using the callback technique:

  • Write a callback function that will be called by PortAudio when audio processing is needed.
  • Initialize the PA library and open a stream for audio I/O.
  • Start the stream. Your callback function will be now be called repeatedly by PA in the background.
  • In your callback you can read audio data from the inputBuffer and/or write data to the outputBuffer.
  • Stop the stream by returning 1 from your callback, or by calling a stop function.
  • Close the stream and terminate the library.
  • In addition to this "Callback" architecture, V19 also supports a "Blocking I/O" model which uses read and write calls which may be more familiar to non-audio programmers. Note that at this time, not all APIs support this functionality.
  • In this tutorial, we'll show how to use the callback architecture to play a sawtooth wave. Much of the tutorial is taken from the file Play a simple (aliasing) sawtooth wave, which is part of the PortAudio distribution.
  • When you're done with this tutorial, you'll be armed with the basic knowledge you need to write an audio program. If you need more sample code, look in the "examples" and "test" directory of the PortAudio distribution.

Programming Tutorial Contents[edit]