PortAudio 2.0

portaudio.h

Go to the documentation of this file.
00001 #ifndef PORTAUDIO_H
00002 #define PORTAUDIO_H
00003 /*
00004  * $Id$
00005  * PortAudio Portable Real-Time Audio Library
00006  * PortAudio API Header File
00007  * Latest version available at: http://www.portaudio.com/
00008  *
00009  * Copyright (c) 1999-2002 Ross Bencina and Phil Burk
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining
00012  * a copy of this software and associated documentation files
00013  * (the "Software"), to deal in the Software without restriction,
00014  * including without limitation the rights to use, copy, modify, merge,
00015  * publish, distribute, sublicense, and/or sell copies of the Software,
00016  * and to permit persons to whom the Software is furnished to do so,
00017  * subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be
00020  * included in all copies or substantial portions of the Software.
00021  *
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
00026  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00027  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00028  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00029  */
00030 
00031 /*
00032  * The text above constitutes the entire PortAudio license; however, 
00033  * the PortAudio community also makes the following non-binding requests:
00034  *
00035  * Any person wishing to distribute modifications to the Software is
00036  * requested to send the modifications to the original developer so that
00037  * they can be incorporated into the canonical version. It is also 
00038  * requested that these non-binding requests be included along with the 
00039  * license above.
00040  */
00041 
00048 #ifdef __cplusplus
00049 extern "C"
00050 {
00051 #endif /* __cplusplus */
00052 
00058 int Pa_GetVersion( void );
00059 
00067 const char* Pa_GetVersionText( void );
00068 
00081 #define paMakeVersionNumber(major, minor, subminor) \
00082     (((major)&0xFF)<<16 | ((minor)&0xFF)<<8 | ((subminor)&0xFF))
00083 
00084 
00090 typedef struct PaVersionInfo {
00091     int versionMajor;
00092     int versionMinor;
00093     int versionSubMinor;
00099     const char *versionControlRevision;
00101     const char *versionText;
00102 } PaVersionInfo;
00103     
00114 const PaVersionInfo* Pa_GetVersionInfo();
00115 
00116 
00121 typedef int PaError;
00122 typedef enum PaErrorCode
00123 {
00124     paNoError = 0,
00125 
00126     paNotInitialized = -10000,
00127     paUnanticipatedHostError,
00128     paInvalidChannelCount,
00129     paInvalidSampleRate,
00130     paInvalidDevice,
00131     paInvalidFlag,
00132     paSampleFormatNotSupported,
00133     paBadIODeviceCombination,
00134     paInsufficientMemory,
00135     paBufferTooBig,
00136     paBufferTooSmall,
00137     paNullCallback,
00138     paBadStreamPtr,
00139     paTimedOut,
00140     paInternalError,
00141     paDeviceUnavailable,
00142     paIncompatibleHostApiSpecificStreamInfo,
00143     paStreamIsStopped,
00144     paStreamIsNotStopped,
00145     paInputOverflowed,
00146     paOutputUnderflowed,
00147     paHostApiNotFound,
00148     paInvalidHostApi,
00149     paCanNotReadFromACallbackStream,
00150     paCanNotWriteToACallbackStream,
00151     paCanNotReadFromAnOutputOnlyStream,
00152     paCanNotWriteToAnInputOnlyStream,
00153     paIncompatibleStreamHostApi,
00154     paBadBufferPtr
00155 } PaErrorCode;
00156 
00157 
00161 const char *Pa_GetErrorText( PaError errorCode );
00162 
00163 
00183 PaError Pa_Initialize( void );
00184 
00185 
00202 PaError Pa_Terminate( void );
00203 
00204 
00205 
00212 typedef int PaDeviceIndex;
00213 
00214 
00220 #define paNoDevice ((PaDeviceIndex)-1)
00221 
00222 
00228 #define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2)
00229 
00230 
00231 /* Host API enumeration mechanism */
00232 
00238 typedef int PaHostApiIndex;
00239 
00240 
00250 PaHostApiIndex Pa_GetHostApiCount( void );
00251 
00252 
00261 PaHostApiIndex Pa_GetDefaultHostApi( void );
00262 
00263 
00275 typedef enum PaHostApiTypeId
00276 {
00277     paInDevelopment=0, /* use while developing support for a new host API */
00278     paDirectSound=1,
00279     paMME=2,
00280     paASIO=3,
00281     paSoundManager=4,
00282     paCoreAudio=5,
00283     paOSS=7,
00284     paALSA=8,
00285     paAL=9,
00286     paBeOS=10,
00287     paWDMKS=11,
00288     paJACK=12,
00289     paWASAPI=13,
00290     paAudioScienceHPI=14
00291 } PaHostApiTypeId;
00292 
00293 
00296 typedef struct PaHostApiInfo
00297 {
00299     int structVersion;
00301     PaHostApiTypeId type;
00303     const char *name;
00304 
00310     int deviceCount;
00311 
00316     PaDeviceIndex defaultInputDevice;
00317 
00322     PaDeviceIndex defaultOutputDevice;
00323     
00324 } PaHostApiInfo;
00325 
00326 
00340 const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi );
00341 
00342 
00358 PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type );
00359 
00360 
00382 PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi,
00383         int hostApiDeviceIndex );
00384 
00385 
00386 
00389 typedef struct PaHostErrorInfo{
00390     PaHostApiTypeId hostApiType;    
00391     long errorCode;                 
00392     const char *errorText;          
00393 }PaHostErrorInfo;
00394 
00395 
00409 const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void );
00410 
00411 
00412 
00413 /* Device enumeration and capabilities */
00414 
00422 PaDeviceIndex Pa_GetDeviceCount( void );
00423 
00424 
00431 PaDeviceIndex Pa_GetDefaultInputDevice( void );
00432 
00433 
00449 PaDeviceIndex Pa_GetDefaultOutputDevice( void );
00450 
00451 
00460 typedef double PaTime;
00461 
00462 
00484 typedef unsigned long PaSampleFormat;
00485 
00486 
00487 #define paFloat32        ((PaSampleFormat) 0x00000001) 
00488 #define paInt32          ((PaSampleFormat) 0x00000002) 
00489 #define paInt24          ((PaSampleFormat) 0x00000004) 
00490 #define paInt16          ((PaSampleFormat) 0x00000008) 
00491 #define paInt8           ((PaSampleFormat) 0x00000010) 
00492 #define paUInt8          ((PaSampleFormat) 0x00000020) 
00493 #define paCustomFormat   ((PaSampleFormat) 0x00010000) 
00495 #define paNonInterleaved ((PaSampleFormat) 0x80000000) 
00500 typedef struct PaDeviceInfo
00501 {
00502     int structVersion;  /* this is struct version 2 */
00503     const char *name;
00504     PaHostApiIndex hostApi; 
00506     int maxInputChannels;
00507     int maxOutputChannels;
00508 
00510     PaTime defaultLowInputLatency;
00511     PaTime defaultLowOutputLatency;
00513     PaTime defaultHighInputLatency;
00514     PaTime defaultHighOutputLatency;
00515 
00516     double defaultSampleRate;
00517 } PaDeviceInfo;
00518 
00519 
00533 const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device );
00534 
00535 
00538 typedef struct PaStreamParameters
00539 {
00546     PaDeviceIndex device;
00547     
00553     int channelCount;
00554 
00559     PaSampleFormat sampleFormat;
00560 
00572     PaTime suggestedLatency;
00573 
00579     void *hostApiSpecificStreamInfo;
00580 
00581 } PaStreamParameters;
00582 
00583 
00585 #define paFormatIsSupported (0)
00586 
00609 PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
00610                               const PaStreamParameters *outputParameters,
00611                               double sampleRate );
00612 
00613 
00614 
00615 /* Streaming types and functions */
00616 
00617 
00635 typedef void PaStream;
00636 
00637 
00642 #define paFramesPerBufferUnspecified  (0)
00643 
00644 
00653 typedef unsigned long PaStreamFlags;
00654 
00656 #define   paNoFlag          ((PaStreamFlags) 0)
00657 
00661 #define   paClipOff         ((PaStreamFlags) 0x00000001)
00662 
00666 #define   paDitherOff       ((PaStreamFlags) 0x00000002)
00667 
00677 #define   paNeverDropInput  ((PaStreamFlags) 0x00000004)
00678 
00685 #define   paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008)
00686 
00690 #define   paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000)
00691 
00699 typedef struct PaStreamCallbackTimeInfo{
00700     PaTime inputBufferAdcTime;  
00701     PaTime currentTime;         
00702     PaTime outputBufferDacTime; 
00703 } PaStreamCallbackTimeInfo;
00704 
00705 
00712 typedef unsigned long PaStreamCallbackFlags;
00713 
00721 #define paInputUnderflow   ((PaStreamCallbackFlags) 0x00000001)
00722 
00730 #define paInputOverflow    ((PaStreamCallbackFlags) 0x00000002)
00731 
00736 #define paOutputUnderflow  ((PaStreamCallbackFlags) 0x00000004)
00737 
00741 #define paOutputOverflow   ((PaStreamCallbackFlags) 0x00000008)
00742 
00747 #define paPrimingOutput    ((PaStreamCallbackFlags) 0x00000010)
00748 
00753 typedef enum PaStreamCallbackResult
00754 {
00755     paContinue=0,   
00756     paComplete=1,   
00757     paAbort=2       
00758 } PaStreamCallbackResult;
00759 
00760 
00830 typedef int PaStreamCallback(
00831     const void *input, void *output,
00832     unsigned long frameCount,
00833     const PaStreamCallbackTimeInfo* timeInfo,
00834     PaStreamCallbackFlags statusFlags,
00835     void *userData );
00836 
00837 
00892 PaError Pa_OpenStream( PaStream** stream,
00893                        const PaStreamParameters *inputParameters,
00894                        const PaStreamParameters *outputParameters,
00895                        double sampleRate,
00896                        unsigned long framesPerBuffer,
00897                        PaStreamFlags streamFlags,
00898                        PaStreamCallback *streamCallback,
00899                        void *userData );
00900 
00901 
00932 PaError Pa_OpenDefaultStream( PaStream** stream,
00933                               int numInputChannels,
00934                               int numOutputChannels,
00935                               PaSampleFormat sampleFormat,
00936                               double sampleRate,
00937                               unsigned long framesPerBuffer,
00938                               PaStreamCallback *streamCallback,
00939                               void *userData );
00940 
00941 
00945 PaError Pa_CloseStream( PaStream *stream );
00946 
00947 
00962 typedef void PaStreamFinishedCallback( void *userData );
00963 
00964 
00983 PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback ); 
00984 
00985 
00988 PaError Pa_StartStream( PaStream *stream );
00989 
00990 
00994 PaError Pa_StopStream( PaStream *stream );
00995 
00996 
01000 PaError Pa_AbortStream( PaStream *stream );
01001 
01002 
01015 PaError Pa_IsStreamStopped( PaStream *stream );
01016 
01017 
01031 PaError Pa_IsStreamActive( PaStream *stream );
01032 
01033 
01034 
01039 typedef struct PaStreamInfo
01040 {
01042     int structVersion;
01043 
01050     PaTime inputLatency;
01051 
01058     PaTime outputLatency;
01059 
01067     double sampleRate;
01068     
01069 } PaStreamInfo;
01070 
01071 
01085 const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream );
01086 
01087 
01103 PaTime Pa_GetStreamTime( PaStream *stream );
01104 
01105 
01122 double Pa_GetStreamCpuLoad( PaStream* stream );
01123 
01124 
01146 PaError Pa_ReadStream( PaStream* stream,
01147                        void *buffer,
01148                        unsigned long frames );
01149 
01150 
01173 PaError Pa_WriteStream( PaStream* stream,
01174                         const void *buffer,
01175                         unsigned long frames );
01176 
01177 
01186 signed long Pa_GetStreamReadAvailable( PaStream* stream );
01187 
01188 
01197 signed long Pa_GetStreamWriteAvailable( PaStream* stream );
01198 
01199 
01200 /* Miscellaneous utilities */
01201 
01202 
01208 PaError Pa_GetSampleSize( PaSampleFormat format );
01209 
01210 
01218 void Pa_Sleep( long msec );
01219 
01220 
01221 
01222 #ifdef __cplusplus
01223 }
01224 #endif /* __cplusplus */
01225 #endif /* PORTAUDIO_H */