2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Routines to manage the songs in Descent.
29 #if !defined(_MSC_VER) && !defined(macintosh)
42 song_info Songs[MAX_NUM_SONGS];
43 int Songs_initialized = 0;
49 extern void digi_stop_current_song();
51 cvar_t Redbook_enabled = { "RedbookEnabled", "1", 1 };
53 //0 if redbook is no playing, else the track number
54 int Redbook_playing = 0;
56 #define NumLevelSongs (Num_songs - SONG_FIRST_LEVEL_SONG)
58 extern int CD_blast_mixer();
61 #define REDBOOK_VOLUME_SCALE (255/3) //255 is MAX
63 #define REDBOOK_VOLUME_SCALE (255)
66 //takes volume in range 0..8
67 void set_redbook_volume(int volume)
70 RBASetVolume(0); // makes the macs sound really funny
72 RBASetVolume(volume*REDBOOK_VOLUME_SCALE/8);
75 extern char CDROM_dir[];
83 if ( Songs_initialized ) return;
86 #if !defined(MACINTOSH) && !defined(WINDOWS) // don't crank it if on a macintosh!!!!!
87 if (!FindArg("-nomixer"))
88 CD_blast_mixer(); // Crank it!
92 if (cfexist("descent.sng")) { // mac (demo?) datafiles don't have the .sng file
93 fp = cfopen( "descent.sng", "rb" );
96 Error( "Couldn't open descent.sng" );
99 while (cfgets(inputline, 80, fp ))
101 if ( strlen( inputline ) )
103 Assert( i < MAX_NUM_SONGS );
104 sscanf( inputline, "%s %s %s",
106 Songs[i].melodic_bank_file,
107 Songs[i].drum_bank_file );
108 //printf( "%d. '%s' '%s' '%s'\n",i,Songs[i].filename,Songs[i].melodic_bank_file,Songs[i].drum_bank_file );
113 if (Num_songs <= SONG_FIRST_LEVEL_SONG)
114 Error("Must have at least %d songs",SONG_FIRST_LEVEL_SONG+1);
118 Songs_initialized = 1;
121 if (FindArg("-noredbook"))
123 cvar_setint( &Redbook_enabled, 0 );
130 RBAInit(toupper(CDROM_dir[0]) - 'A');
135 set_redbook_volume(Config_redbook_volume.intval);
139 atexit(RBAStop); // stop song on exit
142 #define FADE_TIME (f1_0/2)
144 //stop the redbook, so we can read off the CD
145 void songs_stop_redbook(void)
147 int old_volume = Config_redbook_volume.intval * REDBOOK_VOLUME_SCALE / 8;
148 fix old_time = timer_get_fixed_seconds();
150 if (Redbook_playing) { //fade out volume
153 fix t = timer_get_fixed_seconds();
155 new_volume = fixmuldiv(old_volume,(FADE_TIME - (t-old_time)),FADE_TIME);
160 RBASetVolume(new_volume);
162 } while (new_volume > 0);
165 RBAStop(); // Stop CD, if playing
167 RBASetVolume(old_volume); //restore volume
173 //stop any songs - midi or redbook - that are currently playing
174 void songs_stop_all(void)
176 digi_stop_current_song(); // Stop midi song, if playing
178 songs_stop_redbook(); // Stop CD, if playing
181 int force_rb_register=0;
183 void reinit_redbook()
188 RBAInit(toupper(CDROM_dir[0]) - 'A');
193 set_redbook_volume(Config_redbook_volume.intval);
200 //returns 1 if track started sucessfully
201 //start at tracknum. if keep_playing set, play to end of disc. else
202 //play only specified track
203 int play_redbook_track(int tracknum,int keep_playing)
207 if (!RBAEnabled() && Redbook_enabled.intval && !FindArg("-noredbook"))
210 if (force_rb_register) {
211 RBARegisterCD(); //get new track list for new CD
212 force_rb_register = 0;
215 if (Redbook_enabled.intval && RBAEnabled()) {
216 int num_tracks = RBAGetNumberOfTracks();
217 if (tracknum <= num_tracks)
218 if (RBAPlayTracks(tracknum,keep_playing?num_tracks:tracknum)) {
219 Redbook_playing = tracknum;
223 return (Redbook_playing != 0);
229 #define REDBOOK_TITLE_TRACK 2
230 #define REDBOOK_CREDITS_TRACK 3
231 #define REDBOOK_FIRST_LEVEL_TRACK (songs_haved2_cd()?4:1)
233 // songs_haved2_cd returns 1 if the descent 2 CD is in the drive and
235 int songs_haved2_cd()
237 char temp[128],cwd[128];
241 strcpy(temp,CDROM_dir);
243 #ifndef MACINTOSH //for PC, strip of trailing slash
244 if (temp[strlen(temp)-1] == '\\')
245 temp[strlen(temp)-1] = 0;
248 if ( !chdir(temp) ) {
259 /* Redbook versions of 13 songs from Descent 1 as found on the Macintosh version.
260 All the same tracklist, but some versions have tracks mixed to different lengths
264 4: The Escape (aka Close Call)
265 5: Ether in the Air (aka The Darkness of Space)
266 6: Robotic Menace (aka Get It On)
267 7: Virtual Tension (aka Fight)
268 8: Time for the Big Guns (aka Death Lurks Beneath)
269 9: Mystery Metal (aka C-4 Home Recipe)
270 10: Hydraulic Pressure (aka Escape)
271 11: Not That Button! (aka Backwards Time)
272 12: Industrial Accident (aka Crazyfactory)
273 13: Overdrive (aka Machine Gun)
274 14: A Big Problem (aka Insanity)
276 #define D1_DISCID_1 0xb60d990e
277 #define D1_DISCID_2 0xde0feb0e
278 #define D1_DISCID_3 0xb70ee40e
280 #define D1_RB_TITLE 2
281 #define D1_RB_BRIEFING 3
282 #define D1_RB_ENDLEVEL 4
283 #define D1_RB_ENDGAME 3
284 #define D1_RB_CREDITS 5
285 #define D1_RB_FIRST_LEVEL_SONG 6
297 10: Haunted (Instrumental Remix)
302 #define D2_DISCID_1 0x22115710 // Mac version, has some extended versions and 3 bonus tracks
303 #define D2_DISCID_2 0xac0bc30d
304 #define D2_DISCID_3 0xc40c0a0d
305 #define D2_DISCID_4 0xc610080d
306 #define D2_DISCID_5 0xcc101b0d
307 #define D2_DISCID_6 0xd00bf30d
308 #define D2_DISCID_7 0xd2101d0d
309 #define D2_DISCID_8 0xd410070d
310 #define D2_DISCID_9 0xda10370d
312 #define D2_RB_TITLE 2
313 #define D2_RB_CREDITS 3
314 #define D2_RB_FIRST_LEVEL_SONG 4
316 /* Same as above, but all tracks shifted by one
327 11: Haunted (Instrumental Remix)
332 #define D2_2_DISCID_1 0xe010a30e
334 #define D2_2_RB_TITLE 3
335 #define D2_2_RB_CREDITS 4
336 #define D2_2_RB_FIRST_LEVEL_SONG 5
338 /* Descent II: The Infinite Abyss
341 3: Cold Reality - Extended Remix
342 4: Crawl - Extended Remix
343 5: Gunner Down - Extended Remix
344 6: Ratzez - Extended Remix
345 7: Techno Industry - Extended Remix
346 8: Are You Descent? - Extended Remix
347 9: Robot Jungle - Extended Remix
349 #define D2_IA_DISCID_1 0x7d0ff809
350 #define D2_IA_DISCID_2 0x8110ec09
351 #define D2_IA_DISCID_3 0x82104909
352 #define D2_IA_DISCID_4 0x85101d09
353 #define D2_IA_DISCID_5 0x87102209
355 #define D2_IA_RB_TITLE 2
356 #define D2_IA_RB_CREDITS 3
357 #define D2_IA_RB_FIRST_LEVEL_SONG 4
359 /* Descent II: Vertigo Series
361 2: Crush - Extended Remix
362 3: Glut - Extended Remix
363 4: Haunted - Instrumental Re-Remix
365 6: Untitled - Extended Remix
369 #define D2_X_DISCID_1 0x53078208
370 #define D2_X_DISCID_2 0x64071408
372 #define D2_X_RB_FIRST_LEVEL_SONG 2
375 int songs_redbook_track(int songnum)
379 if (!Redbook_enabled.intval)
382 discid = RBAGetDiscID();
389 case SONG_TITLE: return D1_RB_TITLE;
390 case SONG_BRIEFING: return D1_RB_BRIEFING;
391 case SONG_ENDLEVEL: return D1_RB_ENDLEVEL;
392 case SONG_ENDGAME: return D1_RB_ENDGAME;
393 case SONG_CREDITS: return D1_RB_CREDITS;
394 case SONG_FIRST_LEVEL_SONG: return D1_RB_FIRST_LEVEL_SONG;
395 default: Int3(); break;
407 case SONG_TITLE: return D2_RB_TITLE;
408 case SONG_CREDITS: return D2_RB_CREDITS;
409 case SONG_FIRST_LEVEL_SONG: return D2_RB_FIRST_LEVEL_SONG;
410 default: Int3(); break;
414 case SONG_TITLE: return D2_2_RB_TITLE;
415 case SONG_CREDITS: return D2_2_RB_CREDITS;
416 case SONG_FIRST_LEVEL_SONG: return D2_2_RB_FIRST_LEVEL_SONG;
417 default: Int3(); break;
425 case SONG_TITLE: return D2_IA_RB_TITLE;
426 case SONG_CREDITS: return D2_IA_RB_CREDITS;
427 case SONG_FIRST_LEVEL_SONG: return D2_IA_RB_FIRST_LEVEL_SONG;
428 default: Int3(); break;
432 return D2_X_RB_FIRST_LEVEL_SONG;
435 con_printf(CON_DEBUG, "Unknown CD. discid: %x\n", discid);
441 #define REDBOOK_TITLE_TRACK (songs_redbook_track(SONG_TITLE))
442 #define REDBOOK_CREDITS_TRACK (songs_redbook_track(SONG_CREDITS))
443 #define REDBOOK_FIRST_LEVEL_TRACK (songs_redbook_track(SONG_FIRST_LEVEL_SONG))
448 void songs_play_song( int songnum, int repeat )
451 //Assert(songnum != SONG_ENDLEVEL && songnum != SONG_ENDGAME); //not in full version
454 if ( !Songs_initialized )
457 //stop any music already playing
461 //do we want any of these to be redbook songs?
463 if (force_rb_register) {
464 RBARegisterCD(); //get new track list for new CD
465 force_rb_register = 0;
468 if (songnum == SONG_TITLE)
469 play_redbook_track(REDBOOK_TITLE_TRACK,0);
470 else if (songnum == SONG_CREDITS)
471 play_redbook_track(REDBOOK_CREDITS_TRACK,0);
473 if (!Redbook_playing) // not playing redbook, so play midi
474 digi_play_midi_song( Songs[songnum].filename, Songs[songnum].melodic_bank_file, Songs[songnum].drum_bank_file, repeat );
477 int current_song_level;
479 void songs_play_level_song( int levelnum )
484 Assert( levelnum != 0 );
486 if ( !Songs_initialized )
491 current_song_level = levelnum;
493 songnum = (levelnum>0)?(levelnum-1):(-levelnum);
495 if (!RBAEnabled() && Redbook_enabled.intval && !FindArg("-noredbook"))
498 if (force_rb_register) {
499 RBARegisterCD(); //get new track list for new CD
500 force_rb_register = 0;
503 if (Redbook_enabled.intval && RBAEnabled() && (n_tracks = RBAGetNumberOfTracks()) > 1) {
505 //try to play redbook
507 mprintf((0,"n_tracks = %d\n",n_tracks));
509 play_redbook_track(REDBOOK_FIRST_LEVEL_TRACK + (songnum % (n_tracks-REDBOOK_FIRST_LEVEL_TRACK+1)),1);
512 if (! Redbook_playing) { //not playing redbook, so play midi
514 songnum = SONG_FIRST_LEVEL_SONG + (songnum % NumLevelSongs);
516 digi_play_midi_song( Songs[songnum].filename, Songs[songnum].melodic_bank_file, Songs[songnum].drum_bank_file, 1 );
521 //this should be called regularly to check for redbook restart
522 void songs_check_redbook_repeat()
524 static fix last_check_time;
527 if (!Redbook_playing || Config_redbook_volume.intval==0) return;
529 current_time = timer_get_fixed_seconds();
530 if (current_time < last_check_time || (current_time - last_check_time) >= F2_0) {
531 if (!RBAPeekPlayStatus()) {
533 // if title ends, start credit music
534 // if credits music ends, restart it
535 if (Redbook_playing == REDBOOK_TITLE_TRACK || Redbook_playing == REDBOOK_CREDITS_TRACK)
536 play_redbook_track(REDBOOK_CREDITS_TRACK,0);
538 //songs_goto_next_song();
540 //new code plays all tracks to end of disk, so if disk has
541 //stopped we must be at end. So start again with level 1 song.
543 songs_play_level_song(1);
547 last_check_time = current_time;
551 //goto the next level song
552 void songs_goto_next_song()
554 if (Redbook_playing) //get correct track
555 current_song_level = RBAGetTrackNum() - REDBOOK_FIRST_LEVEL_TRACK + 1;
557 songs_play_level_song(current_song_level+1);
561 //goto the previous level song
562 void songs_goto_prev_song()
564 if (Redbook_playing) //get correct track
565 current_song_level = RBAGetTrackNum() - REDBOOK_FIRST_LEVEL_TRACK + 1;
567 if (current_song_level > 1)
568 songs_play_level_song(current_song_level-1);