Subversion Repositories Kolibri OS

Rev

Rev 298 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 298 Rev 333
Line 49... Line 49...
49
 
49
 
50
// Purpose?
50
// Purpose?
51
const char snd_prefixen[]
51
const char snd_prefixen[]
Line 52... Line 52...
52
= { 'P', 'P', 'A', 'S', 'S', 'S', 'M', 'M', 'M', 'S', 'S', 'S' };
52
= { 'P', 'P', 'A', 'S', 'S', 'S', 'M', 'M', 'M', 'S', 'S', 'S' };
Line 53... Line 53...
53
 
53
 
54
#define S_MAX_VOLUME		127
54
#define S_MAX_VOLUME            127
55
 
55
 
Line 56... Line 56...
56
// when to clip out sounds
56
// when to clip out sounds
57
// Does not fit the large outdoor areas.
57
// Does not fit the large outdoor areas.
58
#define S_CLIPPING_DIST		(1200*0x10000)
58
#define S_CLIPPING_DIST         (1200*0x10000)
59
 
59
 
60
// Distance tp origin when sounds should be maxed out.
60
// Distance tp origin when sounds should be maxed out.
Line 61... Line 61...
61
// This should relate to movement clipping resolution
61
// This should relate to movement clipping resolution
Line 62... Line 62...
62
// (see BLOCKMAP handling).
62
// (see BLOCKMAP handling).
63
// Originally: (200*0x10000).
63
// Originally: (200*0x10000).
Line 64... Line 64...
64
#define S_CLOSE_DIST		(160*0x10000)
64
#define S_CLOSE_DIST            (160*0x10000)
65
 
65
 
66
 
66
 
Line 67... Line 67...
67
#define S_ATTENUATOR		((S_CLIPPING_DIST-S_CLOSE_DIST)>>FRACBITS)
67
#define S_ATTENUATOR            ((S_CLIPPING_DIST-S_CLOSE_DIST)>>FRACBITS)
68
 
68
 
Line 69... Line 69...
69
// Adjustable by menu.
69
// Adjustable by menu.
70
#define NORM_VOLUME    		snd_MaxVolume
70
#define NORM_VOLUME             snd_MaxVolume
Line 71... Line 71...
71
 
71
 
72
#define NORM_PITCH     		128
72
#define NORM_PITCH              128
73
#define NORM_PRIORITY		64
73
#define NORM_PRIORITY           64
Line 74... Line 74...
74
#define NORM_SEP		128
74
#define NORM_SEP                128
75
 
75
 
76
#define S_PITCH_PERTURB		1
76
#define S_PITCH_PERTURB         1
77
#define S_STEREO_SWING		(96*0x10000)
77
#define S_STEREO_SWING          (96*0x10000)
Line 93... Line 93...
93
 
93
 
94
 
94
 
95
typedef struct
95
typedef struct
96
{
96
{
Line 97... Line 97...
97
    // sound information (if null, channel avail.)
97
    // sound information (if null, channel avail.)
98
    sfxinfo_t*	sfxinfo;
98
    sfxinfo_t*  sfxinfo;
Line 99... Line 99...
99
 
99
 
100
    // origin of sound
100
    // origin of sound
Line 101... Line 101...
101
    void*	origin;
101
    void*       origin;
Line 102... Line 102...
102
 
102
 
103
    // handle of the sound being played
103
    // handle of the sound being played
Line 104... Line 104...
104
    int		handle;
104
    int         handle;
105
    
105
    
106
} channel_t;
106
} channel_t;
107
 
107
 
Line 108... Line 108...
108
 
108
 
109
// the set of channels available
109
// the set of channels available
Line 110... Line 110...
110
static channel_t*	channels;
110
static channel_t*       channels;
111
 
111
 
Line 112... Line 112...
112
// These are not used, but should be (menu).
112
// These are not used, but should be (menu).
113
// Maximum volume of a sound effect.
113
// Maximum volume of a sound effect.
Line 114... Line 114...
114
// Internal default is max out of 0-15.
114
// Internal default is max out of 0-15.
115
int 		snd_SfxVolume = 80;
115
int             snd_SfxVolume = 80;
116
 
116
 
