forked from LemonHaze420/UEFAStriker96
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDAUDIO.C
561 lines (437 loc) · 12.5 KB
/
CDAUDIO.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
/************************************************************************/
/* */
/* Module: Cd audio control */
/* */
/* Author: Rob */
/* */
/* Status: */
/* */
/************************************************************************/
/************************************************************************/
/* */
/* include default headers */
/* */
/************************************************************************/
#include "incs.h"
//#include "include\main.h"
//#include "include\effects.h"
/************************************************************************/
/* */
/* game includes */
/* */
/************************************************************************/
/************************************************************************/
/* */
/* prototypes */
/* */
/************************************************************************/
void set_audio_global_vars();
void install_cd_volume( void );
void set_cd_audio( WORD control );
void check_audio_track( void );
WORD init_xa_audio( void );
WORD cdplay( void );
void set_audio_channel( WORD channel );
WORD play_xa_audio_track( WORD track );
WORD cd_ff( LONG many );
void cdseek( LONG pos );
WORD seekdone( void );
void wait_cdseek( void );
WORD audio_track_ready( void );
void ready_audio_track( WORD track );
void save_audio_track_pos( void );
void inter_play( void );
void do_cd_fade( void );
void set_cd_volume( void );
void modify_cd_volume( WORD volume );
/************************************************************************/
/* */
/* defs */
/* */
/************************************************************************/
#define CDAUDIO
/******************************************************************/
/* cd audio defs */
/******************************************************************/
#define CD_POLL_TIME 30
#define AUDIO_CLICK_RETRY 20
#define CD_FADE_SPEED 12
#define CD_EVENT_READY 1
#define NEED_NEXT_CD_EVENT 1
#define WAIT_FADE 1
#define WAIT_SEEK 2
#define SECONDARY_AUDIO_TRACK_READY 3
#define RESTORE_LAST_TRACK 4
#define RESTORE_LAST_CHANNEL 5
/************************************************************************/
/* */
/* vars */
/* */
/************************************************************************/
WORD cd_volume, cd_volume_offset, cd_stereo, cd_fade_volume,cd_volume_setting;
WORD cd_base_volume;
LONG audio_track_start, audio_track_end, audio_track_pos;
LONG save_pos,save_pos_start,save_pos_end;
LONG audio_bank_1_start,audio_bank_2_start;
LONG audio_track_end_reload;
LONG cd_param,cd_event_control;
WORD audio_check_poll;
WORD audio_click;
WORD audio_control,next_track,current_audio_channel,save_channel;
WORD cd_playing = FALSE;
CdlLOC g_loc;
WORD cd_initialised = YES;
WORD audio_track;
/************************************************************************/
/* */
/* constant data */
/* */
/************************************************************************/
Audio_track available_audio_tracks[] =
{
0,0,0,45000,250, // republica
0,1,0,699*150,250, // jarre
0,2,0,752*150,250, // maddona
0,3,0,40000,250, // odwod
0,4,0,999999,250,
0,5,0,999999,250,
0,6,0,999999,250,
0,7,0,999999,250,
};
/************************************************************************/
/* setup cd audio */
/************************************************************************/
WORD init_xa_audio( void )
{
#ifdef CDAUDIO
CdlFILE fp;
WORD c;
audio_track = -1;
/*********************************************************************/
/* find cd audio bank 1 */
/*********************************************************************/
if (CdSearchFile( &fp, "\\CDAUDIO.XA;1" ) == 0)
{
printf(" cant find audio bank 1\n");
return FALSE;
}
audio_bank_1_start = CdPosToInt(&fp.pos);
CdPause();
cd_volume = 0;
#endif
return YES;
}
/************************************************************************/
/* setup cd audio, mono/stereo etc */
/* control- MONO mono output */
/* STEREO ( OR LEFT_RIGHT ) normal stereo */
/* RIGHT_LEFT inverse stereo */
/* 0 off */
/************************************************************************/
void set_stereo_mode( WORD stereo )
{
cd_stereo = stereo;
}
/************************************************************************/
/* plays an interleaved xa audio track */
/* */
/* */
/************************************************************************/
WORD play_xa_audio_track( WORD track )
{
CdlFILE fp;
Audio_track *at;
UBYTE param[4];
WORD stat;
if( cd_initialised == TRUE )
{
at = &available_audio_tracks[ track ];
audio_track = track;
#ifdef DT
printf(" start audio track %d",track);
#endif
if( at -> audio_bank == 0 )
audio_track_start = audio_bank_1_start + at -> start;
else
audio_track_start = audio_bank_2_start + at -> start;
audio_track_end = audio_track_start + at -> end;
audio_track_pos = audio_track_start;
/*********************************************************************/
/* set soundtrack volume adjust */
/*********************************************************************/
// cd_volume = at -> volume;
// cd_fade_volume = at -> volume;
// cd_volume_setting = at -> volume;
// set_cd_volume( cd_volume );
/*********************************************************************/
/* set cd mode & speed */
/*********************************************************************/
param[0] = CdlModeSpeed|CdlModeRT|CdlModeSF;
CdControlB(CdlSetmode, param, 0);
set_audio_channel( at -> channel );
cdseek( audio_track_start );
wait_cdseek();
cdplay();
if( cd_playing == FALSE )
{
cd_playing = TRUE;
}
stat = TRUE;
}
else
{
printf("request for audio track when cd hasn't been initialised!!\n");
stat = FALSE;
}
set_audio_global_vars();
return stat;
}
WORD stop_xa_audio( void )
{
CdPause();
cd_playing = FALSE;
check_audio_track();
}
/************************************************************************/
/* save current audio track position */
/************************************************************************/
/************************************************************************/
/* set cd read position */
/************************************************************************/
void cdseek( LONG pos )
{
CdIntToPos( pos, &g_loc);
CdControlF( CdlSeekP, (UBYTE *)&g_loc );
}
/************************************************************************/
/* wait for cd seek */
/************************************************************************/
void wait_cdseek( void )
{
while( seekdone() == FALSE )
{
VSync(0);
}
return;
}
/************************************************************************/
/* return last seek status */
/************************************************************************/
WORD seekdone( void )
{
UBYTE result[8];
if( CdSync(1, result) == CdlComplete )
{
return TRUE;
}
return FALSE;
}
/************************************************************************/
/* set audio channel */
/************************************************************************/
void set_audio_channel( WORD channel )
{
CdlFILTER filter;
UBYTE result[8];
filter.file = 1;
filter.chan = channel;
CdControlB(CdlSetfilter, (UBYTE *)&filter, result );
current_audio_channel = channel;
}
/************************************************************************/
/* play audio track */
/************************************************************************/
WORD cdplay( void )
{
CdControlF( CdlReadS, 0);
}
/************************************************************************/
/* fast foreward cd */
/************************************************************************/
WORD cd_ff( LONG many )
{
CdlLOC loc;
audio_track_pos += many;
CdIntToPos( audio_track_pos, &loc);
if (CdControl( CdlReadS, (UBYTE *)&loc, 0) != 1)
return( FALSE );
return YES;
}
void modify_cd_volume( WORD volume )
{
CdlATV vol;
if( cd_stereo & LEFT_RIGHT )
{
vol.val0 = (UBYTE)volume;
vol.val2 = (UBYTE)volume;
vol.val1 =
vol.val3 = 0;
}
if( cd_stereo & RIGHT_LEFT )
{
vol.val1 = (UBYTE)volume;
vol.val3 = (UBYTE)volume;
vol.val0 =
vol.val2 = 0;
}
CdMix( &vol );
}
void set_cd_volume( void )
{
CdlATV vol;
WORD volume;
volume = config -> cd_volume;
if( volume > 255 )
volume = 255;
cd_volume =
cd_fade_volume = volume;
if( cd_stereo & LEFT_RIGHT )
{
vol.val0 = (UBYTE)volume;
vol.val2 = (UBYTE)volume;
vol.val1 =
vol.val3 = 0;
}
if( cd_stereo & RIGHT_LEFT )
{
vol.val1 = (UBYTE)volume;
vol.val3 = (UBYTE)volume;
vol.val0 =
vol.val2 = 0;
}
CdMix( &vol );
}
WORD bob_audio = 0;
WORD bob_ff = 0;
LONG bob_audio_pos = 0;
UBYTE g_param[4];
/************************************************************************/
/* check audio track for loop */
/************************************************************************/
void check_audio_track( void )
{
UBYTE result[8];
LONG cnt, ret;
#ifndef CDAUDIO
return;
#endif
// FntPrint("check audio track\n");
if( bob_ff < 0 )
{
bob_ff = 0;
cd_ff( -1000 );
}
if( bob_ff > 0 )
{
bob_ff = 0;
cd_ff( 1000 );
}
bob_audio_pos = audio_track_pos - audio_track_start;
if( audio_check_poll != -2 )
{
if( audio_check_poll == -1 )
{
if( seekdone() == TRUE )
{
cdplay();
audio_check_poll = 0;
}
}
else
{
if( audio_check_poll++ > CD_POLL_TIME )
audio_check_poll = 0;
if( audio_check_poll == ( CD_POLL_TIME / 2 ) )
{
CdControlF(CdlGetlocP, g_param );
}
else
if( audio_check_poll == CD_POLL_TIME )
{
ret = CdSync(1, result);
if( ret == CdlDiskError )
{
if( audio_click++ == AUDIO_CLICK_RETRY )
{
/*********************************************************/
/* disk read failed / could be cack bit or top opened. */
/* forward it a bit anyway */
/*********************************************************/
cd_ff( 1000 );
audio_click = 0;
}
}
else
if( ret == CdlComplete )
{
if( CdLastCom() == CdlGetlocP &&
(cnt = CdPosToInt((CdlLOC *)&result[5])) > 0)
{
audio_track_pos = cnt;
if( audio_track_pos >= audio_track_end )
{
/************************************************/
/* end of track */
/************************************************/
if( audio_control == RESTORE_LAST_CHANNEL )
{
set_audio_channel( save_channel );
cd_fade_volume = 0;
cd_volume = 1;
audio_control = RESTORE_LAST_TRACK;
}
else
if( audio_control == RESTORE_LAST_TRACK )
{
audio_control = 0;
audio_track_start = save_pos_start;
audio_track_end = save_pos_end;
cdseek( save_pos );
cd_fade_volume = cd_volume_setting;
cd_volume = 0;
audio_check_poll = -1;
}
else
{
cdseek( audio_track_start );
audio_check_poll = -1;
}
}
}
}
}
}
}
do_cd_fade();
}
void do_cd_fade( void )
{
if( cd_fade_volume != cd_volume )
{
if( cd_fade_volume < cd_volume )
{
cd_volume -= CD_FADE_SPEED;
if( cd_volume < cd_fade_volume )
cd_volume = cd_fade_volume;
}
if( cd_fade_volume > cd_volume )
{
cd_volume += CD_FADE_SPEED;
if( cd_volume > cd_fade_volume )
cd_volume = cd_fade_volume;
}
modify_cd_volume( cd_volume );
}
}
void set_audio_global_vars()
{
config->cd_volume = (config->music_volume * config->master_volume ) / 255;
if ( config->sound_mode == 0 )
set_stereo_mode( MONO );
if ( config->sound_mode == 1 )
set_stereo_mode( STEREO );
if ( config->sound_mode == 2 )
set_stereo_mode( RIGHT_LEFT ); // inverse stereo
set_cd_volume();
}