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