117
// Maximum volume of music. Useless so far.
117
// Maximum volume of music. Useless so far.
Line 118... Line 118...
118
int 		snd_MusicVolume = 80; 
118
int             snd_MusicVolume = 80; 
Line 119... Line 119...
119
 
119
 
120
 
120
 
121
 
121
 
122
// whether songs are mus_paused
122
// whether songs are mus_paused
123
static boolean		mus_paused;	
123
static boolean          mus_paused;     
124
 
124
 
125
// music currently being played
125
// music currently being played
126
static musicinfo_t*	mus_playing=0;
126
static musicinfo_t*     mus_playing=0;
Line 127... Line 127...
127
 
127
 
128
// following is set
128
// following is set
129
//  by the defaults code in M_misc:
129
//  by the defaults code in M_misc:
130
// number of channels available
130
// number of channels available
131
int			numChannels;	
131
int                     numChannels;    
132
 
132
 
133
static int		nextcleanup;
133
static int              nextcleanup;
Line 134... Line 134...
134
 
134
 
Line 160... Line 160...
160
// Initializes sound stuff, including volume
160
// Initializes sound stuff, including volume
161
// Sets channels, SFX and music volume,
161
// Sets channels, SFX and music volume,
162
//  allocates channel buffer, sets S_sfx lookup.
162
//  allocates channel buffer, sets S_sfx lookup.
163
//
163
//
164
void S_Init
164
void S_Init
165
( int		sfxVolume,
165
( int           sfxVolume,
166
  int		musicVolume )
166
  int           musicVolume )
167
{  
167
{  
168
  int		i;
168
  int           i;
Line 169... Line 169...
169
 
169
 
Line 170... Line 170...
170
  printf("S_Init: default sfx volume %d\n", sfxVolume);
170
  printf("S_Init: default sfx volume %d\n", sfxVolume);
171
 
171
 
Line 172... Line 172...
172
  I_CreateSound();
172
  //I_CreateSound();
173
  numChannels = NUM_CHANNELS;
173
  numChannels = NUM_CHANNELS;
Line 215... Line 215...
215
  
215
  
216
  // start new music for the level
216
  // start new music for the level
Line 217... Line 217...
217
  mus_paused = 0;
217
  mus_paused = 0;
218
  
218
  
219
  if (gamemode == commercial)
219
  if (gamemode == commercial)
220
	  mnum = mus_runnin + gamemap - 1;
220
          mnum = mus_runnin + gamemap - 1;
221
  else
221
  else
222
  {
222
  {
223
	  int spmus[]=
223
          int spmus[]=
224
	  {
224
          {
225
		  // Song - Who? - Where?
225
                  // Song - Who? - Where?
226
		mus_e3m4,	// American	e4m1
226
                mus_e3m4,       // American     e4m1
227
		mus_e3m2,	// Romero	e4m2
227
                mus_e3m2,       // Romero       e4m2
228
		mus_e3m3,	// Shawn	e4m3
228
                mus_e3m3,       // Shawn        e4m3
229
		mus_e1m5,	// American	e4m4
229
                mus_e1m5,       // American     e4m4
230
		mus_e2m7,	// Tim 	e4m5
230
                mus_e2m7,       // Tim  e4m5
231
		mus_e2m4,	// Romero	e4m6
231
                mus_e2m4,       // Romero       e4m6
232
		mus_e2m6,	// J.Anderson	e4m7 CHIRON.WAD
232
                mus_e2m6,       // J.Anderson   e4m7 CHIRON.WAD
233
		mus_e2m5,	// Shawn	e4m8
233
                mus_e2m5,       // Shawn        e4m8
234
		mus_e1m9	// Tim		e4m9
234
                mus_e1m9        // Tim          e4m9
235
	  };
235
          };
236
	  
236
          
237
	  if (gameepisode < 4)
237
          if (gameepisode < 4)
238
		  mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1;
238
                  mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1;
239
	  else
239
          else
Line 240... Line 240...
240
		  mnum = spmus[gamemap-1];
240
                  mnum = spmus[gamemap-1];
241
  }	
241
  }     
242
  
242
  
Line 243... Line 243...
243
  // HACK FOR COMMERCIAL
243
  // HACK FOR COMMERCIAL
Line 244... Line 244...
244
  //  if (commercial && mnum > mus_e3m9)	
244
  //  if (commercial && mnum > mus_e3m9)        
245
  //      mnum -= mus_e3m9;
245
  //      mnum -= mus_e3m9;
Line 246... Line 246...
246
  
246
  
247
  S_ChangeMusic(mnum, true);
247
  S_ChangeMusic(mnum, true);
248
  
248
  
249
  nextcleanup = 15;
249
  nextcleanup = 15;
Line 257... Line 257...
257
    int        priority;
257
    int        priority;
258
    sfxinfo_t *sfx;
258
    sfxinfo_t *sfx;
259
    int        cnum;
259
    int        cnum;
260
    // int        chnum;  <-- 10.9.98 compiler warning
260
    // int        chnum;  <-- 10.9.98 compiler warning
Line 261... Line 261...
261
  
261
  
Line 262... Line 262...
262
    mobj_t*	origin = (mobj_t *)origin_p;
262
    mobj_t*     origin = (mobj_t *)origin_p;
Line 263... Line 263...
263
  
263
  
264
    //WriteDebug("S_StartSoundAtVolume...\n");
264
    //WriteDebug("S_StartSoundAtVolume...\n");
Line 285... Line 285...
285
            return;
285
            return;
286
           }
286
           }
