18 PAIO::PAIO(
unsigned sr,
unsigned bs,
int in_stream,
int out_stream,
unsigned in_chans,
unsigned out_chans)
19 :
IO(sr, bs, in_stream, out_stream, in_chans, out_chans) {
22 this->
initialize(sr, bs, in_stream, out_stream, in_chans, out_chans);
27 logMsg(
"PAIO::destructor");
41 static int pa_callback (
const void * inputPointer,
void * outputPointer,
42 unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *outTime,
43 PaStreamCallbackFlags statusFlags,
void * userData) {
45 sample * out = (
float *) outputPointer;
74 throw IOError(
"Portaudio error");
105 if (err != paNoError) {
107 logMsg(
"Error opening PortAudio: %s", Pa_GetErrorText(err ));
109 throw IOError(
"Error opening PortAudio");
131 if (err != paNoError)
148 if (err != paNoError)
165 if (err != paNoError)
186 }
catch (CException ex) {
195 void PAIO::initialize(
unsigned sr,
unsigned bs,
int is,
int os,
unsigned ic,
unsigned oc) {
196 const PaDeviceInfo *pdi;
215 is = (int)Pa_GetDefaultInputDevice();
217 os = (int)Pa_GetDefaultOutputDevice();
229 PaDeviceIndex numDevices = Pa_GetDeviceCount();
233 for (
int i = 0; i < numDevices; i++) {
234 pdi = Pa_GetDeviceInfo(i);
236 pdi->maxInputChannels, pdi->maxOutputChannels,
237 (i == (
int)Pa_GetDefaultInputDevice()), (i == (
int)Pa_GetDefaultOutputDevice()));
238 devPtr->
mFrameRates.push_back(pdi->defaultSampleRate);
275 for (
unsigned i = 0; i <
mDevices.size(); i++) {
void logMsg(const char *format,...)
These are the public logging messages.
long mTimeSum
for printing run-time statistics
unsigned mNumFrames
num frames used in each buffer
bool mAreBuffersAllocated
are the buffers allocated?
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
void handleError(PaError result)
print the error message
PaStream * mStream
the PortAudio stream we play out/get data from
void pullInput(Buffer &outBuffer, SampleBuffer out=0)
get a buffer from the CSL graph
void start()
start the callbacks
void test()
test the IO's graph
static unsigned numOutChannels()
default number of output channels
void stop()
stop the callbacks
PaDeviceIndex mOutDev
IO device numbers.
static void setNumOutChannels(unsigned numChannels)
virtual void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
void freeBuffers()
fcn to free them
static void setNumInChannels(unsigned numChannels)
void setSize(unsigned numChannels, unsigned numFrames)
UnitGenerator * mGraph
the root of my client DSP graph, often a mixer or panner
PaStreamParameters * mOutputParameters
static unsigned blockSize()
the default block size
float sample
(could be changed to int, or double)
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
static unsigned frameRate()
default frame rate
static void setBlockSize(unsigned blockSize)
static unsigned numInChannels()
default number of input channels
static int pa_callback(const void *inputPointer, void *outputPointer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *outTime, PaStreamCallbackFlags statusFlags, void *userData)
static void setFrameRate(unsigned frameRate)
unsigned mNumFramesPlayed
counter of frames I've played
vector< float > mFrameRates
the vector of frame rates I support
unsigned * mChannelMap
the output channel remapping array
unsigned mNumOutChannels
outputs
IO_Status mStatus
status flag
unsigned mNumRealOutChannels
physical outputs
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Buffer mOutputBuffer
the output buffer I use (passed to nextBuffer calls)
unsigned mNumRealInChannels
physical inputs
Buffer mInputBuffer
the most recent input buffer (if it's turned on)
unsigned mNumInChannels
inputs
PAIO(unsigned s_rate=CSL_mFrameRate, unsigned b_size=CSL_mBlockSize, int in_device=-1, int out_device=-1, unsigned in_chans=0, unsigned out_chans=2)
void allocateBuffers()
fcn to malloc storage buffers
SampleBuffer mInputPointer
the buffer for holding the sound card input (if open)
IO Device class – a holder for a sound interface with name, id, # IO channels, etc.
PaStreamParameters * mInputParameters
PA IO stream parameters.
void initialize(unsigned sr, unsigned bs, int is, int os, unsigned ic, unsigned oc)
Actually initialize PortAudio driver.
Base class of CSL exceptions (written upper-case). Has a string message.