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.
54 #define SOF_USED 1 // Set if this sample is used
55 #define SOF_PLAYING 2 // Set if this sample is playing on a channel
56 #define SOF_LINK_TO_OBJ 4 // Sound is linked to a moving object. If object dies, then finishes play and quits.
57 #define SOF_LINK_TO_POS 8 // Sound is linked to segment, pos
58 #define SOF_PLAY_FOREVER 16 // Play forever (or until level is stopped), otherwise plays once
59 #define SOF_PERMANENT 32 // Part of the level, like a waterfall or fan
61 typedef struct sound_object {
62 short signature; // A unique signature to this sound
63 ubyte flags; // Used to tell if this slot is used and/or currently playing, and how long.
64 ubyte pad; // Keep alignment
65 fix max_volume; // Max volume that this sound is playing at
66 fix max_distance; // The max distance that this sound can be heard at...
67 int volume; // Volume that this sound is playing at
68 int pan; // Pan value that this sound is playing at
69 int channel; // What channel this is playing on, -1 if not playing
70 short soundnum; // The sound number that is playing
71 int loop_start; // The start point of the loop. -1 means no loop
72 int loop_end; // The end point of the loop
75 short segnum; // Used if SOF_LINK_TO_POS field is used
80 short objnum; // Used if SOF_LINK_TO_OBJ field is used
86 #define MAX_SOUND_OBJECTS 150
87 sound_object SoundObjects[MAX_SOUND_OBJECTS];
88 short next_signature=0;
90 int N_active_sound_objects=0;
92 int digi_sounds_initialized=0;
96 /* Find the sound which actually equates to a sound number */
97 int digi_xlat_sound(int soundno)
104 soundno = AltSounds[soundno];
109 Assert(Sounds[soundno] != 255); //if hit this, probably using undefined sound
111 return Sounds[soundno];
114 int digi_unxlat_sound(int soundno)
117 ubyte *table = (digi_lomem?AltSounds:Sounds);
119 if ( soundno < 0 ) return -1;
121 for (i=0;i<MAX_SOUNDS;i++)
122 if (table[i] == soundno)
130 void digi_get_sound_loc( vms_matrix * listener, vms_vector * listener_pos, int listener_seg, vms_vector * sound_pos, int sound_seg, fix max_volume, int *volume, int *pan, fix max_distance )
133 vms_vector vector_to_sound;
134 fix angle_from_ear, cosang,sinang;
141 max_distance = (max_distance*5)/4; // Make all sounds travel 1.25 times as far.
143 // Warning: Made the vm_vec_normalized_dir be vm_vec_normalized_dir_quick and got illegal values to acos in the fang computation.
144 distance = vm_vec_normalized_dir_quick( &vector_to_sound, sound_pos, listener_pos );
146 if (distance < max_distance ) {
147 int num_search_segs = f2i(max_distance/20);
148 if ( num_search_segs < 1 ) num_search_segs = 1;
150 path_distance = find_connected_distance(listener_pos, listener_seg, sound_pos, sound_seg, num_search_segs, WID_RENDPAST_FLAG+WID_FLY_FLAG );
151 if ( path_distance > -1 ) {
152 *volume = max_volume - fixdiv(path_distance,max_distance);
153 //mprintf( (0, "Sound path distance %.2f, volume is %d / %d\n", f2fl(distance), *volume, max_volume ));
155 angle_from_ear = vm_vec_delta_ang_norm(&listener->rvec,&vector_to_sound,&listener->uvec);
156 fix_sincos(angle_from_ear,&sinang,&cosang);
157 //mprintf( (0, "volume is %.2f\n", f2fl(*volume) ));
158 if (Config_channels_reversed.intval) cosang *= -1;
159 *pan = (cosang + F1_0)/2;
168 void digi_play_sample_once( int soundno, fix max_volume )
173 if ( Newdemo_state == ND_STATE_RECORDING )
174 newdemo_record_sound( soundno );
176 soundno = digi_xlat_sound(soundno);
178 if (soundno < 0 ) return;
180 channel=digi_find_channel(soundno);
182 digi_stop_sound( channel );
184 // start the sample playing
185 digi_start_sound( soundno, max_volume, 0xffff/2, 0, -1, -1, -1 );
189 void digi_play_sample( int soundno, fix max_volume )
192 if ( Newdemo_state == ND_STATE_RECORDING )
193 newdemo_record_sound( soundno );
195 soundno = digi_xlat_sound(soundno);
197 if (soundno < 0 ) return;
199 // start the sample playing
200 digi_start_sound( soundno, max_volume, 0xffff/2, 0, -1, -1, -1 );
204 void digi_play_sample_3d( int soundno, int angle, int volume, int no_dups )
210 if ( Newdemo_state == ND_STATE_RECORDING ) {
212 newdemo_record_sound_3d_once( soundno, angle, volume );
214 newdemo_record_sound_3d( soundno, angle, volume );
217 soundno = digi_xlat_sound(soundno);
219 if (soundno < 0 ) return;
221 if (volume < 10 ) return;
223 // start the sample playing
224 digi_start_sound( soundno, volume, angle, 0, -1, -1, -1 );
229 void SoundQ_process();
232 void digi_init_sounds()
238 digi_stop_all_channels();
240 digi_stop_looping_sound();
241 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
242 SoundObjects[i].channel = -1;
243 SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
245 N_active_sound_objects = 0;
246 digi_sounds_initialized = 1;
249 extern int digi_max_channels;
251 // plays a sample that loops forever.
252 // Call digi_stop_channe(channel) to stop it.
253 // Call digi_set_channel_volume(channel, volume) to change volume.
254 // if loop_start is -1, entire sample loops
255 // Returns the channel that sound is playing on, or -1 if can't play.
256 // This could happen because of no sound drivers loaded or not enough channels.
257 int digi_looping_sound = -1;
258 int digi_looping_volume = 0;
259 int digi_looping_start = -1;
260 int digi_looping_end = -1;
261 int digi_looping_channel = -1;
263 void digi_play_sample_looping_sub()
265 if ( digi_looping_sound > -1 )
266 digi_looping_channel = digi_start_sound( digi_looping_sound, digi_looping_volume, 0xFFFF/2, 1, digi_looping_start, digi_looping_end, -1 );
269 void digi_play_sample_looping( int soundno, fix max_volume,int loop_start, int loop_end )
271 soundno = digi_xlat_sound(soundno);
273 if (soundno < 0 ) return;
275 if (digi_looping_channel>-1)
276 digi_stop_sound( digi_looping_channel );
278 digi_looping_sound = soundno;
279 digi_looping_volume = max_volume;
280 digi_looping_start = loop_start;
281 digi_looping_end = loop_end;
282 digi_play_sample_looping_sub();
285 void digi_change_looping_volume( fix volume )
287 if ( digi_looping_channel > -1 )
288 digi_set_channel_volume( digi_looping_channel, volume );
289 digi_looping_volume = volume;
292 void digi_stop_looping_sound()
294 if ( digi_looping_channel > -1 )
295 digi_stop_sound( digi_looping_channel );
296 digi_looping_channel = -1;
297 digi_looping_sound = -1;
300 void digi_pause_looping_sound()
302 if ( digi_looping_channel > -1 )
303 digi_stop_sound( digi_looping_channel );
304 digi_looping_channel = -1;
307 void digi_unpause_looping_sound()
309 digi_play_sample_looping_sub();
312 //hack to not start object when loading level
313 int Dont_start_sound_objects = 0;
315 void digi_start_sound_object(int i)
317 // start sample structures
318 SoundObjects[i].channel = -1;
320 if ( SoundObjects[i].volume <= 0 )
323 if ( Dont_start_sound_objects )
326 // -- MK, 2/22/96 -- if ( Newdemo_state == ND_STATE_RECORDING )
327 // -- MK, 2/22/96 -- newdemo_record_sound_3d_once( digi_unxlat_sound(SoundObjects[i].soundnum), SoundObjects[i].pan, SoundObjects[i].volume );
329 // only use up to half the sound channels for "permanent" sounts
330 if ((SoundObjects[i].flags & SOF_PERMANENT) && (N_active_sound_objects >= max(1, digi_get_max_channels() / 4)))
333 // start the sample playing
335 SoundObjects[i].channel = digi_start_sound( SoundObjects[i].soundnum,
336 SoundObjects[i].volume,
338 SoundObjects[i].flags & SOF_PLAY_FOREVER,
339 SoundObjects[i].loop_start,
340 SoundObjects[i].loop_end, i );
342 if (SoundObjects[i].channel > -1 )
343 N_active_sound_objects++;
346 //sounds longer than this get their 3d aspects updated
347 #define SOUND_3D_THRESHHOLD (digi_sample_rate * 3 / 2) //1.5 seconds
349 int digi_link_sound_to_object3( int org_soundnum, short objnum, int forever, fix max_volume, fix max_distance, int loop_start, int loop_end )
356 soundnum = digi_xlat_sound(org_soundnum);
358 if ( max_volume < 0 ) return -1;
359 // if ( max_volume > F1_0 ) max_volume = F1_0;
361 if (soundnum < 0 ) return -1;
362 if (GameSounds[soundnum].data==NULL) {
366 if ((objnum<0)||(objnum>Highest_object_index))
369 if ( !forever ) { // && GameSounds[soundnum - SOUND_OFFSET].length < SOUND_3D_THRESHHOLD) {
370 // Hack to keep sounds from building up...
371 digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &Objects[objnum].pos, Objects[objnum].segnum, max_volume,&volume, &pan, max_distance );
372 digi_play_sample_3d( org_soundnum, pan, volume, 0 );
377 if ( Newdemo_state == ND_STATE_RECORDING ) {
378 newdemo_record_link_sound_to_object3( org_soundnum, objnum, max_volume, max_distance, loop_start, loop_end );
382 for (i=0; i<MAX_SOUND_OBJECTS; i++ )
383 if (SoundObjects[i].flags==0)
386 if (i==MAX_SOUND_OBJECTS) {
387 mprintf((1, "Too many sound objects!\n" ));
391 SoundObjects[i].signature=next_signature++;
392 SoundObjects[i].flags = SOF_USED | SOF_LINK_TO_OBJ;
394 SoundObjects[i].flags |= SOF_PLAY_FOREVER;
395 SoundObjects[i].link_type.obj.objnum = objnum;
396 SoundObjects[i].link_type.obj.objsignature = Objects[objnum].signature;
397 SoundObjects[i].max_volume = max_volume;
398 SoundObjects[i].max_distance = max_distance;
399 SoundObjects[i].volume = 0;
400 SoundObjects[i].pan = 0;
401 SoundObjects[i].soundnum = soundnum;
402 SoundObjects[i].loop_start = loop_start;
403 SoundObjects[i].loop_end = loop_end;
405 if (Dont_start_sound_objects) { //started at level start
407 SoundObjects[i].flags |= SOF_PERMANENT;
408 SoundObjects[i].channel = -1;
411 objp = &Objects[SoundObjects[i].link_type.obj.objnum];
412 digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum,
413 &objp->pos, objp->segnum, SoundObjects[i].max_volume,
414 &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance );
416 digi_start_sound_object(i);
418 // If it's a one-shot sound effect, and it can't start right away, then
419 // just cancel it and be done with it.
420 if ( (SoundObjects[i].channel < 0) && (!(SoundObjects[i].flags & SOF_PLAY_FOREVER)) ) {
421 SoundObjects[i].flags = 0;
426 return SoundObjects[i].signature;
429 int digi_link_sound_to_object2( int org_soundnum, short objnum, int forever, fix max_volume, fix max_distance )
431 return digi_link_sound_to_object3( org_soundnum, objnum, forever, max_volume, max_distance, -1, -1 );
435 int digi_link_sound_to_object( int soundnum, short objnum, int forever, fix max_volume )
437 return digi_link_sound_to_object2( soundnum, objnum, forever, max_volume, 256*F1_0 );
440 int digi_link_sound_to_pos2( int org_soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume, fix max_distance )
446 soundnum = digi_xlat_sound(org_soundnum);
448 if ( max_volume < 0 ) return -1;
449 // if ( max_volume > F1_0 ) max_volume = F1_0;
451 if (soundnum < 0 ) return -1;
452 if (GameSounds[soundnum].data==NULL) {
457 if ((segnum<0)||(segnum>Highest_segment_index))
460 if ( !forever ) { //&& GameSounds[soundnum - SOUND_OFFSET].length < SOUND_3D_THRESHHOLD) {
461 // Hack to keep sounds from building up...
462 digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, pos, segnum, max_volume, &volume, &pan, max_distance );
463 digi_play_sample_3d( org_soundnum, pan, volume, 0 );
467 for (i=0; i<MAX_SOUND_OBJECTS; i++ )
468 if (SoundObjects[i].flags==0)
471 if (i==MAX_SOUND_OBJECTS) {
472 mprintf((1, "Too many sound objects!\n" ));
477 SoundObjects[i].signature=next_signature++;
478 SoundObjects[i].flags = SOF_USED | SOF_LINK_TO_POS;
480 SoundObjects[i].flags |= SOF_PLAY_FOREVER;
481 SoundObjects[i].link_type.pos.segnum = segnum;
482 SoundObjects[i].link_type.pos.sidenum = sidenum;
483 SoundObjects[i].link_type.pos.position = *pos;
484 SoundObjects[i].soundnum = soundnum;
485 SoundObjects[i].max_volume = max_volume;
486 SoundObjects[i].max_distance = max_distance;
487 SoundObjects[i].volume = 0;
488 SoundObjects[i].pan = 0;
489 SoundObjects[i].loop_start = SoundObjects[i].loop_end = -1;
491 if (Dont_start_sound_objects) { //started at level start
493 SoundObjects[i].flags |= SOF_PERMANENT;
495 SoundObjects[i].channel = -1;
499 digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum,
500 &SoundObjects[i].link_type.pos.position, SoundObjects[i].link_type.pos.segnum, SoundObjects[i].max_volume,
501 &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance );
503 digi_start_sound_object(i);
505 // If it's a one-shot sound effect, and it can't start right away, then
506 // just cancel it and be done with it.
507 if ( (SoundObjects[i].channel < 0) && (!(SoundObjects[i].flags & SOF_PLAY_FOREVER)) ) {
508 SoundObjects[i].flags = 0;
513 return SoundObjects[i].signature;
516 int digi_link_sound_to_pos( int soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume )
518 return digi_link_sound_to_pos2( soundnum, segnum, sidenum, pos, forever, max_volume, F1_0 * 256 );
521 //if soundnum==-1, kill any sound
522 void digi_kill_sound_linked_to_segment( int segnum, int sidenum, int soundnum )
527 soundnum = digi_xlat_sound(soundnum);
532 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
533 if ( (SoundObjects[i].flags & SOF_USED) && (SoundObjects[i].flags & SOF_LINK_TO_POS) ) {
534 if ((SoundObjects[i].link_type.pos.segnum == segnum) && (SoundObjects[i].link_type.pos.sidenum==sidenum) && (soundnum==-1 || SoundObjects[i].soundnum==soundnum )) {
535 if ( SoundObjects[i].channel > -1 ) {
536 digi_stop_sound( SoundObjects[i].channel );
537 N_active_sound_objects--;
539 SoundObjects[i].channel = -1;
540 SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
545 // If this assert happens, it means that there were 2 sounds
546 // that got deleted. Weird, get John.
548 mprintf( (1, "ERROR: More than 1 sounds were deleted from seg %d\n", segnum ));
552 void digi_kill_sound_linked_to_object( int objnum )
560 if ( Newdemo_state == ND_STATE_RECORDING ) {
561 newdemo_record_kill_sound_linked_to_object( objnum );
565 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
566 if ( (SoundObjects[i].flags & SOF_USED) && (SoundObjects[i].flags & SOF_LINK_TO_OBJ ) ) {
567 if (SoundObjects[i].link_type.obj.objnum == objnum) {
568 if ( SoundObjects[i].channel > -1 ) {
569 digi_stop_sound( SoundObjects[i].channel );
570 N_active_sound_objects--;
572 SoundObjects[i].channel = -1;
573 SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
578 // If this assert happens, it means that there were 2 sounds
579 // that got deleted. Weird, get John.
581 mprintf( (1, "ERROR: More than 1 sounds were deleted from object %d\n", objnum ));
586 // John's new function, 2/22/96.
587 void digi_record_sound_objects()
591 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
592 if ( (SoundObjects[i].flags & SOF_USED)&&
593 (SoundObjects[i].flags & SOF_LINK_TO_OBJ)&&
594 (SoundObjects[i].flags & SOF_PLAY_FOREVER)
598 newdemo_record_link_sound_to_object3( digi_unxlat_sound(SoundObjects[i].soundnum), SoundObjects[i].link_type.obj.objnum,
599 SoundObjects[i].max_volume, SoundObjects[i].max_distance, SoundObjects[i].loop_start, SoundObjects[i].loop_end );
604 int was_recording = 0;
606 void digi_sync_sounds()
609 int oldvolume, oldpan;
611 if ( Newdemo_state == ND_STATE_RECORDING) {
612 if ( !was_recording ) {
613 digi_record_sound_objects();
622 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
623 if ( SoundObjects[i].flags & SOF_USED ) {
624 oldvolume = SoundObjects[i].volume;
625 oldpan = SoundObjects[i].pan;
627 if ( !(SoundObjects[i].flags & SOF_PLAY_FOREVER) ) {
628 // Check if its done.
629 if (SoundObjects[i].channel > -1 ) {
630 if ( !digi_is_channel_playing(SoundObjects[i].channel) ) {
631 digi_end_sound( SoundObjects[i].channel );
632 SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
633 N_active_sound_objects--;
634 continue; // Go on to next sound...
639 if ( SoundObjects[i].flags & SOF_LINK_TO_POS ) {
640 digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum,
641 &SoundObjects[i].link_type.pos.position, SoundObjects[i].link_type.pos.segnum, SoundObjects[i].max_volume,
642 &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance );
644 } else if ( SoundObjects[i].flags & SOF_LINK_TO_OBJ ) {
648 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
650 objnum = newdemo_find_object( SoundObjects[i].link_type.obj.objsignature );
652 objp = &Objects[objnum];
657 objp = &Objects[SoundObjects[i].link_type.obj.objnum];
660 if ((objp->type==OBJ_NONE) || (objp->signature!=SoundObjects[i].link_type.obj.objsignature)) {
661 // The object that this is linked to is dead, so just end this sound if it is looping.
662 if ( SoundObjects[i].channel>-1 ) {
663 if (SoundObjects[i].flags & SOF_PLAY_FOREVER)
664 digi_stop_sound( SoundObjects[i].channel );
666 digi_end_sound( SoundObjects[i].channel );
667 N_active_sound_objects--;
669 SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
670 continue; // Go on to next sound...
672 digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum,
673 &objp->pos, objp->segnum, SoundObjects[i].max_volume,
674 &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance );
678 if (oldvolume != SoundObjects[i].volume) {
679 if ( SoundObjects[i].volume < 1 ) {
680 // Sound is too far away, so stop it from playing.
682 if ( SoundObjects[i].channel>-1 ) {
683 if (SoundObjects[i].flags & SOF_PLAY_FOREVER)
684 digi_stop_sound( SoundObjects[i].channel );
686 digi_end_sound( SoundObjects[i].channel );
687 N_active_sound_objects--;
688 SoundObjects[i].channel = -1;
691 if (! (SoundObjects[i].flags & SOF_PLAY_FOREVER)) {
692 SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
697 if (SoundObjects[i].channel<0) {
698 digi_start_sound_object(i);
700 digi_set_channel_volume( SoundObjects[i].channel, SoundObjects[i].volume );
705 if (oldpan != SoundObjects[i].pan) {
706 if (SoundObjects[i].channel>-1)
707 digi_set_channel_pan( SoundObjects[i].channel, SoundObjects[i].pan );
714 // digi_sound_debug();
718 void digi_pause_digi_sounds()
723 digi_pause_looping_sound();
725 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
726 if ( (SoundObjects[i].flags & SOF_USED) && (SoundObjects[i].channel>-1) ) {
727 digi_stop_sound( SoundObjects[i].channel );
728 if (! (SoundObjects[i].flags & SOF_PLAY_FOREVER))
729 SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
730 N_active_sound_objects--;
731 SoundObjects[i].channel = -1;
735 digi_stop_all_channels();
739 void digi_pause_all()
742 digi_pause_digi_sounds();
745 void digi_resume_digi_sounds()
747 digi_sync_sounds(); //don't think we really need to do this, but can't hurt
748 digi_unpause_looping_sound();
751 extern void digi_resume_midi();
753 void digi_resume_all()
756 digi_unpause_looping_sound();
759 // Called by the code in digi.c when another sound takes this sound object's
760 // slot because the sound was done playing.
761 void digi_end_soundobj(int i)
763 Assert( SoundObjects[i].flags & SOF_USED );
764 Assert( SoundObjects[i].channel > -1 );
766 N_active_sound_objects--;
767 SoundObjects[i].channel = -1;
770 void digi_stop_digi_sounds()
774 digi_stop_looping_sound();
776 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
777 if ( SoundObjects[i].flags & SOF_USED ) {
778 if ( SoundObjects[i].channel > -1 ) {
779 digi_stop_sound( SoundObjects[i].channel );
780 N_active_sound_objects--;
782 SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
786 digi_stop_all_channels();
792 digi_stop_current_song();
794 digi_stop_digi_sounds();
798 int verify_sound_channel_free( int channel )
801 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
802 if ( SoundObjects[i].flags & SOF_USED ) {
803 if ( SoundObjects[i].channel == channel ) {
804 mprintf(( 0, "ERROR STARTING SOUND CHANNEL ON USED SLOT!!\n" ));
812 void digi_sound_debug()
815 int n_active_sound_objs=0;
818 for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {
819 if ( SoundObjects[i].flags & SOF_USED ) {
821 if ( SoundObjects[i].channel > -1 )
822 n_active_sound_objs++;
825 mprintf_at(( 0, 0, 0, "DIGI: Active Sound Objects: %d,%d/%d (%d max) \n", n_active_sound_objs,N_active_sound_objects, n_sound_objs, MAX_SOUND_OBJECTS ));
826 mprintf_at(( 0, 1, 0, "DIGI: Looping sound: %s, snd=%d, vol=%d, ch=%d \n", (digi_looping_sound>-1?"ON":"OFF"), digi_looping_sound, digi_looping_volume, digi_looping_channel ));
832 typedef struct sound_q {
838 #define MAX_LIFE F1_0*30 // After being queued for 30 seconds, don't play it
839 sound_q SoundQ[MAX_Q];
840 int SoundQ_head, SoundQ_tail, SoundQ_num;
845 SoundQ_head = SoundQ_tail = 0;
857 // Current playing sound is stopped, so take it off the Queue
858 SoundQ_head = (SoundQ_head+1);
859 if ( SoundQ_head >= MAX_Q ) SoundQ_head = 0;
864 void SoundQ_process()
866 fix curtime = timer_get_approx_seconds();
868 if ( SoundQ_channel > -1 ) {
869 if ( digi_is_channel_playing(SoundQ_channel) )
874 if ( SoundQ_num > 0 ) {
875 mprintf(( 0, "SQ:%d ", SoundQ_num ));
878 while ( SoundQ_head != SoundQ_tail ) {
879 sound_q * q = &SoundQ[SoundQ_head];
881 if ( q->time_added+MAX_LIFE > curtime ) {
882 SoundQ_channel = digi_start_sound(q->soundnum, F1_0+1, 0xFFFF/2, 0, -1, -1, -1 );
885 // expired; remove from Queue
892 void digi_start_sound_queued( short soundnum, fix volume )
896 soundnum = digi_xlat_sound(soundnum);
898 if (soundnum < 0 ) return;
901 if ( i>=MAX_Q ) i = 0;
903 // Make sure its loud so it doesn't get cancelled!
904 if ( volume < F1_0+1 )
907 if ( i != SoundQ_head ) {
908 SoundQ[SoundQ_tail].time_added = timer_get_approx_seconds();
909 SoundQ[SoundQ_tail].soundnum = soundnum;
913 mprintf(( 0, "Sound Q full!\n" ));