Line 287... Line 287...
287
    
287
    
288
        if (volume > snd_SfxVolume)
288
        if (volume > snd_SfxVolume)
289
            volume = snd_SfxVolume;
289
            volume = snd_SfxVolume;
290
       }	
290
       }        
291
    else
291
    else
292
       {
292
       {
293
        pitch = NORM_PITCH;
293
        pitch = NORM_PITCH;
294
        priority = NORM_PRIORITY;
294
        priority = NORM_PRIORITY;
Line 299... Line 299...
299
    //  and if not, modify the params
299
    //  and if not, modify the params
300
    if (origin && origin != players[consoleplayer].mo)
300
    if (origin && origin != players[consoleplayer].mo)
301
       {
301
       {
302
        rc = S_AdjustSoundParams(players[consoleplayer].mo, origin, &volume, &sep, &pitch);
302
        rc = S_AdjustSoundParams(players[consoleplayer].mo, origin, &volume, &sep, &pitch);
303
        if ( origin->x == players[consoleplayer].mo->x && origin->y == players[consoleplayer].mo->y)
303
        if ( origin->x == players[consoleplayer].mo->x && origin->y == players[consoleplayer].mo->y)
304
           {	
304
           {    
305
            sep = NORM_SEP;
305
            sep = NORM_SEP;
306
           }
306
           }
307
        if (!rc)
307
        if (!rc)
308
           {
308
           {
309
            //WriteDebug("No rc from S_AdjustSoundParams...\n");
309
            //WriteDebug("No rc from S_AdjustSoundParams...\n");
310
            return;
310
            return;
311
           }
311
           }
312
       }	
312
       }        
313
    else
313
    else
314
       {
314
       {
315
        sep = NORM_SEP;
315
        sep = NORM_SEP;
316
       }
316
       }
Line 317... Line 317...
317
  
317
  
318
    // hacks to vary the sfx pitches
318
    // hacks to vary the sfx pitches
319
    if (sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit)
319
    if (sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit)
320
       {	
320
       {        
321
        pitch += 8 - (M_Random()&15);
321
        pitch += 8 - (M_Random()&15);
322
        if (pitch < 0)
322
        if (pitch < 0)
323
            pitch = 0;
323
            pitch = 0;
324
        else
324
        else
Line 370... Line 370...
370
      sfx->usefulness = 1;
370
      sfx->usefulness = 1;
Line 371... Line 371...
371
  
371
  
372
  // Assigns the handle to one of the channels in the
372
  // Assigns the handle to one of the channels in the
373
  //  mix/output buffer.
373
  //  mix/output buffer.
374
  //WriteDebug("I_StartSound...\n");
374
  //WriteDebug("I_StartSound...\n");
375
  channels[cnum].handle = I_StartSound(sfx_id,/*sfx->data,*/volume,sep,pitch,priority,origin);
-
 
376
  //cnum = I_StartSound(sfx_id,/*sfx->data,*/volume,sep,pitch,priority,origin);
375
  channels[cnum].handle = I_StartSound(sfx_id,volume,sep,pitch,priority);
377
  channels[cnum].handle = cnum;
376
  channels[cnum].handle = cnum;
378
  channels[cnum].sfxinfo = sfx;
377
  channels[cnum].sfxinfo = sfx;
379
  channels[cnum].origin = origin;
378
  channels[cnum].origin = origin;
Line 380... Line 379...
380
}	
379
}       
381
 
380
 
382
void S_StartSound( void *origin, int sfx_id )
381
void S_StartSound( void *origin, int sfx_id )
383
   {
382
   {
Line 392... Line 391...
392
    // UNUSED. We had problems, had we not?
391
    // UNUSED. We had problems, had we not?
393
#ifdef SAWDEBUG
392
#ifdef SAWDEBUG
394
{
393
{
395
    int i;
394
    int i;
396
    int n;
395
    int n;
397
	
396
        
398
    static mobj_t*      last_saw_origins[10] = {1,1,1,1,1,1,1,1,1,1};
397
    static mobj_t*      last_saw_origins[10] = {1,1,1,1,1,1,1,1,1,1};
399
    static int		first_saw=0;
398
    static int          first_saw=0;
400
    static int		next_saw=0;
399
    static int          next_saw=0;
401
	
400
        
402
    if (sfx_id == sfx_sawidl
401
    if (sfx_id == sfx_sawidl
403
	|| sfx_id == sfx_sawful
402
        || sfx_id == sfx_sawful
404
	|| sfx_id == sfx_sawhit)
403
        || sfx_id == sfx_sawhit)
405
    {
404
    {
406
	for (i=first_saw;i!=next_saw;i=(i+1)%10)
405
        for (i=first_saw;i!=next_saw;i=(i+1)%10)
407
	    if (last_saw_origins[i] != origin)
406
            if (last_saw_origins[i] != origin)
408
		fprintf(stderr, "old origin 0x%lx != "
407
                fprintf(stderr, "old origin 0x%lx != "
409
			"origin 0x%lx for sfx %d\n",
408
                        "origin 0x%lx for sfx %d\n",
410
			last_saw_origins[i],
409
                        last_saw_origins[i],
411
			origin,
410
                        origin,
412
			sfx_id);
411
                        sfx_id);
413
	    
412
            
414
	last_saw_origins[next_saw] = origin;
413
        last_saw_origins[next_saw] = origin;
415
	next_saw = (next_saw + 1) % 10;
414
        next_saw = (next_saw + 1) % 10;
416
	if (next_saw == first_saw)
415
        if (next_saw == first_saw)
417
	    first_saw = (first_saw + 1) % 10;
416
            first_saw = (first_saw + 1) % 10;
418
	    
417
            
419
	for (n=i=0; i
418
        for (n=i=0; i
420
	{
419
        {
421
	    if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]
420
            if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]
422
		|| channels[i].sfxinfo == &S_sfx[sfx_sawful]
421
                || channels[i].sfxinfo == &S_sfx[sfx_sawful]
423
		|| channels[i].sfxinfo == &S_sfx[sfx_sawhit]) n++;
422
                || channels[i].sfxinfo == &S_sfx[sfx_sawhit]) n++;
424
	}
423
        }
425
	    
424
            
426
	if (n>1)
425
        if (n>1)
427
	{
426
        {
428
	    for (i=0; i
427
            for (i=0; i
429
	    {
428
            {
430
		if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]
429
                if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]
431
		    || channels[i].sfxinfo == &S_sfx[sfx_sawful]
430
                    || channels[i].sfxinfo == &S_sfx[sfx_sawful]
432
		    || channels[i].sfxinfo == &S_sfx[sfx_sawhit])
431
                    || channels[i].sfxinfo == &S_sfx[sfx_sawhit])
433
		{
432
                {
434
		    fprintf(stderr,
433
                    fprintf(stderr,
435
			    "chn: sfxinfo=0x%lx, origin=0x%lx, "
434
                            "chn: sfxinfo=0x%lx, origin=0x%lx, "
436
			    "handle=%d\n",
435
                            "handle=%d\n",
437
			    channels[i].sfxinfo,
436
                            channels[i].sfxinfo,
438
			    channels[i].origin,
437
                            channels[i].origin,
439
			    channels[i].handle);
438
                            channels[i].handle);
440
		}
439
                }
441
	    }
440
            }
442
	    fprintf(stderr, "\n");
441
            fprintf(stderr, "\n");
443
	}
442
        }
444
    }
443
    }
445
}
444
}
446
#endif
445
#endif
Line 447... Line 446...
447
 
