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
|
//////////////////////////////////////////////////////////////////////////
HINSTANCE pPaDll;
/*
the function pointers to the PortAudio DLLs
*/
PaError (__cdecl* Pa_Initialize)( void );
PaError (__cdecl* Pa_Terminate)( void );
long (__cdecl* Pa_GetHostError)( void );
const char* (__cdecl* Pa_GetErrorText)( PaError );
int (__cdecl* Pa_CountDevices)(void);
PaDeviceID (__cdecl* Pa_GetDefaultInputDeviceID)( void );
PaDeviceID (__cdecl* Pa_GetDefaultOutputDeviceID)( void );
const PaDeviceInfo* (__cdecl* Pa_GetDeviceInfo)( PaDeviceID);
PaError (__cdecl* Pa_OpenStream)(
PortAudioStream ** ,
PaDeviceID ,
int ,
PaSampleFormat ,
void *,
PaDeviceID ,
int ,
PaSampleFormat ,
void *,
double ,
unsigned long ,
unsigned long ,
unsigned long ,
PortAudioCallback *,
void * );
PaError (__cdecl* Pa_OpenDefaultStream)( PortAudioStream** stream,
int numInputChannels,
int numOutputChannels,
PaSampleFormat sampleFormat,
double sampleRate,
unsigned long framesPerBuffer,
unsigned long numberOfBuffers,
PortAudioCallback *callback,
void *userData );
PaError (__cdecl* Pa_CloseStream)( PortAudioStream* );
PaError (__cdecl* Pa_StartStream)( PortAudioStream *stream );
PaError (__cdecl* Pa_StopStream)( PortAudioStream *stream );
PaError (__cdecl* Pa_AbortStream)( PortAudioStream *stream );
PaError (__cdecl* Pa_StreamActive)( PortAudioStream *stream );
PaTimestamp (__cdecl* Pa_StreamTime)( PortAudioStream *stream );
double (__cdecl* Pa_GetCPULoad)( PortAudioStream* stream );
int (__cdecl* Pa_GetMinNumBuffers)( int framesPerBuffer, double sampleRate );
void (__cdecl* Pa_Sleep)( long msec );
PaError (__cdecl* Pa_GetSampleSize)( PaSampleFormat format );
//////////////////////////////////////////////////////////////////////////
...
ZERROR AudioEngine::DirectXSupport(ZBOOL bSupDX)
{
if (bSupDX)
if (CheckForDirectXSupport())
bSupportDirectX = _TRUE;
else
return _NO_SOUND;
else
bSupportDirectX = _FALSE;
return _NO_ERROR;
}
ZBOOL AudioEngine::CheckForDirectXSupport()
{
HMODULE pTestDXLib;
FARPROC pFunctionality;
pTestDXLib=LoadLibrary("DSOUND");
if (pTestDXLib!=NULL) // check if there is a DirectSound
{
pFunctionality = GetProcAddress(pTestDXLib, (char*) 7);
if (pFunctionality!=NULL)
{
FreeLibrary(pTestDXLib);
return _TRUE;
}
else
{
FreeLibrary(pTestDXLib);
return _FALSE;
}
}
else
return _FALSE;
}
ZERROR AudioEngine::LoadPALib()
{
#ifdef _DEBUG
if (bSupportDirectX)
pPaDll = LoadLibrary("PA_DXD");
else
pPaDll = LoadLibrary("PA_MMED");
#else
if (bSupportDirectX)
pPaDll = LoadLibrary("PA_DX");
else
pPaDll = LoadLibrary("PA_MME");
#endif
if (pPaDll!=NULL)
{
Pa_Initialize = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_Initialize");
Pa_Terminate = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_Terminate");
Pa_GetHostError = (long (__cdecl* )( void )) GetProcAddress(pPaDll,"Pa_GetHostError");
Pa_GetErrorText = (const char* (__cdecl* )( PaError )) GetProcAddress(pPaDll,"Pa_GetErrorText");
Pa_CountDevices = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_CountDevices");
Pa_GetDefaultInputDeviceID = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_GetDefaultInputDeviceID");
Pa_GetDefaultOutputDeviceID = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_GetDefaultOutputDeviceID");
Pa_GetDeviceInfo = (const PaDeviceInfo* (__cdecl* )( PaDeviceID)) GetProcAddress(pPaDll,"Pa_GetDeviceInfo");
Pa_OpenStream = ( PaError (__cdecl* )(
PortAudioStream ** ,
PaDeviceID ,
int ,
PaSampleFormat ,
void *,
PaDeviceID ,
int ,
PaSampleFormat ,
void *,
double ,
unsigned long ,
unsigned long ,
unsigned long ,
PortAudioCallback *,
void * )) GetProcAddress(pPaDll,"Pa_OpenStream");
Pa_OpenDefaultStream = (PaError (__cdecl* )( PortAudioStream** ,
int ,
int ,
PaSampleFormat ,
double ,
unsigned long ,
unsigned long ,
PortAudioCallback *,
void * )) GetProcAddress(pPaDll,"Pa_OpenDefaultStream");
Pa_CloseStream = (PaError (__cdecl* )( PortAudioStream* )) GetProcAddress(pPaDll,"Pa_CloseStream");
Pa_StartStream = (PaError (__cdecl* )( PortAudioStream* )) GetProcAddress(pPaDll,"Pa_StartStream");
Pa_StopStream = (PaError (__cdecl* )( PortAudioStream* ))GetProcAddress(pPaDll,"Pa_StopStream");
Pa_AbortStream = (PaError (__cdecl* )( PortAudioStream* )) GetProcAddress(pPaDll,"Pa_AbortStream");
Pa_StreamActive = (PaError (__cdecl* )( PortAudioStream* )) GetProcAddress(pPaDll,"Pa_StreamActive");
Pa_StreamTime = (PaTimestamp (__cdecl* )( PortAudioStream *))GetProcAddress(pPaDll,"Pa_StreamTime");
Pa_GetCPULoad = (double (__cdecl* )( PortAudioStream* ))GetProcAddress(pPaDll,"Pa_GetCPULoad");
Pa_GetMinNumBuffers = (int (__cdecl* )( int , double )) GetProcAddress(pPaDll,"Pa_GetMinNumBuffers");
Pa_Sleep = (void (__cdecl* )( long )) GetProcAddress(pPaDll,"Pa_Sleep");
Pa_GetSampleSize = (PaError (__cdecl* )( PaSampleFormat )) GetProcAddress(pPaDll,"Pa_GetSampleSize");
return _NO_ERROR;
}
else
return _DLL_NOT_FOUND;
}
ZERROR AudioEngine::UnLoadPALib()
{
if (pPaDll!=NULL)
FreeLibrary(pPaDll);
return _NO_ERROR;
}
...
|