portaudio.h

00001 #ifndef PORT_AUDIO_H
00002 #define PORT_AUDIO_H
00003 
00004 #ifdef __cplusplus
00005 extern "C"
00006 {
00007 #endif /* __cplusplus */
00008 
00009 /*
00010  * $Id: portaudio.h 94 2003-05-13 10:54:17Z rene-cvs $
00011  * PortAudio Portable Real-Time Audio Library
00012  * PortAudio API Header File
00013  * Latest version available at: http://www.audiomulch.com/portaudio/
00014  *
00015  * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
00016  *
00017  * Permission is hereby granted, free of charge, to any person obtaining
00018  * a copy of this software and associated documentation files
00019  * (the "Software"), to deal in the Software without restriction,
00020  * including without limitation the rights to use, copy, modify, merge,
00021  * publish, distribute, sublicense, and/or sell copies of the Software,
00022  * and to permit persons to whom the Software is furnished to do so,
00023  * subject to the following conditions:
00024  *
00025  * The above copyright notice and this permission notice shall be
00026  * included in all copies or substantial portions of the Software.
00027  *
00028  * Any person wishing to distribute modifications to the Software is
00029  * requested to send the modifications to the original developer so that
00030  * they can be incorporated into the canonical version.
00031  *
00032  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00035  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
00036  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00037  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 typedef int PaError;
00043 typedef enum {
00044     paNoError = 0,
00045 
00046     paHostError = -10000,
00047     paInvalidChannelCount,
00048     paInvalidSampleRate,
00049     paInvalidDeviceId,
00050     paInvalidFlag,
00051     paSampleFormatNotSupported,
00052     paBadIODeviceCombination,
00053     paInsufficientMemory,
00054     paBufferTooBig,
00055     paBufferTooSmall,
00056     paNullCallback,
00057     paBadStreamPtr,
00058     paTimedOut,
00059     paInternalError,
00060     paDeviceUnavailable
00061 } PaErrorNum;
00062 
00063 /*
00064  Pa_Initialize() is the library initialisation function - call this before
00065  using the library.
00066 
00067 */
00068 
00069 PaError Pa_Initialize( void );
00070 
00071 /*
00072  Pa_Terminate() is the library termination function - call this after
00073  using the library.
00074 
00075 */
00076 
00077 PaError Pa_Terminate( void );
00078 
00079 /*
00080  Pa_GetHostError() returns a host specific error code.
00081  This can be called after receiving a PortAudio error code of paHostError.
00082 
00083 */
00084 
00085 long Pa_GetHostError( void );
00086 
00087 /*
00088  Pa_GetErrorText() translates the supplied PortAudio error number
00089  into a human readable message.
00090  
00091 */
00092 
00093 const char *Pa_GetErrorText( PaError errnum );
00094 
00095 /*
00096  Sample formats
00097  
00098  These are formats used to pass sound data between the callback and the
00099  stream. Each device has a "native" format which may be used when optimum
00100  efficiency or control over conversion is required.
00101  
00102  Formats marked "always available" are supported (emulated) by all 
00103  PortAudio implementations.
00104  
00105  The floating point representation (paFloat32) uses +1.0 and -1.0 as the 
00106  maximum and minimum respectively.
00107 
00108  paUInt8 is an unsigned 8 bit format where 128 is considered "ground"
00109 
00110 */
00111 
00112 typedef unsigned long PaSampleFormat;
00113 #define paFloat32      ((PaSampleFormat) (1<<0)) /*always available*/
00114 #define paInt16        ((PaSampleFormat) (1<<1)) /*always available*/
00115 #define paInt32        ((PaSampleFormat) (1<<2)) /*always available*/
00116 #define paInt24        ((PaSampleFormat) (1<<3))
00117 #define paPackedInt24  ((PaSampleFormat) (1<<4))
00118 #define paInt8         ((PaSampleFormat) (1<<5))
00119 #define paUInt8        ((PaSampleFormat) (1<<6))
00120 #define paCustomFormat ((PaSampleFormat) (1<<16))
00121 
00122 /*
00123  Device enumeration mechanism.
00124  
00125  Device ids range from 0 to Pa_CountDevices()-1.
00126  
00127  Devices may support input, output or both.
00128 
00129 */
00130 
00131 typedef int PaDeviceID;
00132 #define paNoDevice -1
00133 
00134 int Pa_CountDevices( void );
00135 
00136 typedef struct
00137 {
00138     int structVersion;
00139     const char *name;
00140     int maxInputChannels;
00141     int maxOutputChannels;
00142     /* Number of discrete rates, or -1 if range supported. */
00143     int numSampleRates;
00144     /* Array of supported sample rates, or {min,max} if range supported. */
00145     const double *sampleRates;
00146     PaSampleFormat nativeSampleFormats;
00147 }
00148 PaDeviceInfo;
00149 
00150 /*
00151  Pa_GetDefaultInputDeviceID(), Pa_GetDefaultOutputDeviceID() return the
00152  default device ids for input and output respectively, or paNoDevice if
00153  no device is available.
00154  The result can be passed to Pa_OpenStream().
00155  
00156  On the PC, the user can specify a default device by
00157  setting an environment variable. For example, to use device #1.
00158  
00159   set PA_RECOMMENDED_OUTPUT_DEVICE=1
00160  
00161  The user should first determine the available device ids by using
00162  the supplied application "pa_devs".
00163 
00164 */
00165 
00166 PaDeviceID Pa_GetDefaultInputDeviceID( void );
00167 PaDeviceID Pa_GetDefaultOutputDeviceID( void );
00168 
00169 
00170 
00171 /*
00172  Pa_GetDeviceInfo() returns a pointer to an immutable PaDeviceInfo structure
00173  for the device specified.
00174  If the device parameter is out of range the function returns NULL.
00175 
00176  PortAudio manages the memory referenced by the returned pointer, the client
00177  must not manipulate or free the memory. The pointer is only guaranteed to be
00178  valid between calls to Pa_Initialize() and Pa_Terminate().
00179 
00180 */
00181 
00182 const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID device );
00183 
00184 /*
00185  PaTimestamp is used to represent a continuous sample clock with arbitrary
00186  start time that can be used for syncronization. The type is used for the
00187  outTime argument to the PortAudioCallback and as the result of Pa_StreamTime()
00188 
00189 */
00190 
00191 typedef double PaTimestamp;
00192 
00193 /*
00194  PortAudioCallback is implemented by PortAudio clients.
00195  
00196  inputBuffer and outputBuffer are arrays of interleaved samples,
00197  the format, packing and number of channels used by the buffers are
00198  determined by parameters to Pa_OpenStream() (see below).
00199  
00200  framesPerBuffer is the number of sample frames to be processed by the callback.
00201  
00202  outTime is the time in samples when the buffer(s) processed by
00203  this callback will begin being played at the audio output.
00204  See also Pa_StreamTime()
00205  
00206  userData is the value of a user supplied pointer passed to Pa_OpenStream()
00207  intended for storing synthesis data etc.
00208  
00209  return value:
00210  The callback can return a non-zero value to stop the stream. This may be
00211  useful in applications such as soundfile players where a specific duration
00212  of output is required. However, it is not necessary to utilise this mechanism
00213  as StopStream() will also terminate the stream. A callback returning a
00214  non-zero value must fill the entire outputBuffer.
00215  
00216  NOTE: None of the other stream functions may be called from within the
00217  callback function except for Pa_GetCPULoad().
00218 
00219 */
00220 
00221 typedef int (PortAudioCallback)(
00222     void *inputBuffer, void *outputBuffer,
00223     unsigned long framesPerBuffer,
00224     PaTimestamp outTime, void *userData );
00225 
00226 
00227 /*
00228  Stream flags
00229  
00230  These flags may be supplied (ored together) in the streamFlags argument to
00231  the Pa_OpenStream() function.
00232 
00233 */
00234 
00235 #define   paNoFlag      (0)
00236 #define   paClipOff     (1<<0)   /* disable default clipping of out of range samples */
00237 #define   paDitherOff   (1<<1)   /* disable default dithering */
00238 #define   paPlatformSpecificFlags (0x00010000)
00239 typedef   unsigned long PaStreamFlags;
00240 
00241 /*
00242  A single PortAudioStream provides multiple channels of real-time
00243  input and output audio streaming to a client application.
00244  Pointers to PortAudioStream objects are passed between PortAudio functions.
00245 */
00246 
00247 typedef void PortAudioStream;
00248 #define PaStream PortAudioStream
00249 
00250 /*
00251  Pa_OpenStream() opens a stream for either input, output or both.
00252  
00253  stream is the address of a PortAudioStream pointer which will receive
00254  a pointer to the newly opened stream.
00255  
00256  inputDevice is the id of the device used for input (see PaDeviceID above.)
00257  inputDevice may be paNoDevice to indicate that an input device is not required.
00258  
00259  numInputChannels is the number of channels of sound to be delivered to the
00260  callback. It can range from 1 to the value of maxInputChannels in the
00261  PaDeviceInfo record for the device specified by the inputDevice parameter.
00262  If inputDevice is paNoDevice numInputChannels is ignored.
00263  
00264  inputSampleFormat is the sample format of inputBuffer provided to the callback
00265  function. inputSampleFormat may be any of the formats described by the
00266  PaSampleFormat enumeration (see above). PortAudio guarantees support for
00267  the device's native formats (nativeSampleFormats in the device info record)
00268  and additionally 16 and 32 bit integer and 32 bit floating point formats.
00269  Support for other formats is implementation defined.
00270  
00271  inputDriverInfo is a pointer to an optional driver specific data structure
00272  containing additional information for device setup or stream processing.
00273  inputDriverInfo is never required for correct operation. If not used
00274  inputDriverInfo should be NULL.
00275  
00276  outputDevice is the id of the device used for output (see PaDeviceID above.)
00277  outputDevice may be paNoDevice to indicate that an output device is not required.
00278  
00279  numOutputChannels is the number of channels of sound to be supplied by the
00280  callback. See the definition of numInputChannels above for more details.
00281  
00282  outputSampleFormat is the sample format of the outputBuffer filled by the
00283  callback function. See the definition of inputSampleFormat above for more
00284  details.
00285  
00286  outputDriverInfo is a pointer to an optional driver specific data structure
00287  containing additional information for device setup or stream processing.
00288  outputDriverInfo is never required for correct operation. If not used
00289  outputDriverInfo should be NULL.
00290  
00291  sampleRate is the desired sampleRate. For full-duplex streams it is the
00292  sample rate for both input and output
00293  
00294  framesPerBuffer is the length in sample frames of all internal sample buffers
00295  used for communication with platform specific audio routines. Wherever
00296  possible this corresponds to the framesPerBuffer parameter passed to the
00297  callback function.
00298  
00299  numberOfBuffers is the number of buffers used for multibuffered communication
00300  with the platform specific audio routines. If you pass zero, then an optimum
00301  value will be chosen for you internally. This parameter is provided only
00302  as a guide - and does not imply that an implementation must use multibuffered
00303  i/o when reliable double buffering is available (such as SndPlayDoubleBuffer()
00304  on the Macintosh.)
00305  
00306  streamFlags may contain a combination of flags ORed together.
00307  These flags modify the behaviour of the streaming process. Some flags may only
00308  be relevant to certain buffer formats.
00309  
00310  callback is a pointer to a client supplied function that is responsible
00311  for processing and filling input and output buffers (see above for details.)
00312  
00313  userData is a client supplied pointer which is passed to the callback
00314  function. It could for example, contain a pointer to instance data necessary
00315  for processing the audio buffers.
00316  
00317  return value:
00318  Upon success Pa_OpenStream() returns PaNoError and places a pointer to a
00319  valid PortAudioStream in the stream argument. The stream is inactive (stopped).
00320  If a call to Pa_OpenStream() fails a non-zero error code is returned (see
00321  PaError above) and the value of stream is invalid.
00322  
00323 */
00324 
00325 PaError Pa_OpenStream( PortAudioStream** stream,
00326                        PaDeviceID inputDevice,
00327                        int numInputChannels,
00328                        PaSampleFormat inputSampleFormat,
00329                        void *inputDriverInfo,
00330                        PaDeviceID outputDevice,
00331                        int numOutputChannels,
00332                        PaSampleFormat outputSampleFormat,
00333                        void *outputDriverInfo,
00334                        double sampleRate,
00335                        unsigned long framesPerBuffer,
00336                        unsigned long numberOfBuffers,
00337                        PaStreamFlags streamFlags,
00338                        PortAudioCallback *callback,
00339                        void *userData );
00340 
00341 
00342 /*
00343  Pa_OpenDefaultStream() is a simplified version of Pa_OpenStream() that opens
00344  the default input and/or output devices. Most parameters have identical meaning
00345  to their Pa_OpenStream() counterparts, with the following exceptions:
00346  
00347  If either numInputChannels or numOutputChannels is 0 the respective device
00348  is not opened. This has the same effect as passing paNoDevice in the device
00349  arguments to Pa_OpenStream().
00350  
00351  sampleFormat applies to both the input and output buffers.
00352 
00353 */
00354 
00355 PaError Pa_OpenDefaultStream( PortAudioStream** stream,
00356                               int numInputChannels,
00357                               int numOutputChannels,
00358                               PaSampleFormat sampleFormat,
00359                               double sampleRate,
00360                               unsigned long framesPerBuffer,
00361                               unsigned long numberOfBuffers,
00362                               PortAudioCallback *callback,
00363                               void *userData );
00364 
00365 /*
00366  Pa_CloseStream() closes an audio stream, flushing any pending buffers.
00367 
00368 */
00369 
00370 PaError Pa_CloseStream( PortAudioStream* );
00371 
00372 /*
00373  Pa_StartStream() and Pa_StopStream() begin and terminate audio processing.
00374  Pa_StopStream() waits until all pending audio buffers have been played.
00375  Pa_AbortStream() stops playing immediately without waiting for pending
00376  buffers to complete.
00377     
00378 */
00379 
00380 PaError Pa_StartStream( PortAudioStream *stream );
00381 
00382 PaError Pa_StopStream( PortAudioStream *stream );
00383 
00384 PaError Pa_AbortStream( PortAudioStream *stream );
00385 
00386 /*
00387  Pa_StreamActive() returns one (1) when the stream is active (ie playing
00388  or recording audio), zero (0) when not playing, or a negative error number
00389  if the stream is invalid.
00390  The stream is active between calls to Pa_StartStream() and Pa_StopStream(),
00391  but may also become inactive if the callback returns a non-zero value.
00392  In the latter case, the stream is considered inactive after the last
00393  buffer has finished playing.
00394  
00395 */
00396 
00397 PaError Pa_StreamActive( PortAudioStream *stream );
00398 
00399 /*
00400  Pa_StreamTime() returns the current output time in samples for the stream.
00401  This time may be used as a time reference (for example synchronizing audio to
00402  MIDI).
00403  
00404 */
00405 
00406 PaTimestamp Pa_StreamTime( PortAudioStream *stream );
00407 
00408 /*
00409  Pa_GetCPULoad() returns the CPU Load for the stream.
00410  The "CPU Load" is a fraction of total CPU time consumed by the stream's
00411  audio processing routines including, but not limited to the client supplied
00412  callback.
00413  A value of 0.5 would imply that PortAudio and the sound generating
00414  callback was consuming roughly 50% of the available CPU time.
00415  This function may be called from the callback function or the application.
00416  
00417 */
00418 
00419 double Pa_GetCPULoad( PortAudioStream* stream );
00420 
00421 /*
00422  Pa_GetMinNumBuffers() returns the minimum number of buffers required by
00423  the current host based on minimum latency.
00424  On the PC, for the DirectSound implementation, latency can be optionally set
00425  by user by setting an environment variable.
00426  For example, to set latency to 200 msec, put:
00427  
00428     set PA_MIN_LATENCY_MSEC=200
00429  
00430  in the AUTOEXEC.BAT file and reboot.
00431  If the environment variable is not set, then the latency will be determined
00432  based on the OS. Windows NT has higher latency than Win95.
00433  
00434 */
00435 
00436 int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate );
00437 
00438 /*
00439  Pa_Sleep() puts the caller to sleep for at least 'msec' milliseconds.
00440  You may sleep longer than the requested time so don't rely on this for
00441  accurate musical timing.
00442  
00443  Pa_Sleep() is provided as a convenience for authors of portable code (such as
00444  the tests and examples in the PortAudio distribution.)
00445  
00446 */
00447 
00448 void Pa_Sleep( long msec );
00449 
00450 /*
00451  Pa_GetSampleSize() returns the size in bytes of a single sample in the
00452  supplied PaSampleFormat, or paSampleFormatNotSupported if the format is
00453  no supported.
00454   
00455 */
00456 
00457 PaError Pa_GetSampleSize( PaSampleFormat format );
00458 
00459 
00460 #ifdef __cplusplus
00461 }
00462 #endif /* __cplusplus */
00463 #endif /* PORT_AUDIO_H */

Generated on Mon Jun 5 10:20:43 2006 for Intelligence.kdevelop by  doxygen 1.4.6