446
 
Line 455... Line 454...
455
 
454
 
Line 456... Line 455...
456
    int cnum;
455
    int cnum;
457
 
456
 
458
    for (cnum=0 ; cnum
457
    for (cnum=0 ; cnum
459
    {
458
    {
460
	if (channels[cnum].sfxinfo && channels[cnum].origin == origin)
459
        if (channels[cnum].sfxinfo && channels[cnum].origin == origin)
461
	{
460
        {
462
	    S_StopChannel(cnum);
461
            S_StopChannel(cnum);
463
	    break;
462
            break;
464
	}
463
        }
Line 478... Line 477...
478
//
477
//
479
void S_PauseSound(void)
478
void S_PauseSound(void)
480
{
479
{
481
    if (mus_playing && !mus_paused)
480
    if (mus_playing && !mus_paused)
482
    {
481
    {
483
	I_PauseSong(mus_playing->handle);
482
        I_PauseSong(mus_playing->handle);
484
	mus_paused = true;
483
        mus_paused = true;
485
    }
484
    }
486
}
485
}
Line 487... Line 486...
487
 
486
 
488
void S_ResumeSound(void)
487
void S_ResumeSound(void)
489
{
488
{
490
    if (mus_playing && mus_paused)
489
    if (mus_playing && mus_paused)
491
    {
490
    {
492
	I_ResumeSong(mus_playing->handle);
491
        I_ResumeSong(mus_playing->handle);
493
	mus_paused = false;
492
        mus_paused = false;
494
    }
493
    }
Line 495... Line 494...
495
}
494
}
496
 
495
 
497
 
496
 
498
//
497
//
499
// Updates music & sounds
498
// Updates music & sounds
500
//
499
//
501
void S_UpdateSounds(void* listener_p)
500
void S_UpdateSounds(void* listener_p)
502
{
501
{
503
    int		audible;
502
    int         audible;
504
    int		cnum;
503
    int         cnum;
505
    int		volume;
504
    int         volume;
506
    int		sep;
505
    int         sep;
Line 507... Line 506...
507
    int		pitch;
506
    int         pitch;
Line 508... Line 507...
508
    sfxinfo_t*	sfx;
507
    sfxinfo_t*  sfx;
509
    channel_t*	c;
508
    channel_t*  c;
510
    
509
    
511
    mobj_t*	listener = (mobj_t*)listener_p;
510
    mobj_t*     listener = (mobj_t*)listener_p;
512
 
511
 
513
 
512
 
514
    
513
    
515
    // Clean up unused data.
514
    // Clean up unused data.
516
    // This is currently not done for 16bit (sounds cached static).
515
    // This is currently not done for 16bit (sounds cached static).
517
    // DOS 8bit remains. 
516
    // DOS 8bit remains. 
518
    /*if (gametic > nextcleanup)
517
    /*if (gametic > nextcleanup)
519
    {
518
    {
520
	for (i=1 ; i
519
        for (i=1 ; i
521
	{
520
        {
522
	    if (S_sfx[i].usefulness < 1
521
            if (S_sfx[i].usefulness < 1
523
		&& S_sfx[i].usefulness > -1)
522
                && S_sfx[i].usefulness > -1)
524
	    {
523
            {
525
		if (--S_sfx[i].usefulness == -1)
524
                if (--S_sfx[i].usefulness == -1)
526
		{
525
                {
Line 527... Line 526...
527
		    Z_ChangeTag(S_sfx[i].data, PU_CACHE);
526
                    Z_ChangeTag(S_sfx[i].data, PU_CACHE);
528
		    S_sfx[i].data = 0;
527
                    S_sfx[i].data = 0;
529
		}
528
                }
530
	    }
529
            }
Line 531... Line 530...
531
	}
530
        }
532
	nextcleanup = gametic + 15;
531
        nextcleanup = gametic + 15;
533
    }*/
532
    }*/
534
    
533
    
535
    for (cnum=0 ; cnum
534
    for (cnum=0 ; cnum
536
    {
535
    {
537
	c = &channels[cnum];
536
        c = &channels[cnum];
538
	sfx = c->sfxinfo;
537
        sfx = c->sfxinfo;
539
 
538
 
540
	if (c->sfxinfo)
539
        if (c->sfxinfo)
541
	{
540
        {
542
	    if (I_SoundIsPlaying(c->handle))
541
            if (I_SoundIsPlaying(c->handle))
543
	    {
542
            {
544
		// initialize parameters
543
                // initialize parameters
545
		volume = snd_SfxVolume;
544
                volume = snd_SfxVolume;
546
		pitch = NORM_PITCH;
545
                pitch = NORM_PITCH;
547
		sep = NORM_SEP;
546
                sep = NORM_SEP;
548
 
547
 
549
		if (sfx->link)
548
                if (sfx->link)
550
		{
549
                {
551
		    pitch = sfx->pitch;
550
                    pitch = sfx->pitch;
552
		    volume += sfx->volume;
551
                    volume += sfx->volume;
553
		    if (volume < 1)
552
                    if (volume < 1)
554
		    {
553
                    {
555
			S_StopChannel(cnum);
554
                        S_StopChannel(cnum);
556
			continue;
555
                        continue;
557
		    }
556
                    }
558
		    else if (volume > snd_SfxVolume)
557
                    else if (volume > snd_SfxVolume)
559
		    {
558
                    {
560
			volume = snd_SfxVolume;
559
                        volume = snd_SfxVolume;
561
		    }
560
                    }
562
		}
561
                }
563
 
562
 
564
		// check non-local sounds for distance clipping
563
                // check non-local sounds for distance clipping
565
		//  or modify their params
564
                //  or modify their params
566
		if (c->origin && listener_p != c->origin)
565
                if (c->origin && listener_p != c->origin)
567
		{
566
                {
568
		    audible = S_AdjustSoundParams(listener,
567
                    audible = S_AdjustSoundParams(listener,
569
						  c->origin,
568
                                                  c->origin,
570
						  &volume,
569
                                                  &volume,
571
						  &sep,
570
                                                  &sep,
572
						  &pitch);
571
                                                  &pitch);
573
		    
572
                    
574
		    if (!audible)
573
                    if (!audible)
575
		    {
574
                    {
576
			S_StopChannel(cnum);
575
                        S_StopChannel(cnum);
577
		    }
576
                    }
578
		    else
577
                    else
579
			I_UpdateSoundParams(c->handle, volume, sep, pitch);
578
                        I_UpdateSoundParams(c->handle, volume, sep, pitch);
580
		}
579
                }
581
	    }
580
            }
582
	    else
581
            else
583
	    {
582
            {
584
		// if channel is allocated but sound has stopped,
583
                // if channel is allocated but sound has stopped,
585
		//  free it
584
                //  free it
586
		S_StopChannel(cnum);
585
                S_StopChannel(cnum);
Line 587... Line 586...
587
	    }
586
            }
588
	}
587
        }
589
    }
588
    }
590
    // kill music if it is a single-play && finished
589
    // kill music if it is a single-play && finished
591
    // if (	mus_playing
590
    // if (     mus_playing
592
    //      && !I_QrySongPlaying(mus_playing->handle)
591
    //      && !I_QrySongPlaying(mus_playing->handle)
593
    //      && !mus_paused )
592
    //      && !mus_paused )
Line 594... Line 593...
594
    // S_StopMusic();
593
    // S_StopMusic();
595
}
594
}
596
 
595
 
Line 612... Line 611...
612
 
611
 
613
void S_SetSfxVolume(int volume)
612
void S_SetSfxVolume(int volume)
Line 614... Line 613...
614
{
613
{
615
 
614
 
Line 616... Line 615...
616
    if (volume < 0 || volume > 127)
615
    if (volume < 0 || volume > 127)
Line 617... Line 616...
617
	I_Error("Attempt to set sfx volume at %d", volume);
616
        I_Error("Attempt to set sfx volume at %d", volume);
Line 632... Line 631...
632
// clean-up&code for orig midi 10.9.98-dlw
631
// clean-up&code for orig midi 10.9.98-dlw
633
void S_ChangeMusic(int musicnum, int looping)
632
void S_ChangeMusic(int musicnum, int looping)
634
{
633
{
Line 635... Line 634...
635
 
634
 
636
    // I_PlaySong(music->handle, looping);
635
    // I_PlaySong(music->handle, looping);
637
//	mus_playing = music;
636
//      mus_playing = music;
Line 638... Line 637...
638
}
637
}
639
 
638
 
640
 
639
 
641
void S_StopMusic(void)
640
void S_StopMusic(void)
642
{
641
{
643
    if (mus_playing)
642
    if (mus_playing)
644
    {
643
    {
645
		if (mus_paused) I_ResumeSong(mus_playing->handle);
644
                if (mus_paused) I_ResumeSong(mus_playing->handle);
646
		I_StopSong(mus_playing->handle);
645
                I_StopSong(mus_playing->handle);
647
		I_UnRegisterSong(mus_playing->handle);
646
                I_UnRegisterSong(mus_playing->handle);
648
		Z_ChangeTag(mus_playing->data, PU_CACHE);
647
                Z_ChangeTag(mus_playing->data, PU_CACHE);
649
		mus_playing->data = 0;
648
                mus_playing->data = 0;
Line 650... Line 649...
650
		mus_playing = 0;
649
                mus_playing = 0;
651
    }
650
    }
Line 652... Line 651...
652
}
651
}
653
 
652
 
Line 654... Line 653...
654
void S_StopChannel(int cnum)
653
void S_StopChannel(int cnum)
655
{
654
{
656
 
655
 
657
    int		i;
656
    int         i;
658
    channel_t*	c = &channels[cnum];
657
    channel_t*  c = &channels[cnum];
659
 
658
 
660
    if (c->sfxinfo)
659
    if (c->sfxinfo)
661
    {
660
    {
662
	// stop the sound playing
661
        // stop the sound playing
663
	if (I_SoundIsPlaying(c->handle))
662
        if (I_SoundIsPlaying(c->handle))
664
	{
663
        {
Line 665... Line 664...
665
#ifdef SAWDEBUG
664
#ifdef SAWDEBUG
666
	    if (c->sfxinfo == &S_sfx[sfx_sawful])
665
            if (c->sfxinfo == &S_sfx[sfx_sawful])
667
		fprintf(stderr, "stopped\n");
666
                fprintf(stderr, "stopped\n");
668
#endif
667
#endif
669
	    I_StopSound(c->handle);
668
            I_StopSound(c->handle);
670
	}
669
        }
671
 
670
 
672
	// check to see
671
        // check to see
673
	//  if other channels are playing the sound
672
        //  if other channels are playing the sound
674
	for (i=0 ; i
673
        for (i=0 ; i
675
	{
674
        {
676
	    if (cnum != i
675
            if (cnum != i
677
		&& c->sfxinfo == channels[i].sfxinfo)
676
                && c->sfxinfo == channels[i].sfxinfo)
Line 678... Line 677...
678
	    {
677
            {
679
		break;
678
                break;
680
	    }
679
            }
Line 681... Line 680...
681
	}
680
        }
Line 696... Line 695...
696
//
695
//
697
int
696
int
698
S_AdjustSoundParams (mobj_t* listener, mobj_t* source, 
697
S_AdjustSoundParams (mobj_t* listener, mobj_t* source, 
699
                     int* vol, int* sep, int* pitch)
698
                     int* vol, int* sep, int* pitch)
700
{
699
{
701
    fixed_t	approx_dist;
700
    fixed_t     approx_dist;
702
    fixed_t	adx;
701
    fixed_t     adx;
703
    fixed_t	ady;
702
    fixed_t     ady;
704
    angle_t	angle;
703
    angle_t     angle;
Line 705... Line 704...
705
 
704
 
706
    // calculate the distance to sound origin
705
    // calculate the distance to sound origin
707
    //  and clip it if necessary
706
    //  and clip it if necessary
708
    adx = abs(listener->x - source->x);
707
    adx = abs(listener->x - source->x);
Line 709... Line 708...
709
    ady = abs(listener->y - source->y);
708
    ady = abs(listener->y - source->y);
710
 
709
 
Line 711... Line 710...
711
    // From _GG1_ p.428. Appox. eucledian distance fast.
710
    // From _GG1_ p.428. Appox. eucledian distance fast.
712
    approx_dist = adx + ady - ((adx < ady ? adx : ady)>>1);
711
    approx_dist = adx + ady - ((adx < ady ? adx : ady)>>1);
713
    
712
    
714
    if (gamemap != 8
713
    if (gamemap != 8
715
	&& approx_dist > S_CLIPPING_DIST)
714
        && approx_dist > S_CLIPPING_DIST)
Line 716... Line 715...
716
    {
715
    {
717
	return 0;
716
        return 0;
718
    }
717
    }
719
    
718
    
720
    // angle of source to listener
719
    // angle of source to listener
Line 721... Line 720...
721
    angle = R_PointToAngle2(listener->x,
720
    angle = R_PointToAngle2(listener->x,
722
			    listener->y,
721
                            listener->y,
723
			    source->x,
722
                            source->x,
724
			    source->y);
723
                            source->y);
Line 725... Line 724...
725
 
724
 
Line 726... Line 725...
726
    if (angle > listener->angle)
725
    if (angle > listener->angle)
727
	angle = angle - listener->angle;
726
        angle = angle - listener->angle;
Line 728... Line 727...
728
    else
727
    else
729
	angle = angle + (0xffffffff - listener->angle);
728
        angle = angle + (0xffffffff - listener->angle);
730
 
729
 
731
    angle >>= ANGLETOFINESHIFT;
730
    angle >>= ANGLETOFINESHIFT;
732
 
731
 
733
    // stereo separation
732
    // stereo separation
734
    *sep = 128 - (FixedMul(S_STEREO_SWING,finesine[angle])>>FRACBITS);
733
    *sep = 128 - (FixedMul(S_STEREO_SWING,finesine[angle])>>FRACBITS);
735
 
734
 
736
    // volume calculation
735
    // volume calculation
Line 737... Line 736...
737
    if (approx_dist < S_CLOSE_DIST)
736
    if (approx_dist < S_CLOSE_DIST)
738
    {
737
    {
739
	*vol = snd_SfxVolume;
738
        *vol = snd_SfxVolume;
740
    }
739
    }
741
    else if (gamemap == 8)
740
    else if (gamemap == 8)
742
    {
741
    {
743
	if (approx_dist > S_CLIPPING_DIST)
742
        if (approx_dist > S_CLIPPING_DIST)
744
	    approx_dist = S_CLIPPING_DIST;
743
            approx_dist = S_CLIPPING_DIST;
745
 
744
 
746
	*vol = 15+ ((snd_SfxVolume-15)
745
        *vol = 15+ ((snd_SfxVolume-15)
747
		    *((S_CLIPPING_DIST - approx_dist)>>FRACBITS))
746
                    *((S_CLIPPING_DIST - approx_dist)>>FRACBITS))
Line 748... Line 747...
748
	    / S_ATTENUATOR;
747
            / S_ATTENUATOR;
749
    }
748
    }
Line 763... Line 762...
763
//   If none available, return -1.  Otherwise channel #.
762
//   If none available, return -1.  Otherwise channel #.
764
//
763
//
765
int S_getChannel( void *origin, sfxinfo_t *sfxinfo, int sfxid )
764
int S_getChannel( void *origin, sfxinfo_t *sfxinfo, int sfxid )
766
   {
765
   {
767
    // channel number to use
766
    // channel number to use
768
    int		cnum;
767
    int         cnum;
Line 769... Line 768...
769
        
768
        
Line 770... Line 769...
770
    channel_t*	c;
769
    channel_t*  c;
771
 
770
 
772
    // Find an open channel
771
    // Find an open channel
773
    //for (cnum = 0; cnum < numChannels; cnum++)
772
    //for (cnum = 0; cnum < numChannels; cnum++)