-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlibportaudio.pas
278 lines (242 loc) · 10.9 KB
/
libportaudio.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
{ Header for libportaudio
Copyright (C) 2021 Red_prig
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
}
unit libportaudio;
{$mode objfpc}{$H+}
{$PACKRECORDS C}
interface
uses
{$if defined(USE_STATIC_PORTAUDIO) and defined(WINDOWS)}
libaudio_static,
{$ENDIF}
CTypes;
{$ifdef USE_STATIC_PORTAUDIO}
{$Linklib libportaudio.a, static}
{$IFDEF unix}
{$Linklib libasound}
{$Linklib libpthread}
{$Linklib libm}
{$Linklib libc}
{$ENDIF}
{$endif}
Const
{$IFDEF unix}
{$IFDEF darwin}
libname='libportaudio.2.dylib';
{$ELSE}
libname='libportaudio.so.2';
{$ENDIF}
{$ELSE}
libname='libportaudio-2.dll';
{$ENDIF}
type
PaError = CInt32;
PaErrorCode =(
paNotInitialized := -10000,
paUnanticipatedHostError,
paInvalidChannelCount,
paInvalidSampleRate,
paInvalidDevice,
paInvalidFlag,
paSampleFormatNotSupported,
paBadIODeviceCombination,
paInsufficientMemory,
paBufferTooBig,
paBufferTooSmall,
paNullCallback,
paBadStreamPtr,
paTimedOut,
paInternalError,
paDeviceUnavailable,
paIncompatibleHostApiSpecificStreamInfo,
paStreamIsStopped,
paStreamIsNotStopped,
paInputOverflowed,
paOutputUnderflowed,
paHostApiNotFound,
paInvalidHostApi,
paCanNotReadFromACallbackStream,
paCanNotWriteToACallbackStream,
paCanNotReadFromAnOutputOnlyStream,
paCanNotWriteToAnInputOnlyStream,
paIncompatibleStreamHostApi,
paBadBufferPtr,
paNoError := 0
);
PaDeviceIndex = CInt32;
PaHostApiIndex = CInt32;
PaHostApiTypeId =(paInDevelopment := 0,
paDirectSound := 1,
paMME := 2,
paASIO := 3,
paSoundManager := 4,
paCoreAudio := 5,
paOSS := 7,
paALSA := 8,
paAL := 9,
paBeOS := 10,
paWDMKS := 11,
paJACK := 12,
paWASAPI := 13,
paAudioScienceHPI := 14
);
PaHostApiInfo = record
structVersion : CInt32;
_type : PaHostApiTypeId ;
_name : Pchar;
deviceCount : CInt32;
defaultInputDevice : PaDeviceIndex;
defaultOutputDevice : PaDeviceIndex;
end;
PPaHostApiInfo = ^PaHostApiInfo;
PaHostErrorInfo = record
hostApiType : PaHostApiTypeId;
errorCode : CLong;
errorText : PChar;
end;
PPaHostErrorInfo = ^PaHostErrorInfo;
PaTime = CDouble;
PaSampleFormat = pCULongLong;
PaDeviceInfo = record
structVersion : CInt32;
_name : PChar;
hostApi : PaHostApiIndex;
maxInputChannels : CInt32;
maxOutputChannels : CInt32;
defaultLowInputLatency : PaTime;
defaultLowOutputLatency : PaTime;
defaultHighInputLatency : PaTime;
defaultHighOutputLatency : PaTime;
defaultSampleRate : CDouble;
end;
PPaDeviceInfo = ^PaDeviceInfo;
PaStreamParameters = record
device : PaDeviceIndex;
channelCount : CInt32;
sampleFormat : PaSampleFormat;
suggestedLatency : PaTime;
hostApiSpecificStreamInfo : Pointer;
end;
PPaStreamParameters = ^PaStreamParameters;
PaStream = Pointer;
PPaStream = ^PaStream;
PPPaStream = ^PPaStream;
PaStreamFlags = CULong;
PaStreamCallbackTimeInfo = record
inputBufferAdcTime : PaTime;
currentTime : PaTime;
outputBufferDacTime : PaTime;
end;
PaStreamCallbackFlags = CULong;
PaStreamCallbackResult =(
paContinue := 0,
paComplete := 1,
paAbort := 2);
PaStreamCallback = function(
input : Pointer;
output : Pointer;
frameCount : CULong;
timeInfo : PaStreamCallbackTimeInfo;
statusFlags : PaStreamCallbackFlags;
userData : Pointer) : CInt32;
PaStreamFinishedCallback = procedure(userData : Pointer);
PaStreamInfo = record
structVersion : CInt32;
inputLatency : PaTime;
outputLatency : PaTime;
sampleRate : CDouble;
end;
PPaStreamInfo = ^PaStreamInfo;
const
paFormatIsSupported = 0;
paFramesPerBufferUnspecified = 0;
paNoDevice = PaDeviceIndex(-1);
paUseHostApiSpecificDeviceSpecification = PaDeviceIndex(-2);
paFloat32 = PaSampleFormat($00000001);
paInt32 = PaSampleFormat($00000002);
paInt24 = PaSampleFormat($00000004);
paInt16 = PaSampleFormat($00000008);
paInt8 = PaSampleFormat($00000010);
paUInt8 = PaSampleFormat($00000020);
paCustomFormat = PaSampleFormat($00010000);
paNonInterleaved = PaSampleFormat($80000000);
paNoFlag = PaStreamFlags(0);
paClipOff = PaStreamFlags($00000001);
paDitherOff = PaStreamFlags($00000002);
paNeverDropInput = PaStreamFlags($00000004);
paPrimeOutputBuffersUsingStreamCallback = PaStreamFlags($00000008);
paPlatformSpecificFlags = PaStreamFlags($FFFF0000);
paInputUnderflow = PaStreamCallbackFlags($00000001);
paInputOverflow = PaStreamCallbackFlags($00000002);
paOutputUnderflow = PaStreamCallbackFlags($00000004);
paOutputOverflow = PaStreamCallbackFlags($00000008);
paPrimingOutput = PaStreamCallbackFlags($00000010);
function Pa_GetVersion():CInt32 ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetVersionText():PChar ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetErrorText(errorCode : PaError):PChar ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_Initialize():PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_Terminate():PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetHostApiCount():PaHostApiIndex ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetDefaultHostApi():PaHostApiIndex ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetHostApiInfo(hostApi : PaHostApiIndex):PPaHostApiInfo ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_HostApiTypeIdToHostApiIndex(_type : PaHostApiTypeId):PaHostApiIndex ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_HostApiDeviceIndexToDeviceIndex(hostApi : PaHostApiIndex;hostApiDeviceIndex : CInt32):PaDeviceIndex ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetLastHostErrorInfo():PPaHostErrorInfo ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetDeviceCount:PaDeviceIndex ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetDefaultInputDevice:PaDeviceIndex ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetDefaultOutputDevice:PaDeviceIndex ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetDeviceInfo(device : PaDeviceIndex):PPaDeviceInfo ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_IsFormatSupported(inputParameters,outputParameters : PPaStreamParameters; sampleRate : CDouble):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_OpenStream(stream : PPPaStream;
inputParameters : PPaStreamParameters;
outputParameters : PPaStreamParameters;
sampleRate : CDouble;
framesPerBuffer : CULong;
streamFlags : PaStreamFlags;
streamCallback : PaStreamCallback;
userData : Pointer):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_OpenDefaultStream(stream : PPPaStream;
numInputChannels : CInt32;
numOutputChannels : CInt32;
sampleFormat : PaSampleFormat;
sampleRate : CDouble;
framesPerBuffer : CULong;
streamCallback : PaStreamCallback;
userData : Pointer):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_CloseStream(stream : PPaStream):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_SetStreamFinishedCallback(stream : PPaStream;
streamFinishedCallback : PaStreamFinishedCallback):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_StartStream(stream : PPaStream):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_StopStream(stream : PPaStream):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_AbortStream(stream : PPaStream):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_IsStreamStopped(stream : PPaStream):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_IsStreamActive(stream : PPaStream):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetStreamInfo(stream : PPaStream):PPaStreamInfo ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetStreamTime(stream : PPaStream):Patime ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetStreamCpuLoad(stream : PPaStream):CDouble ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_ReadStream(stream : PPaStream; buffer : pcfloat ;frames : CULong):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_WriteStream(stream : PPaStream; buffer : pcfloat ;frames : CULong):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetStreamReadAvailable(stream : PPaStream):CSLong ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetStreamWriteAvailable(stream : PPaStream):CSLong ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_GetSampleSize(format : PaSampleFormat):PaError ; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
function Pa_Sleep(msec : CLong) : integer; cdecl; external {$ifndef USE_STATIC_PORTAUDIO} libname {$endif};
implementation
end.