-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbflib_sndlib.c
374 lines (338 loc) · 11.5 KB
/
bflib_sndlib.c
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/******************************************************************************/
// Bullfrog Engine Emulation Library - for use to remake classic games like
// Syndicate Wars, Magic Carpet or Dungeon Keeper.
/******************************************************************************/
/** @file bflib_sndlib.c
* Low-level sound and music related routines.
* @par Purpose:
* Hardware wrapper to play music and sound in games.
* @par Comment:
* Windows version os Bullfrog Engine uses Miles Sound System, wrapped
* with WSND7R.DLL. This library contains definitions of the exported functions.
* @author KeeperFX Team
* @date 16 Nov 2008 - 30 Dec 2008
* @par Copying and copyrights:
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
/******************************************************************************/
#include "bflib_sndlib.h"
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include "bflib_basics.h"
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
// Global variables
typedef int (WINAPI *FARPROCI)(int);
typedef int (WINAPI *FARPROCII)(int,int);
typedef int (WINAPI *FARPROCIII)(int,int,int);
typedef int (WINAPI *FARPROCS)(const char *);
typedef int (WINAPI *FARPROCP)(const void *);
typedef int (WINAPI *FARPROCSIII)(const char *,int,int,int);
typedef int (WINAPI *FARPROCIIII)(int,int,int,int);
typedef struct SampleInfo * (WINAPI *FARPROC_PLAY1)(int,int,int,int,int,unsigned char,unsigned char, void *, int);
/******************************************************************************/
// Functions
// GetModuleHandleExA(0,"WSND7R",&hModule); seems not to work
int __stdcall FreeAudio(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_FreeAudio@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of FreeAudio function; skipped."); return 0; }
return proc();
}
int __stdcall SetRedbookVolume(int volume)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_SetRedbookVolume@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of SetRedbookVolume function; skipped."); return 0; }
return ((FARPROCI)proc)(volume);
}
int __stdcall SetSoundMasterVolume(int volume)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_SetSoundMasterVolume@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of SetSoundMasterVolume function; skipped."); return 0; }
return ((FARPROCI)proc)(volume);
}
int __stdcall SetMusicMasterVolume(int volume)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_SetMusicMasterVolume@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of SetMusicMasterVolume function; skipped."); return 0; }
return ((FARPROCI)proc)(volume);
}
int __stdcall GetSoundInstalled(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_GetSoundInstalled@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of GetSoundInstalled function; skipped."); return 0; }
return proc();
}
int __stdcall PlayRedbookTrack(int track)
{
HMODULE hModule;
SYNCDBG(18,"Starting");
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_PlayRedbookTrack@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of PlayRedbookTrack function; skipped."); return 0; }
return ((FARPROCI)proc)(track);
}
int __stdcall MonitorStreamedSoundTrack(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_MonitorStreamedSoundTrack@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of MonitorStreamedSoundTrack function; skipped."); return 0; }
return proc();
}
int __stdcall StopRedbookTrack(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_StopRedbookTrack@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of StopRedbookTrack function; skipped."); return 0; }
return proc();
}
void * __stdcall GetSoundDriver(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_GetSoundDriver@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of GetSoundDriver function; skipped."); return 0; }
return (void *)proc();
}
int __stdcall StopAllSamples(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_StopAllSamples@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of StopAllSamples function; skipped."); return 0; }
return proc();
}
struct SampleInfo * __stdcall GetFirstSampleInfoStructure(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_GetFirstSampleInfoStructure@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of GetFirstSampleInfoStructure function; skipped."); return 0; }
return (struct SampleInfo *)proc();
}
int __stdcall LoadMusic(int i)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_LoadMusic@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of LoadMusic function; skipped."); return 0; }
return ((FARPROCI)proc)(i);
}
int __stdcall InitAudio(void *i)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_InitAudio@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of InitAudio function; skipped."); return 0; }
return ((FARPROCP)proc)(i);
}
int __stdcall SetupAudioOptionDefaults(void *i)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_SetupAudioOptionDefaults@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of SetupAudioOptionDefaults function; skipped."); return 0; }
return ((FARPROCP)proc)(i);
}
int __stdcall PlayStreamedSample(char *fname, int a2, int a3, int a4)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_PlayStreamedSample@16");
if (proc==NULL)
{ ERRORLOG("Can't get address of PlayStreamedSample function; skipped."); return 0; }
return ((FARPROCSIII)proc)(fname, a2, a3, a4);
}
int __stdcall IsSamplePlaying(int a1, int a2, int a3)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_IsSamplePlaying@12");
if (proc==NULL)
{ ERRORLOG("Can't get address of IsSamplePlaying function; skipped."); return 0; }
return (unsigned char)((FARPROCIII)proc)(a1, a2, a3);
}
int __stdcall StopStreamedSample(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_StopStreamedSample@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of StopStreamedSample function; skipped."); return 0; }
return proc();
}
int __stdcall StreamedSampleFinished(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_StreamedSampleFinished@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of StreamedSampleFinished function; skipped."); return 0; }
return proc();
}
int __stdcall SetStreamedSampleVolume(int volume)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_SetStreamedSampleVolume@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of SetStreamedSampleVolume function; skipped."); return 0; }
return ((FARPROCI)proc)(volume);
}
struct SampleInfo * __stdcall GetLastSampleInfoStructure(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_GetLastSampleInfoStructure@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of GetLastSampleInfoStructure function; skipped."); return 0; }
return (struct SampleInfo *)proc();
}
int __stdcall GetCurrentSoundMasterVolume(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_GetCurrentSoundMasterVolume@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of GetCurrentSoundMasterVolume function; skipped."); return 0; }
return proc();
}
int __stdcall StopMusic(void)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_StopMusic@0");
if (proc==NULL)
{ ERRORLOG("Can't get address of StopMusic function; skipped."); return 0; }
return proc();
}
int __stdcall LoadAwe32Soundfont(const char *fname)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_LoadAwe32Soundfont@4");
if (proc==NULL)
{ ERRORLOG("Can't get address of LoadAwe32Soundfont function; skipped."); return 0; }
return ((FARPROCS)proc)(fname);
}
int __stdcall StartMusic(int i,int v)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_StartMusic@8");
if (proc==NULL)
{ ERRORLOG("Can't get address of StartMusic function; skipped."); return 0; }
return ((FARPROCII)proc)(i,v);
}
int __stdcall StopSample(int a,int b)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_StopSample@8");
if (proc==NULL)
{ ERRORLOG("Can't get address of StopSample function; skipped."); return 0; }
return ((FARPROCII)proc)(a,b);
}
int __stdcall SetSampleVolume(int a,int b,int c,int d)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_SetSampleVolume@16");
if (proc==NULL)
{ ERRORLOG("Can't get address of SetSampleVolume function; skipped."); return 0; }
return ((FARPROCIIII)proc)(a,b,c,d);
}
int __stdcall SetSamplePan(int a,int b,int c,int d)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_SetSamplePan@16");
if (proc==NULL)
{ ERRORLOG("Can't get address of SetSamplePan function; skipped."); return 0; }
return ((FARPROCIIII)proc)(a,b,c,d);
}
int __stdcall SetSamplePitch(int a,int b,int c,int d)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_SetSamplePitch@16");
if (proc==NULL)
{ ERRORLOG("Can't get address of SetSamplePitch function; skipped."); return 0; }
return ((FARPROCIIII)proc)(a,b,c,d);
}
struct SampleInfo * __stdcall PlaySampleFromAddress(int a1, int smpl_idx, int a3, int a4, int a5, unsigned char a6, unsigned char a7, void * buf, int sfxid)
{
HMODULE hModule;
hModule=GetModuleHandle("WSND7R");
FARPROC proc;
proc=GetProcAddress(hModule,"_PlaySampleFromAddress@36");
if (proc==NULL)
{ ERRORLOG("Can't get address of PlaySampleFromAddress function; skipped."); return 0; }
return ((FARPROC_PLAY1)proc)(a1, smpl_idx, a3, a4, a5, a6, a7, buf, sfxid);
}
/******************************************************************************/
#ifdef __cplusplus
}
#endif