1 /*
2 TiMidity++ -- MIDI to WAVE converter and player
3 Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4 Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 #define PORTAUDIO_V19 1
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif /* HAVE_CONFIG_H */
25 #include "interface.h"
26
27 #ifdef AU_PORTAUDIO_DLL
28
29 #ifdef __W32__
30 #include <windows.h>
31 #endif
32 #include <portaudio.h>
33
34
35 #include "w32_portaudio.h"
36
37
38 #ifdef PORTAUDIO_V19
39
40 #include <pa_asio.h>
41
42 extern int load_portaudio_dll(int);
43 extern void free_portaudio_dll(void);
44
45 /***************************************************************
46 name: portaudio_dll dll: portaudio.dll
47 ***************************************************************/
48
49 typedef int(*type_Pa_GetVersion)( void );
50 typedef const char*(*type_Pa_GetVersionText)( void );
51 typedef const char*(*type_Pa_GetErrorText)( PaError errorCode );
52 typedef PaError(*type_Pa_Initialize)( void );
53 typedef PaError(*type_Pa_Terminate)( void );
54 typedef PaHostApiIndex(*type_Pa_GetHostApiCount)( void );
55 typedef PaHostApiIndex(*type_Pa_GetDefaultHostApi)( void );
56 typedef const PaHostApiInfo *(*type_Pa_GetHostApiInfo)( PaHostApiIndex hostApi );
57 typedef PaHostApiIndex(*type_Pa_HostApiTypeIdToHostApiIndex)( PaHostApiTypeId type );
58 typedef const PaHostErrorInfo*(*type_Pa_GetLastHostErrorInfo)( void );
59 typedef PaDeviceIndex(*type_Pa_GetDeviceCount)( void );
60 typedef PaDeviceIndex(*type_Pa_GetDefaultInputDevice)( void );
61 typedef PaDeviceIndex(*type_Pa_GetDefaultOutputDevice)( void );
62 typedef const PaDeviceInfo*(*type_Pa_GetDeviceInfo)( PaDeviceIndex device );
63 typedef PaError(*type_Pa_IsFormatSupported)( const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate );
64 typedef PaError(*type_Pa_OpenStream)( PaStream** stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData );
65 typedef PaError(*type_Pa_OpenDefaultStream)( PaStream** stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData );
66 typedef PaError(*type_Pa_CloseStream)( PaStream *stream );
67 //typedef typedef void(*type_PaStreamFinishedCallback)( void *userData );
68 typedef PaError(*type_Pa_SetStreamFinishedCallback)( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback );
69 typedef PaError(*type_Pa_StartStream)( PaStream *stream );
70 typedef PaError(*type_Pa_StopStream)( PaStream *stream );
71 typedef PaError(*type_Pa_AbortStream)( PaStream *stream );
72 typedef PaError(*type_Pa_IsStreamStopped)( PaStream *stream );
73 typedef PaError(*type_Pa_IsStreamActive)( PaStream *stream );
74 typedef const PaStreamInfo*(*type_Pa_GetStreamInfo)( PaStream *stream );
75 typedef PaTime(*type_Pa_GetStreamTime)( PaStream *stream );
76 typedef double(*type_Pa_GetStreamCpuLoad)( PaStream* stream );
77 typedef signed long(*type_Pa_GetStreamReadAvailable)( PaStream* stream );
78 typedef signed long(*type_Pa_GetStreamWriteAvailable)( PaStream* stream );
79 typedef PaError(*type_Pa_GetSampleSize)( PaSampleFormat format );
80 typedef void(*type_Pa_Sleep)( long msec );
81 typedef PaError(*type_PaAsio_ShowControlPanel)( PaDeviceIndex device, void* systemSpecific );
82
83 static struct portaudio_dll_ {
84 type_Pa_GetVersion Pa_GetVersion;
85 type_Pa_GetVersionText Pa_GetVersionText;
86 type_Pa_GetErrorText Pa_GetErrorText;
87 type_Pa_Initialize Pa_Initialize;
88 type_Pa_Terminate Pa_Terminate;
89 type_Pa_GetHostApiCount Pa_GetHostApiCount;
90 type_Pa_GetDefaultHostApi Pa_GetDefaultHostApi;
91 type_Pa_GetHostApiInfo Pa_GetHostApiInfo;
92 type_Pa_HostApiTypeIdToHostApiIndex Pa_HostApiTypeIdToHostApiIndex;
93 type_Pa_GetLastHostErrorInfo Pa_GetLastHostErrorInfo;
94 type_Pa_GetDeviceCount Pa_GetDeviceCount;
95 type_Pa_GetDefaultInputDevice Pa_GetDefaultInputDevice;
96 type_Pa_GetDefaultOutputDevice Pa_GetDefaultOutputDevice;
97 type_Pa_GetDeviceInfo Pa_GetDeviceInfo;
98 type_Pa_IsFormatSupported Pa_IsFormatSupported;
99 type_Pa_OpenStream Pa_OpenStream;
100 type_Pa_OpenDefaultStream Pa_OpenDefaultStream;
101 type_Pa_CloseStream Pa_CloseStream;
102 // type_PaStreamFinishedCallback PaStreamFinishedCallback;
103 type_Pa_SetStreamFinishedCallback Pa_SetStreamFinishedCallback;
104 type_Pa_StartStream Pa_StartStream;
105 type_Pa_StopStream Pa_StopStream;
106 type_Pa_AbortStream Pa_AbortStream;
107 type_Pa_IsStreamStopped Pa_IsStreamStopped;
108 type_Pa_IsStreamActive Pa_IsStreamActive;
109 type_Pa_GetStreamInfo Pa_GetStreamInfo;
110 type_Pa_GetStreamTime Pa_GetStreamTime;
111 type_Pa_GetStreamCpuLoad Pa_GetStreamCpuLoad;
112 type_Pa_GetStreamReadAvailable Pa_GetStreamReadAvailable;
113 type_Pa_GetStreamWriteAvailable Pa_GetStreamWriteAvailable;
114 type_Pa_GetSampleSize Pa_GetSampleSize;
115 type_Pa_Sleep Pa_Sleep;
116 type_PaAsio_ShowControlPanel PaAsio_ShowControlPanel;
117 } portaudio_dll;
118
119 static volatile HANDLE h_portaudio_dll = NULL;
120
free_portaudio_dll(void)121 void free_portaudio_dll(void)
122 {
123 if(h_portaudio_dll){
124 FreeLibrary(h_portaudio_dll);
125 h_portaudio_dll = NULL;
126 }
127 }
128
load_portaudio_dll(int a)129 int load_portaudio_dll(int a)
130 {
131 if(!h_portaudio_dll){
132 h_portaudio_dll = LoadLibrary("portaudio.dll");
133 if(!h_portaudio_dll) return -1;
134 }
135 portaudio_dll.Pa_GetVersion = (type_Pa_GetVersion)GetProcAddress(h_portaudio_dll,"Pa_GetVersion");
136 if(!portaudio_dll.Pa_GetVersion){ free_portaudio_dll(); return -1; }
137 portaudio_dll.Pa_GetVersionText = (type_Pa_GetVersionText)GetProcAddress(h_portaudio_dll,"Pa_GetVersionText");
138 if(!portaudio_dll.Pa_GetVersionText){ free_portaudio_dll(); return -1; }
139 portaudio_dll.Pa_GetErrorText = (type_Pa_GetErrorText)GetProcAddress(h_portaudio_dll,"Pa_GetErrorText");
140 if(!portaudio_dll.Pa_GetErrorText){ free_portaudio_dll(); return -1; }
141 portaudio_dll.Pa_Initialize = (type_Pa_Initialize)GetProcAddress(h_portaudio_dll,"Pa_Initialize");
142 if(!portaudio_dll.Pa_Initialize){ free_portaudio_dll(); return -1; }
143 portaudio_dll.Pa_Terminate = (type_Pa_Terminate)GetProcAddress(h_portaudio_dll,"Pa_Terminate");
144 if(!portaudio_dll.Pa_Terminate){ free_portaudio_dll(); return -1; }
145 portaudio_dll.Pa_GetHostApiCount = (type_Pa_GetHostApiCount)GetProcAddress(h_portaudio_dll,"Pa_GetHostApiCount");
146 if(!portaudio_dll.Pa_GetHostApiCount){ free_portaudio_dll(); return -1; }
147 portaudio_dll.Pa_GetDefaultHostApi = (type_Pa_GetDefaultHostApi)GetProcAddress(h_portaudio_dll,"Pa_GetDefaultHostApi");
148 if(!portaudio_dll.Pa_GetDefaultHostApi){ free_portaudio_dll(); return -1; }
149 portaudio_dll.Pa_GetHostApiInfo = (type_Pa_GetHostApiInfo)GetProcAddress(h_portaudio_dll,"Pa_GetHostApiInfo");
150 if(!portaudio_dll.Pa_GetHostApiInfo){ free_portaudio_dll(); return -1; }
151 portaudio_dll.Pa_HostApiTypeIdToHostApiIndex = (type_Pa_HostApiTypeIdToHostApiIndex)GetProcAddress(h_portaudio_dll,"Pa_HostApiTypeIdToHostApiIndex");
152 if(!portaudio_dll.Pa_HostApiTypeIdToHostApiIndex){ free_portaudio_dll(); return -1; }
153 portaudio_dll.Pa_GetLastHostErrorInfo = (type_Pa_GetLastHostErrorInfo)GetProcAddress(h_portaudio_dll,"Pa_GetLastHostErrorInfo");
154 if(!portaudio_dll.Pa_GetLastHostErrorInfo){ free_portaudio_dll(); return -1; }
155 portaudio_dll.Pa_GetDeviceCount = (type_Pa_GetDeviceCount)GetProcAddress(h_portaudio_dll,"Pa_GetDeviceCount");
156 if(!portaudio_dll.Pa_GetDeviceCount){ free_portaudio_dll(); return -1; }
157 portaudio_dll.Pa_GetDefaultInputDevice = (type_Pa_GetDefaultInputDevice)GetProcAddress(h_portaudio_dll,"Pa_GetDefaultInputDevice");
158 if(!portaudio_dll.Pa_GetDefaultInputDevice){ free_portaudio_dll(); return -1; }
159 portaudio_dll.Pa_GetDefaultOutputDevice = (type_Pa_GetDefaultOutputDevice)GetProcAddress(h_portaudio_dll,"Pa_GetDefaultOutputDevice");
160 if(!portaudio_dll.Pa_GetDefaultOutputDevice){ free_portaudio_dll(); return -1; }
161 portaudio_dll.Pa_GetDeviceInfo = (type_Pa_GetDeviceInfo)GetProcAddress(h_portaudio_dll,"Pa_GetDeviceInfo");
162 if(!portaudio_dll.Pa_GetDeviceInfo){ free_portaudio_dll(); return -1; }
163 portaudio_dll.Pa_IsFormatSupported = (type_Pa_IsFormatSupported)GetProcAddress(h_portaudio_dll,"Pa_IsFormatSupported");
164 if(!portaudio_dll.Pa_IsFormatSupported){ free_portaudio_dll(); return -1; }
165 portaudio_dll.Pa_OpenStream = (type_Pa_OpenStream)GetProcAddress(h_portaudio_dll,"Pa_OpenStream");
166 if(!portaudio_dll.Pa_OpenStream){ free_portaudio_dll(); return -1; }
167 portaudio_dll.Pa_OpenDefaultStream = (type_Pa_OpenDefaultStream)GetProcAddress(h_portaudio_dll,"Pa_OpenDefaultStream");
168 if(!portaudio_dll.Pa_OpenDefaultStream){ free_portaudio_dll(); return -1; }
169 portaudio_dll.Pa_CloseStream = (type_Pa_CloseStream)GetProcAddress(h_portaudio_dll,"Pa_CloseStream");
170 if(!portaudio_dll.Pa_CloseStream){ free_portaudio_dll(); return -1; }
171 // portaudio_dll.PaStreamFinishedCallback = (type_PaStreamFinishedCallback)GetProcAddress(h_portaudio_dll,"PaStreamFinishedCallback");
172 // if(!portaudio_dll.PaStreamFinishedCallback){ free_portaudio_dll(); return -1; }
173 portaudio_dll.Pa_SetStreamFinishedCallback = (type_Pa_SetStreamFinishedCallback)GetProcAddress(h_portaudio_dll,"Pa_SetStreamFinishedCallback");
174 if(!portaudio_dll.Pa_SetStreamFinishedCallback){ free_portaudio_dll(); return -1; }
175 portaudio_dll.Pa_StartStream = (type_Pa_StartStream)GetProcAddress(h_portaudio_dll,"Pa_StartStream");
176 if(!portaudio_dll.Pa_StartStream){ free_portaudio_dll(); return -1; }
177 portaudio_dll.Pa_StopStream = (type_Pa_StopStream)GetProcAddress(h_portaudio_dll,"Pa_StopStream");
178 if(!portaudio_dll.Pa_StopStream){ free_portaudio_dll(); return -1; }
179 portaudio_dll.Pa_AbortStream = (type_Pa_AbortStream)GetProcAddress(h_portaudio_dll,"Pa_AbortStream");
180 if(!portaudio_dll.Pa_AbortStream){ free_portaudio_dll(); return -1; }
181 portaudio_dll.Pa_IsStreamStopped = (type_Pa_IsStreamStopped)GetProcAddress(h_portaudio_dll,"Pa_IsStreamStopped");
182 if(!portaudio_dll.Pa_IsStreamStopped){ free_portaudio_dll(); return -1; }
183 portaudio_dll.Pa_IsStreamActive = (type_Pa_IsStreamActive)GetProcAddress(h_portaudio_dll,"Pa_IsStreamActive");
184 if(!portaudio_dll.Pa_IsStreamActive){ free_portaudio_dll(); return -1; }
185 portaudio_dll.Pa_GetStreamInfo = (type_Pa_GetStreamInfo)GetProcAddress(h_portaudio_dll,"Pa_GetStreamInfo");
186 if(!portaudio_dll.Pa_GetStreamInfo){ free_portaudio_dll(); return -1; }
187 portaudio_dll.Pa_GetStreamTime = (type_Pa_GetStreamTime)GetProcAddress(h_portaudio_dll,"Pa_GetStreamTime");
188 if(!portaudio_dll.Pa_GetStreamTime){ free_portaudio_dll(); return -1; }
189 portaudio_dll.Pa_GetStreamCpuLoad = (type_Pa_GetStreamCpuLoad)GetProcAddress(h_portaudio_dll,"Pa_GetStreamCpuLoad");
190 if(!portaudio_dll.Pa_GetStreamCpuLoad){ free_portaudio_dll(); return -1; }
191 portaudio_dll.Pa_GetStreamReadAvailable = (type_Pa_GetStreamReadAvailable)GetProcAddress(h_portaudio_dll,"Pa_GetStreamReadAvailable");
192 if(!portaudio_dll.Pa_GetStreamReadAvailable){ free_portaudio_dll(); return -1; }
193 portaudio_dll.Pa_GetStreamWriteAvailable = (type_Pa_GetStreamWriteAvailable)GetProcAddress(h_portaudio_dll,"Pa_GetStreamWriteAvailable");
194 if(!portaudio_dll.Pa_GetStreamWriteAvailable){ free_portaudio_dll(); return -1; }
195 portaudio_dll.Pa_GetSampleSize = (type_Pa_GetSampleSize)GetProcAddress(h_portaudio_dll,"Pa_GetSampleSize");
196 if(!portaudio_dll.Pa_GetSampleSize){ free_portaudio_dll(); return -1; }
197 portaudio_dll.Pa_Sleep = (type_Pa_Sleep)GetProcAddress(h_portaudio_dll,"Pa_Sleep");
198 if(!portaudio_dll.Pa_Sleep){ free_portaudio_dll(); return -1; }
199 portaudio_dll.PaAsio_ShowControlPanel = (type_PaAsio_ShowControlPanel)GetProcAddress(h_portaudio_dll,"PaAsio_ShowControlPanel");
200 if(!portaudio_dll.PaAsio_ShowControlPanel){ free_portaudio_dll(); return -1; }
201 return 0;
202 }
203
Pa_GetVersion(void)204 int Pa_GetVersion( void )
205 {
206 if(h_portaudio_dll){
207 return portaudio_dll.Pa_GetVersion();
208 }
209 return (int)0;
210 }
211
Pa_GetVersionText(void)212 const char* Pa_GetVersionText( void )
213 {
214 if(h_portaudio_dll){
215 return portaudio_dll.Pa_GetVersionText();
216 }
217 return (const char*)0;
218 }
219
Pa_GetErrorText(PaError errorCode)220 const char* Pa_GetErrorText( PaError errorCode )
221 {
222 if(h_portaudio_dll){
223 return portaudio_dll.Pa_GetErrorText(errorCode);
224 }
225 return (const char*)0;
226 }
227
Pa_Initialize(void)228 PaError Pa_Initialize( void )
229 {
230 if(h_portaudio_dll){
231 return portaudio_dll.Pa_Initialize();
232 }
233 return (PaError)0;
234 }
235
Pa_Terminate(void)236 PaError Pa_Terminate( void )
237 {
238 if(h_portaudio_dll){
239 return portaudio_dll.Pa_Terminate();
240 }
241 return (PaError)0;
242 }
243
Pa_GetHostApiCount(void)244 PaHostApiIndex Pa_GetHostApiCount( void )
245 {
246 if(h_portaudio_dll){
247 return portaudio_dll.Pa_GetHostApiCount();
248 }
249 return (PaHostApiIndex)0;
250 }
251
Pa_GetDefaultHostApi(void)252 PaHostApiIndex Pa_GetDefaultHostApi( void )
253 {
254 if(h_portaudio_dll){
255 return portaudio_dll.Pa_GetDefaultHostApi();
256 }
257 return (PaHostApiIndex)0;
258 }
259
Pa_GetHostApiInfo(PaHostApiIndex hostApi)260 const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi )
261 {
262 if(h_portaudio_dll){
263 return portaudio_dll.Pa_GetHostApiInfo(hostApi);
264 }
265 return (const PaHostApiInfo *)0;
266 }
267
Pa_HostApiTypeIdToHostApiIndex(PaHostApiTypeId type)268 PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type )
269 {
270 if(h_portaudio_dll){
271 return portaudio_dll.Pa_HostApiTypeIdToHostApiIndex(type);
272 }
273 return (PaHostApiIndex)0;
274 }
275
Pa_GetLastHostErrorInfo(void)276 const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void )
277 {
278 if(h_portaudio_dll){
279 return portaudio_dll.Pa_GetLastHostErrorInfo();
280 }
281 return (const PaHostErrorInfo*)0;
282 }
283
Pa_GetDeviceCount(void)284 PaDeviceIndex Pa_GetDeviceCount( void )
285 {
286 if(h_portaudio_dll){
287 return portaudio_dll.Pa_GetDeviceCount();
288 }
289 return (PaDeviceIndex)0;
290 }
291
Pa_GetDefaultInputDevice(void)292 PaDeviceIndex Pa_GetDefaultInputDevice( void )
293 {
294 if(h_portaudio_dll){
295 return portaudio_dll.Pa_GetDefaultInputDevice();
296 }
297 return (PaDeviceIndex)0;
298 }
299
Pa_GetDefaultOutputDevice(void)300 PaDeviceIndex Pa_GetDefaultOutputDevice( void )
301 {
302 if(h_portaudio_dll){
303 return portaudio_dll.Pa_GetDefaultOutputDevice();
304 }
305 return (PaDeviceIndex)0;
306 }
307
Pa_GetDeviceInfo(PaDeviceIndex device)308 const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device )
309 {
310 if(h_portaudio_dll){
311 return portaudio_dll.Pa_GetDeviceInfo(device);
312 }
313 return (const PaDeviceInfo*)0;
314 }
315
Pa_IsFormatSupported(const PaStreamParameters * inputParameters,const PaStreamParameters * outputParameters,double sampleRate)316 PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate )
317 {
318 if(h_portaudio_dll){
319 return portaudio_dll.Pa_IsFormatSupported(inputParameters,outputParameters,sampleRate);
320 }
321 return (PaError)0;
322 }
323
Pa_OpenStream(PaStream ** stream,const PaStreamParameters * inputParameters,const PaStreamParameters * outputParameters,double sampleRate,unsigned long framesPerBuffer,PaStreamFlags streamFlags,PaStreamCallback * streamCallback,void * userData)324 PaError Pa_OpenStream( PaStream** stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData )
325 {
326 if(h_portaudio_dll){
327 return portaudio_dll.Pa_OpenStream(stream,inputParameters,outputParameters,sampleRate,framesPerBuffer,streamFlags,streamCallback,userData);
328 }
329 return (PaError)0;
330 }
331
Pa_OpenDefaultStream(PaStream ** stream,int numInputChannels,int numOutputChannels,PaSampleFormat sampleFormat,double sampleRate,unsigned long framesPerBuffer,PaStreamCallback * streamCallback,void * userData)332 PaError Pa_OpenDefaultStream( PaStream** stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData )
333 {
334 if(h_portaudio_dll){
335 return portaudio_dll.Pa_OpenDefaultStream(stream,numInputChannels,numOutputChannels,sampleFormat,sampleRate,framesPerBuffer,streamCallback,userData);
336 }
337 return (PaError)0;
338 }
339
Pa_CloseStream(PaStream * stream)340 PaError Pa_CloseStream( PaStream *stream )
341 {
342 if(h_portaudio_dll){
343 return portaudio_dll.Pa_CloseStream(stream);
344 }
345 return (PaError)0;
346 }
347 /*
348 typedef void PaStreamFinishedCallback( void *userData )
349 {
350 if(h_portaudio_dll){
351 portaudio_dll.PaStreamFinishedCallback(userData);
352 }
353 }
354 */
Pa_SetStreamFinishedCallback(PaStream * stream,PaStreamFinishedCallback * streamFinishedCallback)355 PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback )
356 {
357 if(h_portaudio_dll){
358 return portaudio_dll.Pa_SetStreamFinishedCallback(stream,streamFinishedCallback);
359 }
360 return (PaError)0;
361 }
362
Pa_StartStream(PaStream * stream)363 PaError Pa_StartStream( PaStream *stream )
364 {
365 if(h_portaudio_dll){
366 return portaudio_dll.Pa_StartStream(stream);
367 }
368 return (PaError)0;
369 }
370
Pa_StopStream(PaStream * stream)371 PaError Pa_StopStream( PaStream *stream )
372 {
373 if(h_portaudio_dll){
374 return portaudio_dll.Pa_StopStream(stream);
375 }
376 return (PaError)0;
377 }
378
Pa_AbortStream(PaStream * stream)379 PaError Pa_AbortStream( PaStream *stream )
380 {
381 if(h_portaudio_dll){
382 return portaudio_dll.Pa_AbortStream(stream);
383 }
384 return (PaError)0;
385 }
386
Pa_IsStreamStopped(PaStream * stream)387 PaError Pa_IsStreamStopped( PaStream *stream )
388 {
389 if(h_portaudio_dll){
390 return portaudio_dll.Pa_IsStreamStopped(stream);
391 }
392 return (PaError)0;
393 }
394
Pa_IsStreamActive(PaStream * stream)395 PaError Pa_IsStreamActive( PaStream *stream )
396 {
397 if(h_portaudio_dll){
398 return portaudio_dll.Pa_IsStreamActive(stream);
399 }
400 return (PaError)0;
401 }
402
Pa_GetStreamInfo(PaStream * stream)403 const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream )
404 {
405 if(h_portaudio_dll){
406 return portaudio_dll.Pa_GetStreamInfo(stream);
407 }
408 return (const PaStreamInfo*)0;
409 }
410
Pa_GetStreamTime(PaStream * stream)411 PaTime Pa_GetStreamTime( PaStream *stream )
412 {
413 if(h_portaudio_dll){
414 return portaudio_dll.Pa_GetStreamTime(stream);
415 }
416 return (PaTime)0;
417 }
418
Pa_GetStreamCpuLoad(PaStream * stream)419 double Pa_GetStreamCpuLoad( PaStream* stream )
420 {
421 if(h_portaudio_dll){
422 return portaudio_dll.Pa_GetStreamCpuLoad(stream);
423 }
424 return (double)0;
425 }
426
Pa_GetStreamReadAvailable(PaStream * stream)427 signed long Pa_GetStreamReadAvailable( PaStream* stream )
428 {
429 if(h_portaudio_dll){
430 return portaudio_dll.Pa_GetStreamReadAvailable(stream);
431 }
432 return (signed long)0;
433 }
434
Pa_GetStreamWriteAvailable(PaStream * stream)435 signed long Pa_GetStreamWriteAvailable( PaStream* stream )
436 {
437 if(h_portaudio_dll){
438 return portaudio_dll.Pa_GetStreamWriteAvailable(stream);
439 }
440 return (signed long)0;
441 }
442
Pa_GetSampleSize(PaSampleFormat format)443 PaError Pa_GetSampleSize( PaSampleFormat format )
444 {
445 if(h_portaudio_dll){
446 return portaudio_dll.Pa_GetSampleSize(format);
447 }
448 return (PaError)0;
449 }
450
Pa_Sleep(long msec)451 void Pa_Sleep( long msec )
452 {
453 if(h_portaudio_dll){
454 portaudio_dll.Pa_Sleep(msec);
455 }
456 }
PaAsio_ShowControlPanel(PaDeviceIndex device,void * systemSpecific)457 PaError PaAsio_ShowControlPanel( PaDeviceIndex device, void* systemSpecific )
458 {
459 if(h_portaudio_dll){
460 return portaudio_dll.PaAsio_ShowControlPanel(device,systemSpecific);
461 }
462 return (PaError)0;
463 }
464
465 /***************************************************************/
466
467
468
469 #else
470
471
472
473 extern int load_portaudio_dll(int type);
474 extern void free_portaudio_dll(void);
475
476 /***************************************************************
477 name: portaudio_dll dll: portaudio.dll
478 ***************************************************************/
479
480 // (PaError)0 -> paDeviceUnavailable
481 // (PaDeviceID)0 -> paNoDevice
482
483 // #define PA_DLL_ASIO 1
484 // #define PA_DLL_WIN_DS 2
485 // #define PA_DLL_WIN_WMME 3
486 #define PA_DLL_ASIO_FILE "pa_asio.dll"
487 #define PA_DLL_WIN_DS_FILE "pa_win_ds.dll"
488 #define PA_DLL_WIN_WMME_FILE "pa_win_wmme.dll"
489
490 typedef PaError(*type_Pa_Initialize)( void );
491 typedef PaError(*type_Pa_Terminate)( void );
492 typedef long(*type_Pa_GetHostError)( void );
493 typedef const char*(*type_Pa_GetErrorText)( PaError errnum );
494 typedef int(*type_Pa_CountDevices)( void );
495 typedef PaDeviceID(*type_Pa_GetDefaultInputDeviceID)( void );
496 typedef PaDeviceID(*type_Pa_GetDefaultOutputDeviceID)( void );
497 typedef const PaDeviceInfo*(*type_Pa_GetDeviceInfo)( PaDeviceID device );
498 typedef PaError(*type_Pa_OpenStream)( PortAudioStream** stream,PaDeviceID inputDevice,int numInputChannels,PaSampleFormat inputSampleFormat,void *inputDriverInfo,PaDeviceID outputDevice,int numOutputChannels,PaSampleFormat outputSampleFormat,void *outputDriverInfo,double sampleRate,unsigned long framesPerBuffer,unsigned long numberOfBuffers,PaStreamFlags streamFlags,PortAudioCallback *callback,void *userData );
499 typedef PaError(*type_Pa_OpenDefaultStream)( PortAudioStream** stream,int numInputChannels,int numOutputChannels,PaSampleFormat sampleFormat,double sampleRate,unsigned long framesPerBuffer,unsigned long numberOfBuffers,PortAudioCallback *callback,void *userData );
500 typedef PaError(*type_Pa_CloseStream)( PortAudioStream *stream );
501 typedef PaError(*type_Pa_StartStream)( PortAudioStream *stream );
502 typedef PaError(*type_Pa_StopStream)( PortAudioStream *stream );
503 typedef PaError(*type_Pa_AbortStream)( PortAudioStream *stream );
504 typedef PaError(*type_Pa_StreamActive)( PortAudioStream *stream );
505 typedef PaTimestamp(*type_Pa_StreamTime)( PortAudioStream *stream );
506 typedef double(*type_Pa_GetCPULoad)( PortAudioStream* stream );
507 typedef int(*type_Pa_GetMinNumBuffers)( int framesPerBuffer, double sampleRate );
508 typedef void(*type_Pa_Sleep)( long msec );
509 typedef PaError(*type_Pa_GetSampleSize)( PaSampleFormat format );
510
511 static struct portaudio_dll_ {
512 type_Pa_Initialize Pa_Initialize;
513 type_Pa_Terminate Pa_Terminate;
514 type_Pa_GetHostError Pa_GetHostError;
515 type_Pa_GetErrorText Pa_GetErrorText;
516 type_Pa_CountDevices Pa_CountDevices;
517 type_Pa_GetDefaultInputDeviceID Pa_GetDefaultInputDeviceID;
518 type_Pa_GetDefaultOutputDeviceID Pa_GetDefaultOutputDeviceID;
519 type_Pa_GetDeviceInfo Pa_GetDeviceInfo;
520 type_Pa_OpenStream Pa_OpenStream;
521 type_Pa_OpenDefaultStream Pa_OpenDefaultStream;
522 type_Pa_CloseStream Pa_CloseStream;
523 type_Pa_StartStream Pa_StartStream;
524 type_Pa_StopStream Pa_StopStream;
525 type_Pa_AbortStream Pa_AbortStream;
526 type_Pa_StreamActive Pa_StreamActive;
527 type_Pa_StreamTime Pa_StreamTime;
528 type_Pa_GetCPULoad Pa_GetCPULoad;
529 type_Pa_GetMinNumBuffers Pa_GetMinNumBuffers;
530 type_Pa_Sleep Pa_Sleep;
531 type_Pa_GetSampleSize Pa_GetSampleSize;
532 } portaudio_dll;
533
534 static volatile HANDLE h_portaudio_dll = NULL;
535
free_portaudio_dll(void)536 void free_portaudio_dll(void)
537 {
538 if(h_portaudio_dll){
539 FreeLibrary(h_portaudio_dll);
540 h_portaudio_dll = NULL;
541 }
542 }
543
load_portaudio_dll(int type)544 int load_portaudio_dll(int type)
545 {
546 char* dll_file = NULL;
547 switch(type){
548 case PA_DLL_ASIO:
549 dll_file = PA_DLL_ASIO_FILE;
550 break;
551 case PA_DLL_WIN_DS:
552 dll_file = PA_DLL_WIN_DS_FILE;
553 break;
554 case PA_DLL_WIN_WMME:
555 dll_file = PA_DLL_WIN_WMME_FILE;
556 break;
557 default:
558 return -1;
559 }
560 if(!h_portaudio_dll){
561 h_portaudio_dll = LoadLibrary(dll_file);
562 if(!h_portaudio_dll) return -1;
563 }
564 portaudio_dll.Pa_Initialize = (type_Pa_Initialize)GetProcAddress(h_portaudio_dll,"Pa_Initialize");
565 if(!portaudio_dll.Pa_Initialize){ free_portaudio_dll(); return -1; }
566 portaudio_dll.Pa_Terminate = (type_Pa_Terminate)GetProcAddress(h_portaudio_dll,"Pa_Terminate");
567 if(!portaudio_dll.Pa_Terminate){ free_portaudio_dll(); return -1; }
568 portaudio_dll.Pa_GetHostError = (type_Pa_GetHostError)GetProcAddress(h_portaudio_dll,"Pa_GetHostError");
569 if(!portaudio_dll.Pa_GetHostError){ free_portaudio_dll(); return -1; }
570 portaudio_dll.Pa_GetErrorText = (type_Pa_GetErrorText)GetProcAddress(h_portaudio_dll,"Pa_GetErrorText");
571 if(!portaudio_dll.Pa_GetErrorText){ free_portaudio_dll(); return -1; }
572 portaudio_dll.Pa_CountDevices = (type_Pa_CountDevices)GetProcAddress(h_portaudio_dll,"Pa_CountDevices");
573 if(!portaudio_dll.Pa_CountDevices){ free_portaudio_dll(); return -1; }
574 portaudio_dll.Pa_GetDefaultInputDeviceID = (type_Pa_GetDefaultInputDeviceID)GetProcAddress(h_portaudio_dll,"Pa_GetDefaultInputDeviceID");
575 if(!portaudio_dll.Pa_GetDefaultInputDeviceID){ free_portaudio_dll(); return -1; }
576 portaudio_dll.Pa_GetDefaultOutputDeviceID = (type_Pa_GetDefaultOutputDeviceID)GetProcAddress(h_portaudio_dll,"Pa_GetDefaultOutputDeviceID");
577 if(!portaudio_dll.Pa_GetDefaultOutputDeviceID){ free_portaudio_dll(); return -1; }
578 portaudio_dll.Pa_GetDeviceInfo = (type_Pa_GetDeviceInfo)GetProcAddress(h_portaudio_dll,"Pa_GetDeviceInfo");
579 if(!portaudio_dll.Pa_GetDeviceInfo){ free_portaudio_dll(); return -1; }
580 portaudio_dll.Pa_OpenStream = (type_Pa_OpenStream)GetProcAddress(h_portaudio_dll,"Pa_OpenStream");
581 if(!portaudio_dll.Pa_OpenStream){ free_portaudio_dll(); return -1; }
582 portaudio_dll.Pa_OpenDefaultStream = (type_Pa_OpenDefaultStream)GetProcAddress(h_portaudio_dll,"Pa_OpenDefaultStream");
583 if(!portaudio_dll.Pa_OpenDefaultStream){ free_portaudio_dll(); return -1; }
584 portaudio_dll.Pa_CloseStream = (type_Pa_CloseStream)GetProcAddress(h_portaudio_dll,"Pa_CloseStream");
585 if(!portaudio_dll.Pa_CloseStream){ free_portaudio_dll(); return -1; }
586 portaudio_dll.Pa_StartStream = (type_Pa_StartStream)GetProcAddress(h_portaudio_dll,"Pa_StartStream");
587 if(!portaudio_dll.Pa_StartStream){ free_portaudio_dll(); return -1; }
588 portaudio_dll.Pa_StopStream = (type_Pa_StopStream)GetProcAddress(h_portaudio_dll,"Pa_StopStream");
589 if(!portaudio_dll.Pa_StopStream){ free_portaudio_dll(); return -1; }
590 portaudio_dll.Pa_AbortStream = (type_Pa_AbortStream)GetProcAddress(h_portaudio_dll,"Pa_AbortStream");
591 if(!portaudio_dll.Pa_AbortStream){ free_portaudio_dll(); return -1; }
592 portaudio_dll.Pa_StreamActive = (type_Pa_StreamActive)GetProcAddress(h_portaudio_dll,"Pa_StreamActive");
593 if(!portaudio_dll.Pa_StreamActive){ free_portaudio_dll(); return -1; }
594 portaudio_dll.Pa_StreamTime = (type_Pa_StreamTime)GetProcAddress(h_portaudio_dll,"Pa_StreamTime");
595 if(!portaudio_dll.Pa_StreamTime){ free_portaudio_dll(); return -1; }
596 portaudio_dll.Pa_GetCPULoad = (type_Pa_GetCPULoad)GetProcAddress(h_portaudio_dll,"Pa_GetCPULoad");
597 if(!portaudio_dll.Pa_GetCPULoad){ free_portaudio_dll(); return -1; }
598 portaudio_dll.Pa_GetMinNumBuffers = (type_Pa_GetMinNumBuffers)GetProcAddress(h_portaudio_dll,"Pa_GetMinNumBuffers");
599 if(!portaudio_dll.Pa_GetMinNumBuffers){ free_portaudio_dll(); return -1; }
600 portaudio_dll.Pa_Sleep = (type_Pa_Sleep)GetProcAddress(h_portaudio_dll,"Pa_Sleep");
601 if(!portaudio_dll.Pa_Sleep){ free_portaudio_dll(); return -1; }
602 portaudio_dll.Pa_GetSampleSize = (type_Pa_GetSampleSize)GetProcAddress(h_portaudio_dll,"Pa_GetSampleSize");
603 if(!portaudio_dll.Pa_GetSampleSize){ free_portaudio_dll(); return -1; }
604 return 0;
605 }
606
Pa_Initialize(void)607 PaError Pa_Initialize( void )
608 {
609 if(h_portaudio_dll){
610 return portaudio_dll.Pa_Initialize();
611 }
612 return paDeviceUnavailable;
613 }
614
Pa_Terminate(void)615 PaError Pa_Terminate( void )
616 {
617 if(h_portaudio_dll){
618 return portaudio_dll.Pa_Terminate();
619 }
620 return paDeviceUnavailable;
621 }
622
Pa_GetHostError(void)623 long Pa_GetHostError( void )
624 {
625 if(h_portaudio_dll){
626 return portaudio_dll.Pa_GetHostError();
627 }
628 return (long)0;
629 }
630
Pa_GetErrorText(PaError errnum)631 const char* Pa_GetErrorText( PaError errnum )
632 {
633 if(h_portaudio_dll){
634 return portaudio_dll.Pa_GetErrorText(errnum);
635 }
636 return (const char*)0;
637 }
638
Pa_CountDevices(void)639 int Pa_CountDevices( void )
640 {
641 if(h_portaudio_dll){
642 return portaudio_dll.Pa_CountDevices();
643 }
644 return (int)0;
645 }
646
Pa_GetDefaultInputDeviceID(void)647 PaDeviceID Pa_GetDefaultInputDeviceID( void )
648 {
649 if(h_portaudio_dll){
650 return portaudio_dll.Pa_GetDefaultInputDeviceID();
651 }
652 return paNoDevice;
653 }
654
Pa_GetDefaultOutputDeviceID(void)655 PaDeviceID Pa_GetDefaultOutputDeviceID( void )
656 {
657 if(h_portaudio_dll){
658 return portaudio_dll.Pa_GetDefaultOutputDeviceID();
659 }
660 return paNoDevice;
661 }
662
Pa_GetDeviceInfo(PaDeviceID device)663 const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID device )
664 {
665 if(h_portaudio_dll){
666 return portaudio_dll.Pa_GetDeviceInfo(device);
667 }
668 return (const PaDeviceInfo*)0;
669 }
670
Pa_OpenStream(PortAudioStream ** stream,PaDeviceID inputDevice,int numInputChannels,PaSampleFormat inputSampleFormat,void * inputDriverInfo,PaDeviceID outputDevice,int numOutputChannels,PaSampleFormat outputSampleFormat,void * outputDriverInfo,double sampleRate,unsigned long framesPerBuffer,unsigned long numberOfBuffers,PaStreamFlags streamFlags,PortAudioCallback * callback,void * userData)671 PaError Pa_OpenStream( PortAudioStream** stream,PaDeviceID inputDevice,int numInputChannels,PaSampleFormat inputSampleFormat,void *inputDriverInfo,PaDeviceID outputDevice,int numOutputChannels,PaSampleFormat outputSampleFormat,void *outputDriverInfo,double sampleRate,unsigned long framesPerBuffer,unsigned long numberOfBuffers,PaStreamFlags streamFlags,PortAudioCallback *callback,void *userData )
672 {
673 if(h_portaudio_dll){
674 return portaudio_dll.Pa_OpenStream(stream,inputDevice,numInputChannels,inputSampleFormat,inputDriverInfo,outputDevice,numOutputChannels,outputSampleFormat,outputDriverInfo,sampleRate,framesPerBuffer,numberOfBuffers,streamFlags,callback,userData);
675 }
676 return (PaError)0;
677 }
678
Pa_OpenDefaultStream(PortAudioStream ** stream,int numInputChannels,int numOutputChannels,PaSampleFormat sampleFormat,double sampleRate,unsigned long framesPerBuffer,unsigned long numberOfBuffers,PortAudioCallback * callback,void * userData)679 PaError Pa_OpenDefaultStream( PortAudioStream** stream,int numInputChannels,int numOutputChannels,PaSampleFormat sampleFormat,double sampleRate,unsigned long framesPerBuffer,unsigned long numberOfBuffers,PortAudioCallback *callback,void *userData )
680 {
681 if(h_portaudio_dll){
682 return portaudio_dll.Pa_OpenDefaultStream(stream,numInputChannels,numOutputChannels,sampleFormat,sampleRate,framesPerBuffer,numberOfBuffers,callback,userData);
683 }
684 return (PaError)0;
685 }
686
Pa_CloseStream(PortAudioStream * stream)687 PaError Pa_CloseStream( PortAudioStream *stream )
688 {
689 if(h_portaudio_dll){
690 return portaudio_dll.Pa_CloseStream(stream);
691 }
692 return paDeviceUnavailable;
693 }
694
Pa_StartStream(PortAudioStream * stream)695 PaError Pa_StartStream( PortAudioStream *stream )
696 {
697 if(h_portaudio_dll){
698 return portaudio_dll.Pa_StartStream(stream);
699 }
700 return paDeviceUnavailable;
701 }
702
Pa_StopStream(PortAudioStream * stream)703 PaError Pa_StopStream( PortAudioStream *stream )
704 {
705 if(h_portaudio_dll){
706 return portaudio_dll.Pa_StopStream(stream);
707 }
708 return paDeviceUnavailable;
709 }
710
Pa_AbortStream(PortAudioStream * stream)711 PaError Pa_AbortStream( PortAudioStream *stream )
712 {
713 if(h_portaudio_dll){
714 return portaudio_dll.Pa_AbortStream(stream);
715 }
716 return paDeviceUnavailable;
717 }
718
Pa_StreamActive(PortAudioStream * stream)719 PaError Pa_StreamActive( PortAudioStream *stream )
720 {
721 if(h_portaudio_dll){
722 return portaudio_dll.Pa_StreamActive(stream);
723 }
724 return paDeviceUnavailable;
725 }
726
Pa_StreamTime(PortAudioStream * stream)727 PaTimestamp Pa_StreamTime( PortAudioStream *stream )
728 {
729 if(h_portaudio_dll){
730 return portaudio_dll.Pa_StreamTime(stream);
731 }
732 return (PaTimestamp)0;
733 }
734
Pa_GetCPULoad(PortAudioStream * stream)735 double Pa_GetCPULoad( PortAudioStream* stream )
736 {
737 if(h_portaudio_dll){
738 return portaudio_dll.Pa_GetCPULoad(stream);
739 }
740 return (double)0;
741 }
742
Pa_GetMinNumBuffers(int framesPerBuffer,double sampleRate)743 int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate )
744 {
745 if(h_portaudio_dll){
746 return portaudio_dll.Pa_GetMinNumBuffers(framesPerBuffer,sampleRate);
747 }
748 return (int)0;
749 }
750
Pa_Sleep(long msec)751 void Pa_Sleep( long msec )
752 {
753 if(h_portaudio_dll){
754 portaudio_dll.Pa_Sleep(msec);
755 }
756 }
757
Pa_GetSampleSize(PaSampleFormat format)758 PaError Pa_GetSampleSize( PaSampleFormat format )
759 {
760 if(h_portaudio_dll){
761 return portaudio_dll.Pa_GetSampleSize(format);
762 }
763 return paDeviceUnavailable;
764 }
765
766 /***************************************************************/
767 #endif
768
769 #endif /* AU_PORTAUDIO_DLL */
770
771