2006-04-13 20:47:06 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
2007-02-08 04:19:39 +00:00
|
|
|
Copyright (C) 1996, 2003 - 3D Realms Entertainment
|
|
|
|
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
|
|
|
|
Copyright (C) 2004, 2007 - EDuke32 developers
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
This file is part of EDuke32
|
|
|
|
|
|
|
|
EDuke32 is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//#include <conio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "types.h"
|
|
|
|
#include "fx_man.h"
|
|
|
|
#include "music.h"
|
|
|
|
#include "duke3d.h"
|
|
|
|
#include "util_lib.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define LOUDESTVOLUME 150
|
|
|
|
|
|
|
|
long backflag,numenvsnds;
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= SoundStartup
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
void SoundStartup(void)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
|
|
|
int32 status;
|
|
|
|
|
|
|
|
// if they chose None lets return
|
|
|
|
if (FXDevice < 0) return;
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
status = FX_Init(FXDevice, NumVoices, NumChannels, NumBits, MixRate);
|
2006-11-15 01:16:55 +00:00
|
|
|
if (status == FX_Ok)
|
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
FX_SetVolume(FXVolume);
|
2006-11-15 01:16:55 +00:00
|
|
|
if (ReverseStereo == 1)
|
|
|
|
{
|
2006-04-16 03:42:36 +00:00
|
|
|
FX_SetReverseStereo(!FX_GetReverseStereo());
|
|
|
|
}
|
2006-11-14 21:35:50 +00:00
|
|
|
status = FX_SetCallBack(testcallback);
|
2006-04-16 03:42:36 +00:00
|
|
|
}
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
if (status != FX_Ok)
|
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
sprintf(tempbuf, "Sound startup error: %s", FX_ErrorString(FX_Error));
|
2006-04-16 03:42:36 +00:00
|
|
|
gameexit(tempbuf);
|
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= SoundShutdown
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
void SoundShutdown(void)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
|
|
|
int32 status;
|
|
|
|
|
|
|
|
// if they chose None lets return
|
|
|
|
if (FXDevice < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
status = FX_Shutdown();
|
2006-11-15 01:16:55 +00:00
|
|
|
if (status != FX_Ok)
|
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
sprintf(tempbuf, "Sound shutdown error: %s", FX_ErrorString(FX_Error));
|
2006-04-16 03:42:36 +00:00
|
|
|
gameexit(tempbuf);
|
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= MusicStartup
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
void MusicStartup(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
int32 status;
|
|
|
|
|
|
|
|
// if they chose None lets return
|
|
|
|
if (MusicDevice < 0)
|
|
|
|
return;
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
status = MUSIC_Init(MusicDevice, 0);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (status == MUSIC_Ok)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
MUSIC_SetVolume(MusicVolume);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
initprintf("Couldn't find selected sound card, or, error w/ sound card itself.\n");
|
|
|
|
|
|
|
|
SoundShutdown();
|
|
|
|
uninittimer();
|
|
|
|
uninitengine();
|
|
|
|
CONTROL_Shutdown();
|
|
|
|
CONFIG_WriteSetup();
|
|
|
|
KB_Shutdown();
|
|
|
|
uninitgroupfile();
|
|
|
|
//unlink("duke3d.tmp");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= MusicShutdown
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
void MusicShutdown(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
int32 status;
|
|
|
|
|
|
|
|
// if they chose None lets return
|
|
|
|
if (MusicDevice < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
status = MUSIC_Shutdown();
|
2006-11-14 21:35:50 +00:00
|
|
|
if (status != MUSIC_Ok)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
Error(MUSIC_ErrorString(MUSIC_ErrorCode));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusicUpdate(void)
|
|
|
|
{
|
|
|
|
MUSIC_Update();
|
|
|
|
}
|
|
|
|
|
2006-11-19 08:24:46 +00:00
|
|
|
unsigned char menunum=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
void intomenusounds(void)
|
|
|
|
{
|
|
|
|
short menusnds[] =
|
|
|
|
{
|
|
|
|
LASERTRIP_EXPLODE,
|
|
|
|
DUKE_GRUNT,
|
|
|
|
DUKE_LAND_HURT,
|
|
|
|
CHAINGUN_FIRE,
|
|
|
|
SQUISHED,
|
|
|
|
KICK_HIT,
|
|
|
|
PISTOL_RICOCHET,
|
|
|
|
PISTOL_BODYHIT,
|
|
|
|
PISTOL_FIRE,
|
|
|
|
SHOTGUN_FIRE,
|
|
|
|
BOS1_WALK,
|
|
|
|
RPG_EXPLODE,
|
|
|
|
PIPEBOMB_BOUNCE,
|
|
|
|
PIPEBOMB_EXPLODE,
|
|
|
|
NITEVISION_ONOFF,
|
|
|
|
RPG_SHOOT,
|
|
|
|
SELECT_WEAPON
|
|
|
|
};
|
|
|
|
sound(menusnds[menunum++]);
|
|
|
|
menunum %= 17;
|
|
|
|
}
|
|
|
|
|
2006-12-23 02:38:47 +00:00
|
|
|
void playmusic(const char *fn)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-16 03:02:42 +00:00
|
|
|
#if defined(_WIN32)
|
2006-04-13 20:47:06 +00:00
|
|
|
short fp;
|
|
|
|
long l;
|
|
|
|
|
2006-12-06 23:14:49 +00:00
|
|
|
if (fn == NULL) return;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (MusicToggle == 0) return;
|
|
|
|
if (MusicDevice < 0) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-12-23 02:38:47 +00:00
|
|
|
fp = kopen4load((char *)fn,0);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (fp == -1) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
l = kfilelength(fp);
|
2006-11-13 23:12:47 +00:00
|
|
|
if (l >= (signed long)sizeof(MusicPtr))
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
kclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
kread(fp, MusicPtr, l);
|
|
|
|
kclose(fp);
|
2006-11-19 03:02:36 +00:00
|
|
|
MUSIC_PlaySong((unsigned char *)MusicPtr, MUSIC_LoopSong);
|
2006-11-16 03:02:42 +00:00
|
|
|
#else
|
|
|
|
void PlayMusic(char *_filename);
|
2006-11-20 04:55:37 +00:00
|
|
|
|
2006-12-06 23:14:49 +00:00
|
|
|
if (fn == NULL) return;
|
|
|
|
|
2007-03-01 00:50:59 +00:00
|
|
|
if (MusicToggle == 0) return;
|
|
|
|
if (MusicDevice < 0) return;
|
2006-11-16 03:02:42 +00:00
|
|
|
|
2007-03-01 00:50:59 +00:00
|
|
|
// FIXME: I need this to get the music volume initialized (not sure why) -- Jim Bentler
|
|
|
|
MUSIC_SetVolume(MusicVolume);
|
2007-01-04 07:15:17 +00:00
|
|
|
PlayMusic((char *)fn);
|
2006-11-16 03:02:42 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
int loadsound(unsigned int num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
long fp, l;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (num >= NUM_SOUNDS || SoundToggle == 0) return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
if (FXDevice < 0) return 0;
|
|
|
|
|
|
|
|
fp = kopen4load(sounds[num],loadfromgrouponly);
|
2006-11-13 23:12:47 +00:00
|
|
|
if (fp == -1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-10-10 23:04:38 +00:00
|
|
|
// Bsprintf(fta_quotes[113],"Sound %s(#%d) not found.",sounds[num],num);
|
|
|
|
// FTA(113,&ps[myconnectindex]);
|
|
|
|
initprintf("Sound %s(#%d) not found.\n",sounds[num],num);
|
2006-04-13 20:47:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
l = kfilelength(fp);
|
2006-04-13 20:47:06 +00:00
|
|
|
soundsiz[num] = l;
|
|
|
|
|
|
|
|
Sound[num].lock = 200;
|
|
|
|
|
|
|
|
allocache((long *)&Sound[num].ptr,l,(char *)&Sound[num].lock);
|
2006-11-14 21:35:50 +00:00
|
|
|
kread(fp, Sound[num].ptr , l);
|
|
|
|
kclose(fp);
|
2006-04-13 20:47:06 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
int xyzsound(int num,int i,long x,long y,long z)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
long sndist, cx, cy, cz, j,k;
|
2007-02-28 09:12:41 +00:00
|
|
|
int pitche,pitchs,cs;
|
2006-04-13 20:47:06 +00:00
|
|
|
int voice, sndang, ca, pitch;
|
|
|
|
|
|
|
|
// if(num != 358) return 0;
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (num >= NUM_SOUNDS ||
|
2006-04-13 20:47:06 +00:00
|
|
|
FXDevice < 0 ||
|
2006-11-14 21:35:50 +00:00
|
|
|
((soundm[num]&8) && ud.lockout) ||
|
2006-04-13 20:47:06 +00:00
|
|
|
SoundToggle == 0 ||
|
|
|
|
Sound[num].num > 3 ||
|
|
|
|
FX_VoiceAvailable(soundpr[num]) == 0 ||
|
|
|
|
(ps[myconnectindex].timebeforeexit > 0 && ps[myconnectindex].timebeforeexit <= 26*3) ||
|
|
|
|
ps[myconnectindex].gm&MODE_MENU) return -1;
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (soundm[num]&128)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
sound(num);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (soundm[num]&4)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
if (VoiceToggle==0)
|
2006-04-16 03:42:36 +00:00
|
|
|
return -1;
|
2006-05-10 21:00:56 +00:00
|
|
|
else if (ud.multimode > 1 && PN == APLAYER && sprite[i].yvel != screenpeek && VoiceToggle!=2)
|
2006-04-16 03:42:36 +00:00
|
|
|
return -1;
|
2006-11-13 23:12:47 +00:00
|
|
|
for (j=0;j<NUM_SOUNDS;j++)
|
|
|
|
for (k=0;k<Sound[j].num;k++)
|
2006-11-14 21:35:50 +00:00
|
|
|
if ((Sound[j].num > 0) && (soundm[j]&4))
|
2006-04-13 20:47:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cx = ps[screenpeek].oposx;
|
|
|
|
cy = ps[screenpeek].oposy;
|
|
|
|
cz = ps[screenpeek].oposz;
|
|
|
|
cs = ps[screenpeek].cursectnum;
|
|
|
|
ca = ps[screenpeek].ang+ps[screenpeek].look_ang;
|
|
|
|
|
|
|
|
sndist = FindDistance3D((cx-x),(cy-y),(cz-z)>>4);
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (i >= 0 && (soundm[num]&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9)
|
2006-04-13 20:47:06 +00:00
|
|
|
sndist = divscale14(sndist,(SHT+1));
|
|
|
|
|
|
|
|
pitchs = soundps[num];
|
|
|
|
pitche = soundpe[num];
|
|
|
|
cx = klabs(pitche-pitchs);
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (cx)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
if (pitchs < pitche)
|
|
|
|
pitch = pitchs + (rand()%cx);
|
|
|
|
else pitch = pitche + (rand()%cx);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else pitch = pitchs;
|
|
|
|
|
|
|
|
sndist += soundvo[num];
|
2006-11-13 23:12:47 +00:00
|
|
|
if (sndist < 0) sndist = 0;
|
2006-11-14 21:35:50 +00:00
|
|
|
if (sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,SX,SY,SZ-(24<<8),SECT))
|
2006-04-13 20:47:06 +00:00
|
|
|
sndist += sndist>>5;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
switch (num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-16 03:02:42 +00:00
|
|
|
case PIPEBOMB_EXPLODE:
|
|
|
|
case LASERTRIP_EXPLODE:
|
|
|
|
case RPG_EXPLODE:
|
|
|
|
if (sndist > (6144))
|
|
|
|
sndist = 6144;
|
|
|
|
if (sector[ps[screenpeek].cursectnum].lotag == 2)
|
|
|
|
pitch -= 1024;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (sector[ps[screenpeek].cursectnum].lotag == 2 && (soundm[num]&4) == 0)
|
|
|
|
pitch = -768;
|
|
|
|
if (sndist > 31444 && PN != MUSICANDSFX)
|
|
|
|
return -1;
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2006-10-10 23:04:38 +00:00
|
|
|
if (ps[screenpeek].sound_pitch) pitch += ps[screenpeek].sound_pitch;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (Sound[num].num > 0 && PN != MUSICANDSFX)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
if (SoundOwner[num][0].i == i) stopsound(num);
|
|
|
|
else if (Sound[num].num > 1) stopsound(num);
|
|
|
|
else if (badguy(&sprite[i]) && sprite[i].extra <= 0) stopsound(num);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (PN == APLAYER && sprite[i].yvel == screenpeek)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
sndang = 0;
|
|
|
|
sndist = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sndang = 2048 + ca - getangle(cx-x,cy-y);
|
|
|
|
sndang &= 2047;
|
|
|
|
}
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
if (Sound[num].ptr == 0)
|
|
|
|
{
|
|
|
|
if (loadsound(num) == 0) return 0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Sound[num].lock < 200)
|
|
|
|
Sound[num].lock = 200;
|
|
|
|
else Sound[num].lock++;
|
|
|
|
}
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (soundm[num]&16) sndist = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (sndist < ((255-LOUDESTVOLUME)<<6))
|
2006-04-13 20:47:06 +00:00
|
|
|
sndist = ((255-LOUDESTVOLUME)<<6);
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (soundm[num]&1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
unsigned short start;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (Sound[num].num > 0) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
start = *(unsigned short *)(Sound[num].ptr + 0x14);
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (*Sound[num].ptr == 'C')
|
2006-11-14 21:35:50 +00:00
|
|
|
voice = FX_PlayLoopedVOC(Sound[num].ptr, start, start + soundsiz[num],
|
|
|
|
pitch,sndist>>6,sndist>>6,0,soundpr[num],num);
|
2006-04-13 20:47:06 +00:00
|
|
|
else
|
2006-11-14 21:35:50 +00:00
|
|
|
voice = FX_PlayLoopedWAV(Sound[num].ptr, start, start + soundsiz[num],
|
|
|
|
pitch,sndist>>6,sndist>>6,0,soundpr[num],num);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
if (*Sound[num].ptr == 'C')
|
|
|
|
voice = FX_PlayVOC3D(Sound[ num ].ptr,pitch,sndang>>6,sndist>>6, soundpr[num], num);
|
2006-04-13 20:47:06 +00:00
|
|
|
else
|
2006-11-14 21:35:50 +00:00
|
|
|
voice = FX_PlayWAV3D(Sound[ num ].ptr,pitch,sndang>>6,sndist>>6, soundpr[num], num);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (voice > FX_Ok)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
SoundOwner[num][Sound[num].num].i = i;
|
|
|
|
SoundOwner[num][Sound[num].num].voice = voice;
|
|
|
|
Sound[num].num++;
|
|
|
|
}
|
|
|
|
else Sound[num].lock--;
|
|
|
|
return (voice);
|
|
|
|
}
|
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
void sound(int num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-02-28 09:12:41 +00:00
|
|
|
int pitch,pitche,pitchs,cx;
|
2006-04-13 20:47:06 +00:00
|
|
|
int voice;
|
|
|
|
long start;
|
|
|
|
|
|
|
|
if (FXDevice < 0) return;
|
2006-11-13 23:12:47 +00:00
|
|
|
if (SoundToggle==0) return;
|
2006-11-14 21:35:50 +00:00
|
|
|
if (VoiceToggle==0 && (soundm[num]&4)) return;
|
|
|
|
if ((soundm[num]&8) && ud.lockout) return;
|
2006-11-13 23:12:47 +00:00
|
|
|
if (FX_VoiceAvailable(soundpr[num]) == 0) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
pitchs = soundps[num];
|
|
|
|
pitche = soundpe[num];
|
|
|
|
cx = klabs(pitche-pitchs);
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (cx)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
if (pitchs < pitche)
|
|
|
|
pitch = pitchs + (rand()%cx);
|
|
|
|
else pitch = pitche + (rand()%cx);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else pitch = pitchs;
|
|
|
|
|
2006-11-15 01:16:55 +00:00
|
|
|
if (Sound[num].ptr == 0)
|
|
|
|
{
|
|
|
|
if (loadsound(num) == 0) return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Sound[num].lock < 200)
|
|
|
|
Sound[num].lock = 200;
|
|
|
|
else Sound[num].lock++;
|
|
|
|
}
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (soundm[num]&1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
if (*Sound[num].ptr == 'C')
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
start = (long)*(unsigned short *)(Sound[num].ptr + 0x14);
|
2006-11-14 21:35:50 +00:00
|
|
|
voice = FX_PlayLoopedVOC(Sound[num].ptr, start, start + soundsiz[num],
|
|
|
|
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,soundpr[num],num);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = (long)*(unsigned short *)(Sound[num].ptr + 0x14);
|
2006-11-14 21:35:50 +00:00
|
|
|
voice = FX_PlayLoopedWAV(Sound[num].ptr, start, start + soundsiz[num],
|
|
|
|
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,soundpr[num],num);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
if (*Sound[num].ptr == 'C')
|
2006-11-14 21:35:50 +00:00
|
|
|
voice = FX_PlayVOC3D(Sound[ num ].ptr, pitch,0,255-LOUDESTVOLUME,soundpr[num], num);
|
2006-04-13 20:47:06 +00:00
|
|
|
else
|
2006-11-14 21:35:50 +00:00
|
|
|
voice = FX_PlayWAV3D(Sound[ num ].ptr, pitch,0,255-LOUDESTVOLUME,soundpr[num], num);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (voice > FX_Ok) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
Sound[num].lock--;
|
|
|
|
}
|
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
int spritesound(unsigned int num, int i)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
if (num >= NUM_SOUNDS) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
return xyzsound(num,i,SX,SY,SZ);
|
|
|
|
}
|
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
void stopspritesound(int num, int i)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
|
|
|
stopsound(num);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
void stopsound(int num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
if (Sound[num].num > 0)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
FX_StopSound(SoundOwner[num][Sound[num].num-1].voice);
|
|
|
|
testcallback(num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
void stopenvsound(int num,int i)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-02-28 09:12:41 +00:00
|
|
|
int j, k;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (Sound[num].num > 0)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
k = Sound[num].num;
|
2006-11-13 23:12:47 +00:00
|
|
|
for (j=0;j<k;j++)
|
|
|
|
if (SoundOwner[num][j].i == i)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
FX_StopSound(SoundOwner[num][j].voice);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pan3dsound(void)
|
|
|
|
{
|
|
|
|
long sndist, sx, sy, sz, cx, cy, cz;
|
2007-02-28 09:12:41 +00:00
|
|
|
int sndang,ca,j,k,i,cs;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
numenvsnds = 0;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (ud.camerasprite == -1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
cx = ps[screenpeek].oposx;
|
|
|
|
cy = ps[screenpeek].oposy;
|
|
|
|
cz = ps[screenpeek].oposz;
|
|
|
|
cs = ps[screenpeek].cursectnum;
|
|
|
|
ca = ps[screenpeek].ang+ps[screenpeek].look_ang;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cx = sprite[ud.camerasprite].x;
|
|
|
|
cy = sprite[ud.camerasprite].y;
|
|
|
|
cz = sprite[ud.camerasprite].z;
|
|
|
|
cs = sprite[ud.camerasprite].sectnum;
|
|
|
|
ca = sprite[ud.camerasprite].ang;
|
|
|
|
}
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
for (j=0;j<NUM_SOUNDS;j++) for (k=0;k<Sound[j].num;k++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
i = SoundOwner[j][k].i;
|
|
|
|
|
|
|
|
sx = sprite[i].x;
|
|
|
|
sy = sprite[i].y;
|
|
|
|
sz = sprite[i].z;
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (PN == APLAYER && sprite[i].yvel == screenpeek)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
sndang = 0;
|
|
|
|
sndist = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sndang = 2048 + ca - getangle(cx-sx,cy-sy);
|
|
|
|
sndang &= 2047;
|
|
|
|
sndist = FindDistance3D((cx-sx),(cy-sy),(cz-sz)>>4);
|
2006-11-14 21:35:50 +00:00
|
|
|
if (i >= 0 && (soundm[j]&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9)
|
2006-04-13 20:47:06 +00:00
|
|
|
sndist = divscale14(sndist,(SHT+1));
|
|
|
|
}
|
|
|
|
|
|
|
|
sndist += soundvo[j];
|
2006-11-13 23:12:47 +00:00
|
|
|
if (sndist < 0) sndist = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,sx,sy,sz-(24<<8),SECT))
|
2006-04-13 20:47:06 +00:00
|
|
|
sndist += sndist>>5;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (PN == MUSICANDSFX && SLT < 999)
|
2006-04-13 20:47:06 +00:00
|
|
|
numenvsnds++;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
switch (j)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-16 03:02:42 +00:00
|
|
|
case PIPEBOMB_EXPLODE:
|
|
|
|
case LASERTRIP_EXPLODE:
|
|
|
|
case RPG_EXPLODE:
|
|
|
|
if (sndist > (6144)) sndist = (6144);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (sndist > 31444 && PN != MUSICANDSFX)
|
|
|
|
{
|
|
|
|
stopsound(j);
|
|
|
|
continue;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (Sound[j].ptr == 0 && loadsound(j) == 0) continue;
|
|
|
|
if (soundm[j]&16) sndist = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-14 21:35:50 +00:00
|
|
|
if (sndist < ((255-LOUDESTVOLUME)<<6))
|
2006-04-13 20:47:06 +00:00
|
|
|
sndist = ((255-LOUDESTVOLUME)<<6);
|
|
|
|
|
|
|
|
FX_Pan3D(SoundOwner[j][k].voice,sndang>>6,sndist>>6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testcallback(unsigned long num)
|
|
|
|
{
|
2007-02-28 09:12:41 +00:00
|
|
|
int tempi,tempj,tempk;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if ((long)num < 0)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
if (lumplockbyte[-num] >= 200)
|
2006-04-13 20:47:06 +00:00
|
|
|
lumplockbyte[-num]--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempk = Sound[num].num;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (tempk > 0)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-14 21:35:50 +00:00
|
|
|
if ((soundm[num]&16) == 0)
|
2006-11-13 23:12:47 +00:00
|
|
|
for (tempj=0;tempj<tempk;tempj++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
tempi = SoundOwner[num][tempj].i;
|
2006-11-13 23:12:47 +00:00
|
|
|
if (sprite[tempi].picnum == MUSICANDSFX && sector[sprite[tempi].sectnum].lotag < 3 && sprite[tempi].lotag < 999)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
hittype[tempi].temp_data[0] = 0;
|
2006-11-14 21:35:50 +00:00
|
|
|
if ((tempj + 1) < tempk)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
SoundOwner[num][tempj].voice = SoundOwner[num][tempk-1].voice;
|
|
|
|
SoundOwner[num][tempj].i = SoundOwner[num][tempk-1].i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Sound[num].num--;
|
|
|
|
SoundOwner[num][tempk-1].i = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sound[num].lock--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearsoundlocks(void)
|
|
|
|
{
|
|
|
|
long i;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
for (i=0;i<NUM_SOUNDS;i++)
|
|
|
|
if (Sound[i].lock >= 200)
|
2006-04-13 20:47:06 +00:00
|
|
|
Sound[i].lock = 199;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
for (i=0;i<11;i++)
|
|
|
|
if (lumplockbyte[i] >= 200)
|
2006-04-13 20:47:06 +00:00
|
|
|
lumplockbyte[i] = 199;
|
|
|
|
}
|
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
int isspritemakingsound(int i, int num)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
|
|
|
if (num < 0) num=0; // FIXME
|
2006-05-22 01:05:56 +00:00
|
|
|
return (Sound[num].num > 0);
|
2006-04-16 03:42:36 +00:00
|
|
|
}
|
|
|
|
|
2007-02-28 09:12:41 +00:00
|
|
|
int issoundplaying(int i, int num)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
2006-11-15 01:16:55 +00:00
|
|
|
if (i == -1)
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
if (Sound[num].lock == 200)
|
2006-07-01 12:10:29 +00:00
|
|
|
return 1;
|
2006-12-15 01:09:25 +00:00
|
|
|
return 0;
|
2006-07-01 12:10:29 +00:00
|
|
|
}
|
2006-12-15 01:09:25 +00:00
|
|
|
return(Sound[num].num);
|
2006-04-16 03:42:36 +00:00
|
|
|
}
|