2009-03-15 22:58:20 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
2010-05-25 10:56:00 +00:00
|
|
|
Copyright (C) 2010 EDuke32 developers and contributors
|
2009-03-15 22:58:20 +00:00
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
This file is part of EDuke32.
|
2009-03-15 22:58:20 +00:00
|
|
|
|
|
|
|
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
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-03-15 22:58:20 +00:00
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Stripped sounds.c for use in Mapster32, breaks all ties to game & music
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-04-26 05:57:42 +00:00
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
#include "compat.h"
|
2011-05-15 22:37:24 +00:00
|
|
|
#include "baselayer.h"
|
2009-07-27 05:33:12 +00:00
|
|
|
|
2009-03-15 22:58:20 +00:00
|
|
|
#include "fx_man.h"
|
|
|
|
#include "osd.h"
|
|
|
|
|
|
|
|
#include "cache1d.h"
|
|
|
|
#include "build.h" // vec3_t
|
2011-05-15 22:37:24 +00:00
|
|
|
#include "editor.h"
|
2009-03-15 22:58:20 +00:00
|
|
|
|
2012-11-25 13:18:36 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "mathutil.h"
|
|
|
|
|
2013-06-01 06:57:00 +00:00
|
|
|
#ifdef _WIN32
|
2010-07-19 15:14:00 +00:00
|
|
|
#include "winlayer.h"
|
|
|
|
#endif
|
|
|
|
|
2009-03-15 22:58:20 +00:00
|
|
|
#include "sounds_mapster32.h"
|
|
|
|
|
|
|
|
#define LOUDESTVOLUME 150
|
|
|
|
#define MUSICANDSFX 5
|
|
|
|
|
|
|
|
static char SM32_havesound = 0;
|
2009-07-09 02:29:48 +00:00
|
|
|
|
2012-03-10 21:21:42 +00:00
|
|
|
static char SoundToggle = 1;
|
2009-03-17 21:57:30 +00:00
|
|
|
int32_t NumVoices = 32;
|
2010-08-17 20:00:44 +00:00
|
|
|
int32_t MixRate = 44100;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
2012-03-10 21:21:42 +00:00
|
|
|
int32_t g_numEnvSoundsPlaying;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
|
|
|
void MUSIC_Update(void) {} // needed when linking
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
void S_Callback(uint32_t);
|
2009-03-15 22:58:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= SoundStartup
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
|
2009-03-15 22:58:20 +00:00
|
|
|
int32_t S_SoundStartup(void)
|
|
|
|
{
|
2009-07-27 05:33:12 +00:00
|
|
|
int32_t status;
|
|
|
|
int32_t fxdevicetype;
|
2010-08-02 08:13:51 +00:00
|
|
|
void *initdata = 0;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
|
|
|
// TODO: read config
|
2010-08-17 20:00:44 +00:00
|
|
|
int32_t FXVolume=220, /*NumVoices=32,*/ NumChannels=2, NumBits=16, ReverseStereo=0;
|
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
fxdevicetype = ASS_AutoDetect;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
2013-10-07 10:05:03 +00:00
|
|
|
#ifdef MIXERTYPEWIN
|
2012-11-25 04:26:37 +00:00
|
|
|
initdata = (void *) win_gethwnd(); // used for DirectSound
|
2009-07-27 05:33:12 +00:00
|
|
|
#endif
|
2009-03-15 22:58:20 +00:00
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
status = FX_Init(fxdevicetype, NumVoices, NumChannels, NumBits, MixRate, initdata);
|
2009-03-15 22:58:20 +00:00
|
|
|
if (status == FX_Ok)
|
|
|
|
{
|
|
|
|
FX_SetVolume(FXVolume);
|
2009-07-27 05:33:12 +00:00
|
|
|
FX_SetReverseStereo(ReverseStereo);
|
2010-02-23 18:13:46 +00:00
|
|
|
status = FX_SetCallBack(S_Callback);
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status != FX_Ok)
|
|
|
|
{
|
2013-04-13 03:49:35 +00:00
|
|
|
initprintf("Sound startup error: %s\n", FX_ErrorString(FX_Error));
|
2009-03-15 22:58:20 +00:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
SM32_havesound = 1;
|
2009-07-27 05:33:12 +00:00
|
|
|
|
2009-03-15 22:58:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= SoundShutdown
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void S_SoundShutdown(void)
|
|
|
|
{
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
|
if (!SM32_havesound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
status = FX_Shutdown();
|
|
|
|
if (status != FX_Ok)
|
2013-04-13 03:49:35 +00:00
|
|
|
initprintf("Sound shutdown error: %s\n", FX_ErrorString(FX_Error));
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t S_LoadSound(uint32_t num)
|
|
|
|
{
|
|
|
|
int32_t fp = -1, l;
|
|
|
|
|
|
|
|
if (!SM32_havesound) return 0;
|
|
|
|
if (num >= MAXSOUNDS || SoundToggle == 0) return 0;
|
|
|
|
|
|
|
|
if (g_sounds[num].filename == NULL)
|
|
|
|
{
|
|
|
|
OSD_Printf(OSD_ERROR "Sound (#%d) not defined!\n",num);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-16 19:39:22 +00:00
|
|
|
if (g_sounds[num].filename1) fp = kopen4loadfrommod(g_sounds[num].filename1,0);//pathsearchmode
|
|
|
|
if (fp == -1) fp = kopen4loadfrommod(g_sounds[num].filename,0);
|
2009-03-15 22:58:20 +00:00
|
|
|
if (fp == -1)
|
|
|
|
{
|
|
|
|
OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = kfilelength(fp);
|
|
|
|
g_sounds[num].soundsiz = l;
|
|
|
|
|
|
|
|
g_sounds[num].lock = 200;
|
|
|
|
|
|
|
|
allocache((intptr_t *)&g_sounds[num].ptr,l,(char *)&g_sounds[num].lock);
|
|
|
|
kread(fp, g_sounds[num].ptr , l);
|
|
|
|
kclose(fp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-08-06 10:12:13 +00:00
|
|
|
int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
2009-03-17 21:57:30 +00:00
|
|
|
int32_t sndist, cx, cy, cz, j/*,k*/;
|
2009-03-15 22:58:20 +00:00
|
|
|
int32_t pitche,pitchs,cs;
|
|
|
|
int32_t voice, sndang, ca, pitch;
|
|
|
|
|
|
|
|
// if(num != 358) return 0;
|
|
|
|
|
|
|
|
if (num >= MAXSOUNDS ||
|
2009-04-13 06:53:03 +00:00
|
|
|
!SM32_havesound ||
|
2013-09-08 20:18:56 +00:00
|
|
|
// ((g_sounds[num].m & SF_ADULT) && ud.lockout) ||
|
2009-04-13 06:53:03 +00:00
|
|
|
SoundToggle == 0 ||
|
|
|
|
g_sounds[num].num > 3 ||
|
|
|
|
FX_VoiceAvailable(g_sounds[num].pr) == 0)
|
|
|
|
return -1;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
2013-09-08 20:18:56 +00:00
|
|
|
if (g_sounds[num].m & SF_DTAG)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
|
|
|
S_PlaySound(num);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-08 20:18:56 +00:00
|
|
|
if (g_sounds[num].m & SF_TALK)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
|
|
|
for (j=0; j<MAXSOUNDS; j++)
|
|
|
|
// for (k=0; k<g_sounds[j].num; k++)
|
2013-09-08 20:18:56 +00:00
|
|
|
if ((g_sounds[j].num > 0) && (g_sounds[j].m & SF_TALK))
|
2009-04-13 06:53:03 +00:00
|
|
|
return -1;
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cx = pos->x;
|
|
|
|
cy = pos->y;
|
|
|
|
cz = pos->z;
|
|
|
|
cs = cursectnum;
|
|
|
|
ca = ang;
|
|
|
|
|
|
|
|
sndist = FindDistance3D((cx-pos->x),(cy-pos->y),(cz-pos->z)>>4);
|
|
|
|
|
2013-09-08 20:18:56 +00:00
|
|
|
if (i >= 0 && (g_sounds[num].m & SF_GLOBAL) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9)
|
2009-03-15 22:58:20 +00:00
|
|
|
sndist = divscale14(sndist,(SHT+1));
|
|
|
|
|
|
|
|
pitchs = g_sounds[num].ps;
|
|
|
|
pitche = g_sounds[num].pe;
|
|
|
|
cx = klabs(pitche-pitchs);
|
|
|
|
|
|
|
|
if (cx)
|
|
|
|
{
|
|
|
|
if (pitchs < pitche)
|
|
|
|
pitch = pitchs + (rand()%cx);
|
|
|
|
else pitch = pitche + (rand()%cx);
|
|
|
|
}
|
|
|
|
else pitch = pitchs;
|
|
|
|
|
|
|
|
sndist += g_sounds[num].vo;
|
|
|
|
if (sndist < 0) sndist = 0;
|
|
|
|
if (cs > -1 && sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,SX,SY,SZ-(24<<8),SECT))
|
|
|
|
sndist += sndist>>5;
|
2009-04-13 06:53:03 +00:00
|
|
|
/*
|
|
|
|
switch (num)
|
|
|
|
{
|
|
|
|
case PIPEBOMB_EXPLODE:
|
|
|
|
case LASERTRIP_EXPLODE:
|
|
|
|
case RPG_EXPLODE:
|
|
|
|
if (sndist > (6144))
|
|
|
|
sndist = 6144;
|
|
|
|
if (g_player[screenpeek].ps->cursectnum > -1 && sector[g_player[screenpeek].ps->cursectnum].lotag == 2)
|
|
|
|
pitch -= 1024;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*/
|
2013-09-08 20:18:56 +00:00
|
|
|
if (cursectnum > -1 && sector[cursectnum].lotag == 2 && (g_sounds[num].m & SF_TALK) == 0)
|
2009-04-13 06:53:03 +00:00
|
|
|
pitch = -768;
|
|
|
|
if (sndist > 31444 && PN != MUSICANDSFX)
|
|
|
|
return -1;
|
2009-03-15 22:58:20 +00:00
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (g_sounds[num].num > 0 && PN != MUSICANDSFX)
|
|
|
|
{
|
2012-03-10 21:22:44 +00:00
|
|
|
if (g_sounds[num].SoundOwner[0].ow == i) S_StopSound(num);
|
2009-03-15 22:58:20 +00:00
|
|
|
else if (g_sounds[num].num > 1) S_StopSound(num);
|
|
|
|
// else if (A_CheckEnemySprite(&sprite[i]) && sprite[i].extra <= 0) S_StopSound(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
sndang = 2048 + ca - getangle(cx-pos->x,cy-pos->y);
|
|
|
|
sndang &= 2047;
|
|
|
|
|
|
|
|
if (g_sounds[num].ptr == 0)
|
|
|
|
{
|
|
|
|
if (S_LoadSound(num) == 0) return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (g_sounds[num].lock < 200)
|
|
|
|
g_sounds[num].lock = 200;
|
|
|
|
else g_sounds[num].lock++;
|
|
|
|
}
|
|
|
|
|
2013-09-08 20:18:56 +00:00
|
|
|
if (g_sounds[num].m & SF_GLOBAL) sndist = 0;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
|
|
|
if (sndist < ((255-LOUDESTVOLUME)<<6))
|
|
|
|
sndist = ((255-LOUDESTVOLUME)<<6);
|
|
|
|
|
2013-09-08 20:18:56 +00:00
|
|
|
if (g_sounds[num].m & SF_LOOP)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
2013-03-31 18:58:17 +00:00
|
|
|
if (g_sounds[num].num > 0)
|
|
|
|
return -1;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
voice = FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1,
|
2013-03-31 18:58:17 +00:00
|
|
|
pitch, sndist>>6, sndist>>6, 0, g_sounds[num].pr, num);
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-31 18:58:17 +00:00
|
|
|
voice = FX_PlayAuto3D(g_sounds[num].ptr, g_sounds[num].soundsiz, FX_ONESHOT,
|
|
|
|
pitch, sndang>>4, sndist>>6, g_sounds[num].pr, num);
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
|
2009-07-24 02:31:34 +00:00
|
|
|
if (voice >= FX_Ok)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[num].SoundOwner[g_sounds[num].num].ow = i;
|
2009-03-15 22:58:20 +00:00
|
|
|
g_sounds[num].SoundOwner[g_sounds[num].num].voice = voice;
|
|
|
|
g_sounds[num].num++;
|
|
|
|
}
|
|
|
|
else g_sounds[num].lock--;
|
|
|
|
return (voice);
|
|
|
|
}
|
|
|
|
|
|
|
|
void S_PlaySound(int32_t num)
|
|
|
|
{
|
|
|
|
int32_t pitch,pitche,pitchs,cx;
|
|
|
|
int32_t voice;
|
|
|
|
|
|
|
|
if (!SM32_havesound) return;
|
|
|
|
if (SoundToggle==0) return;
|
2012-01-23 19:13:00 +00:00
|
|
|
if ((unsigned)num >= MAXSOUNDS || !g_sounds[num].filename)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("WARNING: invalid sound #%d\n",num);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-08 20:18:56 +00:00
|
|
|
// if ((g_sounds[num].m & SF_ADULT) && ud.lockout) return;
|
2012-01-23 19:13:00 +00:00
|
|
|
if (FX_VoiceAvailable(g_sounds[num].pr) == 0) return;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
|
|
|
pitchs = g_sounds[num].ps;
|
|
|
|
pitche = g_sounds[num].pe;
|
|
|
|
cx = klabs(pitche-pitchs);
|
|
|
|
|
|
|
|
if (cx)
|
|
|
|
{
|
|
|
|
if (pitchs < pitche)
|
|
|
|
pitch = pitchs + (rand()%cx);
|
|
|
|
else pitch = pitche + (rand()%cx);
|
|
|
|
}
|
|
|
|
else pitch = pitchs;
|
|
|
|
|
|
|
|
if (g_sounds[num].ptr == 0)
|
|
|
|
{
|
|
|
|
if (S_LoadSound(num) == 0) return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (g_sounds[num].lock < 200)
|
|
|
|
g_sounds[num].lock = 200;
|
|
|
|
else g_sounds[num].lock++;
|
|
|
|
}
|
|
|
|
|
2013-09-08 20:18:56 +00:00
|
|
|
if (g_sounds[num].m & SF_LOOP)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
2009-07-27 05:33:12 +00:00
|
|
|
voice = FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1,
|
|
|
|
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].soundsiz,num);
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-31 18:58:17 +00:00
|
|
|
voice = FX_PlayAuto3D(g_sounds[num].ptr, g_sounds[num].soundsiz, FX_ONESHOT,
|
2012-01-23 19:13:00 +00:00
|
|
|
pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num);
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 19:13:00 +00:00
|
|
|
if (voice >= FX_Ok)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[num].SoundOwner[g_sounds[num].num].ow = -1;
|
2009-03-15 22:58:20 +00:00
|
|
|
g_sounds[num].SoundOwner[g_sounds[num].num].voice = voice;
|
|
|
|
g_sounds[num].num++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_sounds[num].lock--;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t A_PlaySound(uint32_t num, int32_t i)
|
|
|
|
{
|
|
|
|
if (num >= MAXSOUNDS) return -1;
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
S_PlaySound(num);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-06 10:12:13 +00:00
|
|
|
return S_PlaySound3D(num,i, (vec3_t *)&sprite[i]);
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void S_StopSound(int32_t num)
|
|
|
|
{
|
|
|
|
if (num >= 0 && num < MAXSOUNDS)
|
|
|
|
if (g_sounds[num].num > 0)
|
|
|
|
{
|
|
|
|
FX_StopSound(g_sounds[num].SoundOwner[g_sounds[num].num-1].voice);
|
2010-02-23 18:13:46 +00:00
|
|
|
S_Callback(num);
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void S_StopEnvSound(int32_t num,int32_t i)
|
|
|
|
{
|
|
|
|
int32_t j, k;
|
|
|
|
|
|
|
|
if (num >= 0 && num < MAXSOUNDS)
|
|
|
|
if (g_sounds[num].num > 0)
|
|
|
|
{
|
|
|
|
k = g_sounds[num].num;
|
|
|
|
for (j=0; j<k; j++)
|
2012-03-10 21:22:44 +00:00
|
|
|
if (g_sounds[num].SoundOwner[j].ow == i)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
|
|
|
FX_StopSound(g_sounds[num].SoundOwner[j].voice);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
void S_Update(void)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
|
|
|
int32_t sndist, sx, sy, sz, cx, cy, cz;
|
|
|
|
int32_t sndang,ca,j,k,i,cs;
|
|
|
|
|
|
|
|
g_numEnvSoundsPlaying = 0;
|
|
|
|
|
|
|
|
cx = pos.x;
|
|
|
|
cy = pos.y;
|
|
|
|
cz = pos.z;
|
|
|
|
cs = cursectnum;
|
|
|
|
ca = ang;
|
|
|
|
|
|
|
|
for (j=0; j<MAXSOUNDS; j++)
|
|
|
|
for (k=0; k<g_sounds[j].num; k++)
|
|
|
|
{
|
2012-03-10 21:22:44 +00:00
|
|
|
i = g_sounds[j].SoundOwner[k].ow;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
|
|
|
sx = sprite[i].x;
|
|
|
|
sy = sprite[i].y;
|
|
|
|
sz = sprite[i].z;
|
|
|
|
|
|
|
|
sndang = 2048 + ca - getangle(cx-sx,cy-sy);
|
|
|
|
sndang &= 2047;
|
|
|
|
sndist = FindDistance3D((cx-sx),(cy-sy),(cz-sz)>>4);
|
2013-09-08 20:18:56 +00:00
|
|
|
if (i >= 0 && (g_sounds[j].m & SF_GLOBAL) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9)
|
2009-03-15 22:58:20 +00:00
|
|
|
sndist = divscale14(sndist,(SHT+1));
|
|
|
|
|
|
|
|
sndist += g_sounds[j].vo;
|
|
|
|
if (sndist < 0) sndist = 0;
|
|
|
|
|
|
|
|
if (cs > -1 && sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,sx,sy,sz-(24<<8),SECT))
|
|
|
|
sndist += sndist>>5;
|
|
|
|
|
|
|
|
if (PN == MUSICANDSFX && SLT < 999)
|
|
|
|
g_numEnvSoundsPlaying++;
|
2009-04-13 06:53:03 +00:00
|
|
|
/*
|
|
|
|
switch (j)
|
|
|
|
{
|
|
|
|
case PIPEBOMB_EXPLODE:
|
|
|
|
case LASERTRIP_EXPLODE:
|
|
|
|
case RPG_EXPLODE:
|
|
|
|
if (sndist > (6144)) sndist = (6144);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*/
|
|
|
|
if (sndist > 31444 && PN != MUSICANDSFX)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
2009-04-13 06:53:03 +00:00
|
|
|
S_StopSound(j);
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-15 22:58:20 +00:00
|
|
|
// }
|
|
|
|
|
|
|
|
if (g_sounds[j].ptr == 0 && S_LoadSound(j) == 0) continue;
|
2013-09-08 20:18:56 +00:00
|
|
|
if (g_sounds[j].m & SF_GLOBAL) sndist = 0;
|
2009-03-15 22:58:20 +00:00
|
|
|
|
|
|
|
if (sndist < ((255-LOUDESTVOLUME)<<6))
|
|
|
|
sndist = ((255-LOUDESTVOLUME)<<6);
|
|
|
|
|
2009-07-26 19:01:39 +00:00
|
|
|
FX_Pan3D(g_sounds[j].SoundOwner[k].voice,sndang>>4,sndist>>6);
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
void S_Callback(uint32_t num)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
|
|
|
int32_t i,j,k;
|
|
|
|
|
|
|
|
k = g_sounds[num].num;
|
|
|
|
|
|
|
|
if (k > 0)
|
|
|
|
{
|
2013-09-08 20:18:56 +00:00
|
|
|
if ((g_sounds[num].m & SF_GLOBAL) == 0)
|
2009-03-15 22:58:20 +00:00
|
|
|
for (j=0; j<k; j++)
|
|
|
|
{
|
2012-03-10 21:22:44 +00:00
|
|
|
i = g_sounds[num].SoundOwner[j].ow;
|
2012-01-23 19:13:00 +00:00
|
|
|
if (i < 0)
|
|
|
|
continue;
|
|
|
|
|
2009-03-15 22:58:20 +00:00
|
|
|
if (sprite[i].picnum == MUSICANDSFX && sector[sprite[i].sectnum].lotag < 3 && sprite[i].lotag < 999)
|
|
|
|
{
|
2014-02-08 14:37:55 +00:00
|
|
|
extern uint8_t g_ambiencePlaying[MAXSPRITES>>3];
|
|
|
|
|
|
|
|
g_ambiencePlaying[i>>3] &= ~(1<<(i&7));
|
|
|
|
|
2012-01-23 19:13:00 +00:00
|
|
|
if (j < k-1)
|
2009-03-15 22:58:20 +00:00
|
|
|
{
|
|
|
|
g_sounds[num].SoundOwner[j].voice = g_sounds[num].SoundOwner[k-1].voice;
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[num].SoundOwner[j].ow = g_sounds[num].SoundOwner[k-1].ow;
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_sounds[num].num--;
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[num].SoundOwner[k-1].ow = -1;
|
2009-03-15 22:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_sounds[num].lock--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void S_ClearSoundLocks(void)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i=0; i<MAXSOUNDS; i++)
|
|
|
|
if (g_sounds[i].lock >= 200)
|
|
|
|
g_sounds[i].lock = 199;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t A_CheckSoundPlaying(int32_t i, int32_t num)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(i);
|
|
|
|
if (num < 0) num=0; // FIXME
|
|
|
|
return (g_sounds[num].num > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t S_CheckSoundPlaying(int32_t i, int32_t num)
|
|
|
|
{
|
|
|
|
if (i == -1)
|
|
|
|
{
|
2009-09-09 07:19:14 +00:00
|
|
|
if (g_sounds[num].lock >= 200)
|
2009-03-15 22:58:20 +00:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return(g_sounds[num].num);
|
|
|
|
}
|