PortAudio  2.0
portaudio.h
Go to the documentation of this file.
1 #ifndef PORTAUDIO_H
2 #define PORTAUDIO_H
3 /*
4  * $Id$
5  * PortAudio Portable Real-Time Audio Library
6  * PortAudio API Header File
7  * Latest version available at: http://www.portaudio.com/
8  *
9  * Copyright (c) 1999-2002 Ross Bencina and Phil Burk
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files
13  * (the "Software"), to deal in the Software without restriction,
14  * including without limitation the rights to use, copy, modify, merge,
15  * publish, distribute, sublicense, and/or sell copies of the Software,
16  * and to permit persons to whom the Software is furnished to do so,
17  * subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
26  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  */
30 
31 /*
32  * The text above constitutes the entire PortAudio license; however,
33  * the PortAudio community also makes the following non-binding requests:
34  *
35  * Any person wishing to distribute modifications to the Software is
36  * requested to send the modifications to the original developer so that
37  * they can be incorporated into the canonical version. It is also
38  * requested that these non-binding requests be included along with the
39  * license above.
40  */
41 
48 #ifdef __cplusplus
49 extern "C"
50 {
51 #endif /* __cplusplus */
52 
58 int Pa_GetVersion( void );
59 
67 const char* Pa_GetVersionText( void );
68 
81 #define paMakeVersionNumber(major, minor, subminor) \
82  (((major)&0xFF)<<16 | ((minor)&0xFF)<<8 | ((subminor)&0xFF))
83 
84 
90 typedef struct PaVersionInfo {
91  int versionMajor;
92  int versionMinor;
93  int versionSubMinor;
101  const char *versionText;
102 } PaVersionInfo;
103 
114 const PaVersionInfo* Pa_GetVersionInfo( void );
115 
116 
121 typedef int PaError;
122 typedef enum PaErrorCode
123 {
124  paNoError = 0,
125 
126  paNotInitialized = -10000,
127  paUnanticipatedHostError,
128  paInvalidChannelCount,
129  paInvalidSampleRate,
130  paInvalidDevice,
131  paInvalidFlag,
132  paSampleFormatNotSupported,
133  paBadIODeviceCombination,
134  paInsufficientMemory,
135  paBufferTooBig,
136  paBufferTooSmall,
137  paNullCallback,
138  paBadStreamPtr,
139  paTimedOut,
140  paInternalError,
141  paDeviceUnavailable,
142  paIncompatibleHostApiSpecificStreamInfo,
143  paStreamIsStopped,
144  paStreamIsNotStopped,
145  paInputOverflowed,
146  paOutputUnderflowed,
147  paHostApiNotFound,
148  paInvalidHostApi,
149  paCanNotReadFromACallbackStream,
150  paCanNotWriteToACallbackStream,
151  paCanNotReadFromAnOutputOnlyStream,
152  paCanNotWriteToAnInputOnlyStream,
153  paIncompatibleStreamHostApi,
154  paBadBufferPtr,
155  paCanNotInitializeRecursively
156 } PaErrorCode;
157 
158 
162 const char *Pa_GetErrorText( PaError errorCode );
163 
164 
184 PaError Pa_Initialize( void );
185 
186 
203 PaError Pa_Terminate( void );
204 
205 
206 
213 typedef int PaDeviceIndex;
214 
215 
221 #define paNoDevice ((PaDeviceIndex)-1)
222 
223 
229 #define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2)
230 
231 
232 /* Host API enumeration mechanism */
233 
239 typedef int PaHostApiIndex;
240 
241 
251 PaHostApiIndex Pa_GetHostApiCount( void );
252 
253 
262 PaHostApiIndex Pa_GetDefaultHostApi( void );
263 
264 
276 typedef enum PaHostApiTypeId
277 {
278  paInDevelopment=0, /* use while developing support for a new host API */
279  paDirectSound=1,
280  paMME=2,
281  paASIO=3,
282  paSoundManager=4,
283  paCoreAudio=5,
284  paOSS=7,
285  paALSA=8,
286  paAL=9,
287  paBeOS=10,
288  paWDMKS=11,
289  paJACK=12,
290  paWASAPI=13,
291  paAudioScienceHPI=14,
292  paAudioIO=15,
293  paPulseAudio=16,
294  paSndio=17
296 
297 
300 typedef struct PaHostApiInfo
301 {
307  const char *name;
308 
315 
320  PaDeviceIndex defaultInputDevice;
321 
326  PaDeviceIndex defaultOutputDevice;
327 
328 } PaHostApiInfo;
329 
330 
344 const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi );
345 
346 
362 PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type );
363 
364 
386 PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi,
387  int hostApiDeviceIndex );
388 
389 
390 
393 typedef struct PaHostErrorInfo{
395  long errorCode;
396  const char *errorText;
398 
399 
414 
415 
416 
417 /* Device enumeration and capabilities */
418 
426 PaDeviceIndex Pa_GetDeviceCount( void );
427 
428 
435 PaDeviceIndex Pa_GetDefaultInputDevice( void );
436 
437 
453 PaDeviceIndex Pa_GetDefaultOutputDevice( void );
454 
455 
464 typedef double PaTime;
465 
466 
488 typedef unsigned long PaSampleFormat;
489 
490 
491 #define paFloat32 ((PaSampleFormat) 0x00000001)
492 #define paInt32 ((PaSampleFormat) 0x00000002)
493 #define paInt24 ((PaSampleFormat) 0x00000004)
494 #define paInt16 ((PaSampleFormat) 0x00000008)
495 #define paInt8 ((PaSampleFormat) 0x00000010)
496 #define paUInt8 ((PaSampleFormat) 0x00000020)
497 #define paCustomFormat ((PaSampleFormat) 0x00010000)
499 #define paNonInterleaved ((PaSampleFormat) 0x80000000)
504 typedef struct PaDeviceInfo
505 {
506  int structVersion; /* this is struct version 2 */
507  const char *name;
508  PaHostApiIndex hostApi;
510  int maxInputChannels;
511  int maxOutputChannels;
512 
515  PaTime defaultLowOutputLatency;
518  PaTime defaultHighOutputLatency;
519 
520  double defaultSampleRate;
521 } PaDeviceInfo;
522 
523 
537 const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device );
538 
539 
542 typedef struct PaStreamParameters
543 {
550  PaDeviceIndex device;
551 
558 
563  PaSampleFormat sampleFormat;
564 
577 
584 
586 
587 
589 #define paFormatIsSupported (0)
590 
613 PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
614  const PaStreamParameters *outputParameters,
615  double sampleRate );
616 
617 
618 
619 /* Streaming types and functions */
620 
621 
639 typedef void PaStream;
640 
641 
646 #define paFramesPerBufferUnspecified (0)
647 
648 
657 typedef unsigned long PaStreamFlags;
658 
660 #define paNoFlag ((PaStreamFlags) 0)
661 
665 #define paClipOff ((PaStreamFlags) 0x00000001)
666 
670 #define paDitherOff ((PaStreamFlags) 0x00000002)
671 
681 #define paNeverDropInput ((PaStreamFlags) 0x00000004)
682 
689 #define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008)
690 
694 #define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000)
695 
705  PaTime currentTime;
708 
709 
716 typedef unsigned long PaStreamCallbackFlags;
717 
725 #define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001)
726 
734 #define paInputOverflow ((PaStreamCallbackFlags) 0x00000002)
735 
740 #define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004)
741 
745 #define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008)
746 
751 #define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010)
752 
758 {
763 
764 
834 typedef int PaStreamCallback(
835  const void *input, void *output,
836  unsigned long frameCount,
837  const PaStreamCallbackTimeInfo* timeInfo,
838  PaStreamCallbackFlags statusFlags,
839  void *userData );
840 
841 
899 PaError Pa_OpenStream( PaStream** stream,
900  const PaStreamParameters *inputParameters,
901  const PaStreamParameters *outputParameters,
902  double sampleRate,
903  unsigned long framesPerBuffer,
904  PaStreamFlags streamFlags,
905  PaStreamCallback *streamCallback,
906  void *userData );
907 
908 
939 PaError Pa_OpenDefaultStream( PaStream** stream,
940  int numInputChannels,
941  int numOutputChannels,
942  PaSampleFormat sampleFormat,
943  double sampleRate,
944  unsigned long framesPerBuffer,
945  PaStreamCallback *streamCallback,
946  void *userData );
947 
948 
952 PaError Pa_CloseStream( PaStream *stream );
953 
954 
969 typedef void PaStreamFinishedCallback( void *userData );
970 
971 
990 PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback );
991 
992 
995 PaError Pa_StartStream( PaStream *stream );
996 
997 
1001 PaError Pa_StopStream( PaStream *stream );
1002 
1003 
1007 PaError Pa_AbortStream( PaStream *stream );
1008 
1009 
1022 PaError Pa_IsStreamStopped( PaStream *stream );
1023 
1024 
1038 PaError Pa_IsStreamActive( PaStream *stream );
1039 
1040 
1041 
1046 typedef struct PaStreamInfo
1047 {
1050 
1058 
1066 
1074  double sampleRate;
1075 
1076 } PaStreamInfo;
1077 
1078 
1092 const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream );
1093 
1094 
1110 PaTime Pa_GetStreamTime( PaStream *stream );
1111 
1112 
1129 double Pa_GetStreamCpuLoad( PaStream* stream );
1130 
1131 
1157 PaError Pa_ReadStream( PaStream* stream,
1158  void *buffer,
1159  unsigned long frames );
1160 
1161 
1188 PaError Pa_WriteStream( PaStream* stream,
1189  const void *buffer,
1190  unsigned long frames );
1191 
1192 
1204 signed long Pa_GetStreamReadAvailable( PaStream* stream );
1205 
1206 
1218 signed long Pa_GetStreamWriteAvailable( PaStream* stream );
1219 
1220 
1221 /* Miscellaneous utilities */
1222 
1223 
1229 PaError Pa_GetSampleSize( PaSampleFormat format );
1230 
1231 
1239 void Pa_Sleep( long msec );
1240 
1241 
1242 
1243 #ifdef __cplusplus
1244 }
1245 #endif /* __cplusplus */
1246 #endif /* PORTAUDIO_H */
PaError Pa_Initialize(void)
struct PaDeviceInfo PaDeviceInfo
int structVersion
Definition: portaudio.h:303
PaTime defaultHighInputLatency
Definition: portaudio.h:517
int PaHostApiIndex
Definition: portaudio.h:239
PaDeviceIndex Pa_GetDefaultInputDevice(void)
PaDeviceIndex Pa_GetDeviceCount(void)
PaHostApiTypeId type
Definition: portaudio.h:305
struct PaStreamInfo PaStreamInfo
PaError Pa_StopStream(PaStream *stream)
struct PaHostErrorInfo PaHostErrorInfo
void PaStream
Definition: portaudio.h:639
const PaStreamInfo * Pa_GetStreamInfo(PaStream *stream)
PaError Pa_GetSampleSize(PaSampleFormat format)
PaError Pa_OpenStream(PaStream **stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData)
double sampleRate
Definition: portaudio.h:1074
PaHostApiIndex Pa_GetDefaultHostApi(void)
const char * name
Definition: portaudio.h:307
int PaStreamCallback(const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
Definition: portaudio.h:834
const PaHostErrorInfo * Pa_GetLastHostErrorInfo(void)
PaError Pa_IsFormatSupported(const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate)
void PaStreamFinishedCallback(void *userData)
Definition: portaudio.h:969
int PaDeviceIndex
Definition: portaudio.h:213
PaError Pa_SetStreamFinishedCallback(PaStream *stream, PaStreamFinishedCallback *streamFinishedCallback)
PaTime defaultLowInputLatency
Definition: portaudio.h:514
PaError Pa_StartStream(PaStream *stream)
void * hostApiSpecificStreamInfo
Definition: portaudio.h:583
struct PaHostApiInfo PaHostApiInfo
const char * versionControlRevision
Definition: portaudio.h:99
PaDeviceIndex defaultInputDevice
Definition: portaudio.h:320
PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex(PaHostApiIndex hostApi, int hostApiDeviceIndex)
PaError Pa_IsStreamStopped(PaStream *stream)
PaTime inputLatency
Definition: portaudio.h:1057
PaSampleFormat sampleFormat
Definition: portaudio.h:563
const char * versionText
Definition: portaudio.h:101
const char * errorText
Definition: portaudio.h:396
unsigned long PaStreamFlags
Definition: portaudio.h:657
int PaError
Definition: portaudio.h:121
PaError Pa_IsStreamActive(PaStream *stream)
PaHostApiTypeId
Definition: portaudio.h:276
PaTime suggestedLatency
Definition: portaudio.h:576
struct PaVersionInfo PaVersionInfo
int Pa_GetVersion(void)
unsigned long PaStreamCallbackFlags
Definition: portaudio.h:716
PaTime Pa_GetStreamTime(PaStream *stream)
struct PaStreamParameters PaStreamParameters
PaError Pa_OpenDefaultStream(PaStream **stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData)
PaDeviceIndex defaultOutputDevice
Definition: portaudio.h:326
int structVersion
Definition: portaudio.h:1049
PaError Pa_AbortStream(PaStream *stream)
const PaHostApiInfo * Pa_GetHostApiInfo(PaHostApiIndex hostApi)
unsigned long PaSampleFormat
Definition: portaudio.h:488
PaHostApiIndex hostApi
Definition: portaudio.h:508
signed long Pa_GetStreamReadAvailable(PaStream *stream)
PaHostApiIndex Pa_GetHostApiCount(void)
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
PaDeviceIndex Pa_GetDefaultOutputDevice(void)
PaStreamCallbackResult
Definition: portaudio.h:757
PaDeviceIndex device
Definition: portaudio.h:550
struct PaStreamCallbackTimeInfo PaStreamCallbackTimeInfo
void Pa_Sleep(long msec)
PaError Pa_ReadStream(PaStream *stream, void *buffer, unsigned long frames)
PaHostApiTypeId hostApiType
Definition: portaudio.h:394
PaTime outputLatency
Definition: portaudio.h:1065
PaError Pa_WriteStream(PaStream *stream, const void *buffer, unsigned long frames)
double PaTime
Definition: portaudio.h:464
const char * Pa_GetErrorText(PaError errorCode)
const PaVersionInfo * Pa_GetVersionInfo(void)
PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex(PaHostApiTypeId type)
signed long Pa_GetStreamWriteAvailable(PaStream *stream)
PaError Pa_CloseStream(PaStream *stream)
PaError Pa_Terminate(void)
const char * Pa_GetVersionText(void)
double Pa_GetStreamCpuLoad(PaStream *stream)