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;
102  const char *versionText;
103 } PaVersionInfo;
104 
115 const PaVersionInfo* Pa_GetVersionInfo( void );
116 
117 
122 typedef int PaError;
123 typedef enum PaErrorCode
124 {
125  paNoError = 0,
126 
127  paNotInitialized = -10000,
128  paUnanticipatedHostError,
129  paInvalidChannelCount,
130  paInvalidSampleRate,
131  paInvalidDevice,
132  paInvalidFlag,
133  paSampleFormatNotSupported,
134  paBadIODeviceCombination,
135  paInsufficientMemory,
136  paBufferTooBig,
137  paBufferTooSmall,
138  paNullCallback,
139  paBadStreamPtr,
140  paTimedOut,
141  paInternalError,
142  paDeviceUnavailable,
143  paIncompatibleHostApiSpecificStreamInfo,
144  paStreamIsStopped,
145  paStreamIsNotStopped,
146  paInputOverflowed,
147  paOutputUnderflowed,
148  paHostApiNotFound,
149  paInvalidHostApi,
150  paCanNotReadFromACallbackStream,
151  paCanNotWriteToACallbackStream,
152  paCanNotReadFromAnOutputOnlyStream,
153  paCanNotWriteToAnInputOnlyStream,
154  paIncompatibleStreamHostApi,
155  paBadBufferPtr,
156  paCanNotInitializeRecursively
157 } PaErrorCode;
158 
159 
163 const char *Pa_GetErrorText( PaError errorCode );
164 
165 
185 PaError Pa_Initialize( void );
186 
187 
204 PaError Pa_Terminate( void );
205 
206 
207 
214 typedef int PaDeviceIndex;
215 
216 
222 #define paNoDevice ((PaDeviceIndex)-1)
223 
224 
230 #define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2)
231 
232 
233 /* Host API enumeration mechanism */
234 
240 typedef int PaHostApiIndex;
241 
242 
252 PaHostApiIndex Pa_GetHostApiCount( void );
253 
254 
263 PaHostApiIndex Pa_GetDefaultHostApi( void );
264 
265 
277 typedef enum PaHostApiTypeId
278 {
279  paInDevelopment=0, /* use while developing support for a new host API */
280  paDirectSound=1,
281  paMME=2,
282  paASIO=3,
283  paSoundManager=4,
284  paCoreAudio=5,
285  paOSS=7,
286  paALSA=8,
287  paAL=9,
288  paBeOS=10,
289  paWDMKS=11,
290  paJACK=12,
291  paWASAPI=13,
292  paAudioScienceHPI=14,
293  paAudioIO=15,
294  paPulseAudio=16,
295  paSndio=17
297 
298 
301 typedef struct PaHostApiInfo
302 {
308  const char *name;
309 
316 
321  PaDeviceIndex defaultInputDevice;
322 
327  PaDeviceIndex defaultOutputDevice;
328 
329 } PaHostApiInfo;
330 
331 
345 const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi );
346 
347 
363 PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type );
364 
365 
387 PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi,
388  int hostApiDeviceIndex );
389 
390 
391 
394 typedef struct PaHostErrorInfo{
396  long errorCode;
397  const char *errorText;
399 
400 
415 
416 
417 
418 /* Device enumeration and capabilities */
419 
427 PaDeviceIndex Pa_GetDeviceCount( void );
428 
429 
436 PaDeviceIndex Pa_GetDefaultInputDevice( void );
437 
438 
454 PaDeviceIndex Pa_GetDefaultOutputDevice( void );
455 
456 
465 typedef double PaTime;
466 
467 
489 typedef unsigned long PaSampleFormat;
490 
491 
492 #define paFloat32 ((PaSampleFormat) 0x00000001)
493 #define paInt32 ((PaSampleFormat) 0x00000002)
494 #define paInt24 ((PaSampleFormat) 0x00000004)
495 #define paInt16 ((PaSampleFormat) 0x00000008)
496 #define paInt8 ((PaSampleFormat) 0x00000010)
497 #define paUInt8 ((PaSampleFormat) 0x00000020)
498 #define paCustomFormat ((PaSampleFormat) 0x00010000)
500 #define paNonInterleaved ((PaSampleFormat) 0x80000000)
505 typedef struct PaDeviceInfo
506 {
510  const char *name;
511 
513  PaHostApiIndex hostApi;
514 
515  int maxInputChannels;
516  int maxOutputChannels;
517 
520  PaTime defaultLowOutputLatency;
523  PaTime defaultHighOutputLatency;
524 
525  double defaultSampleRate;
526 } PaDeviceInfo;
527 
528 
542 const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device );
543 
544 
547 typedef struct PaStreamParameters
548 {
555  PaDeviceIndex device;
556 
563 
568  PaSampleFormat sampleFormat;
569 
582 
589 
591 
592 
594 #define paFormatIsSupported (0)
595 
618 PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
619  const PaStreamParameters *outputParameters,
620  double sampleRate );
621 
622 
623 
624 /* Streaming types and functions */
625 
626 
644 typedef void PaStream;
645 
646 
651 #define paFramesPerBufferUnspecified (0)
652 
653 
662 typedef unsigned long PaStreamFlags;
663 
665 #define paNoFlag ((PaStreamFlags) 0)
666 
670 #define paClipOff ((PaStreamFlags) 0x00000001)
671 
675 #define paDitherOff ((PaStreamFlags) 0x00000002)
676 
686 #define paNeverDropInput ((PaStreamFlags) 0x00000004)
687 
694 #define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008)
695 
699 #define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000)
700 
710  PaTime currentTime;
713 
714 
721 typedef unsigned long PaStreamCallbackFlags;
722 
730 #define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001)
731 
739 #define paInputOverflow ((PaStreamCallbackFlags) 0x00000002)
740 
745 #define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004)
746 
750 #define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008)
751 
756 #define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010)
757 
763 {
768 
769 
839 typedef int PaStreamCallback(
840  const void *input, void *output,
841  unsigned long frameCount,
842  const PaStreamCallbackTimeInfo* timeInfo,
843  PaStreamCallbackFlags statusFlags,
844  void *userData );
845 
846 
904 PaError Pa_OpenStream( PaStream** stream,
905  const PaStreamParameters *inputParameters,
906  const PaStreamParameters *outputParameters,
907  double sampleRate,
908  unsigned long framesPerBuffer,
909  PaStreamFlags streamFlags,
910  PaStreamCallback *streamCallback,
911  void *userData );
912 
913 
944 PaError Pa_OpenDefaultStream( PaStream** stream,
945  int numInputChannels,
946  int numOutputChannels,
947  PaSampleFormat sampleFormat,
948  double sampleRate,
949  unsigned long framesPerBuffer,
950  PaStreamCallback *streamCallback,
951  void *userData );
952 
953 
957 PaError Pa_CloseStream( PaStream *stream );
958 
959 
974 typedef void PaStreamFinishedCallback( void *userData );
975 
976 
995 PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback );
996 
997 
1000 PaError Pa_StartStream( PaStream *stream );
1001 
1002 
1006 PaError Pa_StopStream( PaStream *stream );
1007 
1008 
1012 PaError Pa_AbortStream( PaStream *stream );
1013 
1014 
1027 PaError Pa_IsStreamStopped( PaStream *stream );
1028 
1029 
1043 PaError Pa_IsStreamActive( PaStream *stream );
1044 
1045 
1046 
1051 typedef struct PaStreamInfo
1052 {
1055 
1063 
1071 
1079  double sampleRate;
1080 
1081 } PaStreamInfo;
1082 
1083 
1097 const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream );
1098 
1099 
1115 PaTime Pa_GetStreamTime( PaStream *stream );
1116 
1117 
1134 double Pa_GetStreamCpuLoad( PaStream* stream );
1135 
1136 
1162 PaError Pa_ReadStream( PaStream* stream,
1163  void *buffer,
1164  unsigned long frames );
1165 
1166 
1193 PaError Pa_WriteStream( PaStream* stream,
1194  const void *buffer,
1195  unsigned long frames );
1196 
1197 
1209 signed long Pa_GetStreamReadAvailable( PaStream* stream );
1210 
1211 
1223 signed long Pa_GetStreamWriteAvailable( PaStream* stream );
1224 
1225 
1226 /* Miscellaneous utilities */
1227 
1228 
1234 PaError Pa_GetSampleSize( PaSampleFormat format );
1235 
1236 
1244 void Pa_Sleep( long msec );
1245 
1246 
1247 
1248 #ifdef __cplusplus
1249 }
1250 #endif /* __cplusplus */
1251 #endif /* PORTAUDIO_H */
PaError Pa_Initialize(void)
struct PaDeviceInfo PaDeviceInfo
int structVersion
Definition: portaudio.h:304
PaTime defaultHighInputLatency
Definition: portaudio.h:522
int PaHostApiIndex
Definition: portaudio.h:240
PaDeviceIndex Pa_GetDefaultInputDevice(void)
PaDeviceIndex Pa_GetDeviceCount(void)
PaHostApiTypeId type
Definition: portaudio.h:306
struct PaStreamInfo PaStreamInfo
PaError Pa_StopStream(PaStream *stream)
struct PaHostErrorInfo PaHostErrorInfo
void PaStream
Definition: portaudio.h:644
int structVersion
Definition: portaudio.h:507
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:1079
PaHostApiIndex Pa_GetDefaultHostApi(void)
const char * name
Definition: portaudio.h:510
const char * name
Definition: portaudio.h:308
int PaStreamCallback(const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
Definition: portaudio.h:839
const PaHostErrorInfo * Pa_GetLastHostErrorInfo(void)
PaError Pa_IsFormatSupported(const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate)
void PaStreamFinishedCallback(void *userData)
Definition: portaudio.h:974
int PaDeviceIndex
Definition: portaudio.h:214
PaError Pa_SetStreamFinishedCallback(PaStream *stream, PaStreamFinishedCallback *streamFinishedCallback)
PaTime defaultLowInputLatency
Definition: portaudio.h:519
PaError Pa_StartStream(PaStream *stream)
void * hostApiSpecificStreamInfo
Definition: portaudio.h:588
struct PaHostApiInfo PaHostApiInfo
const char * versionControlRevision
Definition: portaudio.h:100
PaDeviceIndex defaultInputDevice
Definition: portaudio.h:321
PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex(PaHostApiIndex hostApi, int hostApiDeviceIndex)
PaError Pa_IsStreamStopped(PaStream *stream)
PaTime inputLatency
Definition: portaudio.h:1062
PaSampleFormat sampleFormat
Definition: portaudio.h:568
const char * versionText
Definition: portaudio.h:102
const char * errorText
Definition: portaudio.h:397
unsigned long PaStreamFlags
Definition: portaudio.h:662
int PaError
Definition: portaudio.h:122
PaError Pa_IsStreamActive(PaStream *stream)
PaHostApiTypeId
Definition: portaudio.h:277
PaTime suggestedLatency
Definition: portaudio.h:581
struct PaVersionInfo PaVersionInfo
int Pa_GetVersion(void)
unsigned long PaStreamCallbackFlags
Definition: portaudio.h:721
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:327
int structVersion
Definition: portaudio.h:1054
PaError Pa_AbortStream(PaStream *stream)
const PaHostApiInfo * Pa_GetHostApiInfo(PaHostApiIndex hostApi)
unsigned long PaSampleFormat
Definition: portaudio.h:489
PaHostApiIndex hostApi
Definition: portaudio.h:513
signed long Pa_GetStreamReadAvailable(PaStream *stream)
PaHostApiIndex Pa_GetHostApiCount(void)
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
PaDeviceIndex Pa_GetDefaultOutputDevice(void)
PaStreamCallbackResult
Definition: portaudio.h:762
PaDeviceIndex device
Definition: portaudio.h:555
struct PaStreamCallbackTimeInfo PaStreamCallbackTimeInfo
void Pa_Sleep(long msec)
PaError Pa_ReadStream(PaStream *stream, void *buffer, unsigned long frames)
PaHostApiTypeId hostApiType
Definition: portaudio.h:395
PaTime outputLatency
Definition: portaudio.h:1070
PaError Pa_WriteStream(PaStream *stream, const void *buffer, unsigned long frames)
double PaTime
Definition: portaudio.h:465
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)