PortAudio Tutorial

Opening a Stream using Defaults

The next step is to open a stream which is similar to opening a file. You can specify whether you want audio input and/or output, how many channels, the data format, sample rate, etc.

First declare a variable to receive the stream pointer:

PortAudioStream   *stream;
There are two calls for opening streams, Pa_OpenStream() and Pa_OpenDefaultStream(). Pa_OpenStream() takes extra  parameters which give you more control. You can normally just use Pa_OpenDefaultStream() which just calls Pa_OpenStream() with some reasonable default values.  Let's open a stream for stereo output, using floating point data, at 44100 Hz.
err = Pa_OpenDefaultStream(
    &stream,        /* passes back stream pointer */
    0,              /* no input channels */
    2,              /* stereo output */
    paFloat32,      /* 32 bit floating point output */
    44100,          /* sample rate */
    256,            /* frames per buffer */
    0,              /* number of buffers, if zero then use default minimum */
    patestCallback, /* specify our custom callback */
    &data );        /* pass our data through to callback */
If you want to use 16 bit integer data, pass paInt16 instead of paFloat32.
home | contents | previousnext