2006-04-13 20:47:06 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
2010-05-25 10:56:00 +00:00
|
|
|
Copyright (C) 2010 EDuke32 developers and contributors
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
This file is part of EDuke32.
|
2006-04-13 20:47:06 +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
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-04-26 05:57:42 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "fx_man.h"
|
|
|
|
#include "music.h"
|
|
|
|
#include "duke3d.h"
|
2007-08-25 01:05:00 +00:00
|
|
|
#include "osd.h"
|
2010-08-02 08:13:51 +00:00
|
|
|
#include "sounds.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-07-19 15:14:00 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include "winlayer.h"
|
|
|
|
#endif
|
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
int32_t g_numEnvSoundsPlaying,g_maxSoundPos = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
static int32_t MusicIsWaveform = 0;
|
2010-08-02 08:13:51 +00:00
|
|
|
static char *MusicPtr = 0;
|
2009-07-27 05:33:12 +00:00
|
|
|
static int32_t MusicLen = 0;
|
|
|
|
static int32_t MusicVoice = -1;
|
|
|
|
static int32_t MusicPaused = 0;
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
static mutex_t s_mutex;
|
2010-07-19 15:14:00 +00:00
|
|
|
static volatile uint32_t dq[128], dnum = 0;
|
2010-06-22 21:50:01 +00:00
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
void S_SoundStartup(void)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
2010-08-02 08:13:51 +00:00
|
|
|
int32_t fxdevicetype, i;
|
|
|
|
void *initdata = 0;
|
2006-04-16 03:42:36 +00:00
|
|
|
|
2009-08-06 10:12:13 +00:00
|
|
|
if (ud.config.FXDevice >= 0)
|
2009-07-27 05:33:12 +00:00
|
|
|
fxdevicetype = ASS_AutoDetect;
|
2009-08-06 10:12:13 +00:00
|
|
|
else return;
|
2006-04-16 03:42:36 +00:00
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
initdata = (void *) win_gethwnd();
|
|
|
|
#endif
|
2009-07-09 02:29:48 +00:00
|
|
|
|
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
|
|
|
initprintf("Initializing sound... ");
|
2009-08-06 10:12:13 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (FX_Init(fxdevicetype, ud.config.NumVoices, ud.config.NumChannels, ud.config.NumBits, ud.config.MixRate, initdata) != FX_Ok)
|
2006-11-15 01:16:55 +00:00
|
|
|
{
|
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
|
|
|
initprintf("failed! %s\n", FX_ErrorString(FX_Error));
|
2011-01-23 04:59:04 +00:00
|
|
|
return;
|
2006-04-16 03:42:36 +00:00
|
|
|
}
|
2009-07-27 05:33:12 +00:00
|
|
|
|
2012-03-10 21:21:42 +00:00
|
|
|
initprintf("%d voices, %d channels, %d-bit %d Hz\n", ud.config.NumVoices, ud.config.NumChannels,
|
Patch from Hendricks266 and whatever changes happened to be in my tree. I hope they work ;)
"The most noticeable change is the addition of the "includedefault" CON and DEF command, which will attempt to include eduke.con (or nam.con, or ww2gi.con), then game.con, or duke3d.def, or nam.def, or ww2gi.def. This is useful for TCs like my add-ons, where for my pseudo-mutators I currently say "include EDUKE.CON", but I also have to juggle this terrible order of paths, so that I can have an EDUKE.CON file in my HRP which says "include GAME.CON" to allow the mainline game to actually run, but also allow DukePlus to load its EDUKE.CON file (since it uses that and not an -x switch), and also allow any custom EDUKE.CON files in the root to be used."
git-svn-id: https://svn.eduke32.com/eduke32@1909 1a8010ca-5511-0410-912e-c29ae57300e0
2011-06-19 00:11:52 +00:00
|
|
|
ud.config.NumBits, ud.config.MixRate);
|
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
for (i=g_maxSoundPos; i >= 0 ; i--)
|
|
|
|
{
|
|
|
|
int32_t j = MAXSOUNDINSTANCES-1;
|
|
|
|
|
|
|
|
for (; j>=0; j--)
|
|
|
|
{
|
|
|
|
g_sounds[i].num = 0;
|
|
|
|
g_sounds[i].SoundOwner[j].voice = 0;
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[i].SoundOwner[j].ow = -1;
|
2012-10-08 07:07:59 +00:00
|
|
|
g_sounds[i].SoundOwner[j].sndist = UINT32_MAX;
|
|
|
|
g_sounds[i].SoundOwner[j].clock = 0;
|
2010-08-02 08:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_soundlocks[i] = 199;
|
|
|
|
}
|
|
|
|
|
2009-08-06 10:12:13 +00:00
|
|
|
FX_SetVolume(ud.config.FXVolume);
|
|
|
|
FX_SetReverseStereo(ud.config.ReverseStereo);
|
2010-03-01 09:09:26 +00:00
|
|
|
FX_SetCallBack(S_Callback);
|
2010-06-22 21:50:01 +00:00
|
|
|
FX_SetPrintf(initprintf);
|
|
|
|
mutex_init(&s_mutex);
|
2006-04-16 03:42:36 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
void S_SoundShutdown(void)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
2007-08-27 00:20:15 +00:00
|
|
|
if (ud.config.FXDevice < 0)
|
2006-04-16 03:42:36 +00:00
|
|
|
return;
|
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
if (MusicVoice >= 0)
|
|
|
|
S_MusicShutdown();
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (FX_Shutdown() != FX_Ok)
|
2006-11-15 01:16:55 +00:00
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
Bsprintf(tempbuf, "S_SoundShutdown(): error: %s", FX_ErrorString(FX_Error));
|
2008-11-20 14:06:36 +00:00
|
|
|
G_GameExit(tempbuf);
|
2006-04-16 03:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
void S_MusicStartup(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-08-27 00:20:15 +00:00
|
|
|
if (ud.config.MusicDevice < 0)
|
2006-04-13 20:47:06 +00:00
|
|
|
return;
|
|
|
|
|
2009-07-09 02:29:48 +00:00
|
|
|
initprintf("Initializing music...\n");
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (MUSIC_Init(ud.config.MusicDevice, 0) == MUSIC_Ok || MUSIC_Init((ud.config.MusicDevice = 0), 0) == MUSIC_Ok)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-08-27 00:20:15 +00:00
|
|
|
MUSIC_SetVolume(ud.config.MusicVolume);
|
2010-03-01 09:09:26 +00:00
|
|
|
return;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2009-02-28 07:44:54 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
initprintf("S_MusicStartup(): failed initializing\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
void S_MusicShutdown(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-08-27 00:20:15 +00:00
|
|
|
if (ud.config.MusicDevice < 0)
|
2006-04-13 20:47:06 +00:00
|
|
|
return;
|
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
S_StopMusic();
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (MUSIC_Shutdown() != MUSIC_Ok)
|
2010-12-19 22:47:10 +00:00
|
|
|
initprintf("%s", MUSIC_ErrorString(MUSIC_ErrorCode));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
void S_PauseMusic(int32_t onf)
|
|
|
|
{
|
|
|
|
if (MusicPaused == onf || (MusicIsWaveform && MusicVoice < 0))
|
|
|
|
return;
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
MusicPaused = onf;
|
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
if (MusicIsWaveform)
|
2009-07-31 11:45:29 +00:00
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
FX_PauseVoice(MusicVoice, onf);
|
|
|
|
return;
|
2009-07-31 11:45:29 +00:00
|
|
|
}
|
2009-07-27 05:33:12 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (onf)
|
|
|
|
MUSIC_Pause();
|
|
|
|
else
|
|
|
|
MUSIC_Continue();
|
2009-07-27 05:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void S_MusicVolume(int32_t volume)
|
|
|
|
{
|
|
|
|
if (MusicIsWaveform && MusicVoice >= 0)
|
|
|
|
FX_SetPan(MusicVoice, volume, volume, volume);
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
MUSIC_SetVolume(volume);
|
|
|
|
}
|
2009-07-27 05:33:12 +00:00
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
void S_MenuSound(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t SoundNum=0;
|
2010-03-01 09:09:26 +00:00
|
|
|
static const uint8_t menusnds[] =
|
2007-08-25 01:05:00 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
};
|
2009-01-05 14:43:12 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
S_PlaySound(menusnds[SoundNum++ % (sizeof(menusnds)/sizeof(menusnds[0]))]);
|
2008-04-01 09:06:29 +00:00
|
|
|
}
|
2009-07-27 05:33:12 +00:00
|
|
|
|
|
|
|
int32_t S_PlayMusic(const char *fn, const int32_t sel)
|
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
char *ofn = (char *)fn, *testfn, *extension;
|
2009-07-27 05:33:12 +00:00
|
|
|
int32_t fp;
|
2010-03-01 09:09:26 +00:00
|
|
|
const char *alt = 0;
|
2009-07-27 05:33:12 +00:00
|
|
|
|
|
|
|
if (ud.config.MusicToggle == 0) return 0;
|
|
|
|
if (ud.config.MusicDevice < 0) return 0;
|
|
|
|
|
2009-07-28 08:28:58 +00:00
|
|
|
if (MapInfo[sel].alt_musicfn != NULL)
|
2010-02-10 18:20:30 +00:00
|
|
|
alt = fn = MapInfo[sel].alt_musicfn;
|
2010-01-23 22:12:02 +00:00
|
|
|
|
2009-10-07 06:47:35 +00:00
|
|
|
testfn = (char *) Bmalloc(strlen(fn) + 5);
|
2009-07-27 05:33:12 +00:00
|
|
|
strcpy(testfn, fn);
|
|
|
|
extension = strrchr(testfn, '.');
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (extension && !Bstrcasecmp(extension, ".mid"))
|
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
// we've been asked to load a .mid file, but first let's see
|
|
|
|
// if there's an ogg with the same base name lying around
|
2009-07-27 05:33:12 +00:00
|
|
|
strcpy(extension, ".ogg");
|
2009-07-28 06:32:58 +00:00
|
|
|
fp = kopen4loadfrommod(testfn, 0);
|
2009-07-27 05:33:12 +00:00
|
|
|
if (fp >= 0)
|
|
|
|
{
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(testfn);
|
2009-07-27 05:33:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-03-01 09:09:26 +00:00
|
|
|
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(testfn);
|
2009-07-27 05:33:12 +00:00
|
|
|
|
|
|
|
// just use what we've been given
|
2009-07-28 06:32:58 +00:00
|
|
|
fp = kopen4loadfrommod((char *)fn, 0);
|
2009-07-28 08:28:58 +00:00
|
|
|
|
|
|
|
if (alt && fp < 0)
|
|
|
|
fp = kopen4loadfrommod(ofn, 0);
|
2009-07-27 05:33:12 +00:00
|
|
|
}
|
|
|
|
while (0);
|
|
|
|
|
2009-08-09 05:32:17 +00:00
|
|
|
if (fp < 0)
|
|
|
|
{
|
2012-03-26 05:05:57 +00:00
|
|
|
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: can't open \"%s\" for playback!\n",fn);
|
2009-08-09 05:32:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-07-27 05:33:12 +00:00
|
|
|
|
|
|
|
S_StopMusic();
|
|
|
|
|
2010-07-19 15:14:00 +00:00
|
|
|
MusicPtr = (char *) Bmalloc((MusicLen = kfilelength(fp)));
|
2009-08-09 05:32:17 +00:00
|
|
|
|
|
|
|
if ((g_musicSize = kread(fp, (char *)MusicPtr, MusicLen)) != MusicLen)
|
|
|
|
{
|
2012-03-26 05:05:57 +00:00
|
|
|
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: read %d bytes from \"%s\", expected %d\n",g_musicSize, fn, MusicLen);
|
2009-08-09 05:32:17 +00:00
|
|
|
kclose(fp);
|
|
|
|
g_musicSize = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
kclose(fp);
|
|
|
|
|
2009-07-27 10:46:42 +00:00
|
|
|
if (!Bmemcmp(MusicPtr, "MThd", 4))
|
2009-07-27 05:33:12 +00:00
|
|
|
{
|
|
|
|
MUSIC_PlaySong(MusicPtr, MUSIC_LoopSong);
|
|
|
|
MusicIsWaveform = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-09 05:32:17 +00:00
|
|
|
if ((MusicVoice = FX_PlayLoopedAuto(MusicPtr, MusicLen, 0, 0, 0, ud.config.MusicVolume,
|
2010-01-23 22:12:02 +00:00
|
|
|
ud.config.MusicVolume, ud.config.MusicVolume,
|
2010-06-22 21:50:01 +00:00
|
|
|
FX_MUSIC_PRIORITY, MUSIC_ID)) > FX_Ok)
|
2009-08-09 05:32:17 +00:00
|
|
|
MusicIsWaveform = 1;
|
2009-07-27 05:33:12 +00:00
|
|
|
}
|
2009-07-28 08:28:58 +00:00
|
|
|
return (alt != 0);
|
2009-07-27 05:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void S_StopMusic(void)
|
|
|
|
{
|
2009-08-09 05:32:17 +00:00
|
|
|
MusicPaused = 0;
|
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
if (MusicIsWaveform && MusicVoice >= 0)
|
|
|
|
{
|
|
|
|
FX_StopSound(MusicVoice);
|
|
|
|
MusicVoice = -1;
|
2009-08-09 05:32:17 +00:00
|
|
|
MusicIsWaveform = 0;
|
2009-07-27 05:33:12 +00:00
|
|
|
}
|
2009-07-27 10:46:42 +00:00
|
|
|
|
|
|
|
MUSIC_StopSong();
|
2009-07-27 05:33:12 +00:00
|
|
|
|
|
|
|
if (MusicPtr)
|
|
|
|
{
|
|
|
|
Bfree(MusicPtr);
|
2009-08-06 10:12:13 +00:00
|
|
|
MusicPtr = NULL;
|
2009-07-28 06:32:58 +00:00
|
|
|
g_musicSize = MusicLen = 0;
|
2009-07-27 05:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
void S_Cleanup(void)
|
|
|
|
{
|
|
|
|
// process from our own local copy of the delete queue so we don't hold the lock long
|
|
|
|
uint32_t ldq[128], ldnum;
|
|
|
|
|
|
|
|
mutex_lock(&s_mutex);
|
|
|
|
|
|
|
|
if (!dnum)
|
|
|
|
{
|
|
|
|
mutex_unlock(&s_mutex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-13 20:07:40 +00:00
|
|
|
ldnum = dnum;
|
|
|
|
Bmemcpy(ldq, (void *)dq, ldnum*sizeof(int32_t));
|
2010-06-22 21:50:01 +00:00
|
|
|
dnum = 0;
|
|
|
|
|
|
|
|
mutex_unlock(&s_mutex);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
uint32_t num = ldq[--ldnum];
|
|
|
|
|
|
|
|
// negative index is RTS playback
|
|
|
|
if ((int32_t)num < 0)
|
|
|
|
{
|
2010-08-02 08:13:51 +00:00
|
|
|
if (rts_lumplockbyte[-(int32_t)num] >= 200)
|
|
|
|
rts_lumplockbyte[-(int32_t)num]--;
|
2010-06-22 21:50:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-30 19:48:46 +00:00
|
|
|
// num + (MAXSOUNDS*MAXSOUNDINSTANCES) is a sound played globally
|
|
|
|
// for which there was no open slot to keep track of the voice
|
|
|
|
if (num >= (MAXSOUNDS*MAXSOUNDINSTANCES))
|
2011-05-28 14:15:41 +00:00
|
|
|
{
|
2011-10-30 19:48:46 +00:00
|
|
|
g_soundlocks[num-(MAXSOUNDS*MAXSOUNDINSTANCES)]--;
|
2011-05-28 14:15:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
{
|
|
|
|
int32_t j = num & (MAXSOUNDINSTANCES-1);
|
2010-07-03 08:53:57 +00:00
|
|
|
int32_t i;
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
num = (num - j) / MAXSOUNDINSTANCES;
|
|
|
|
|
2012-03-10 21:22:44 +00:00
|
|
|
i = g_sounds[num].SoundOwner[j].ow;
|
2010-07-03 08:53:57 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
if (g_sounds[num].num > MAXSOUNDINSTANCES)
|
|
|
|
OSD_Printf(OSD_ERROR "S_Cleanup(): num exceeds MAXSOUNDINSTANCES! g_sounds[%d].num %d wtf?\n", num, g_sounds[num].num);
|
|
|
|
|
|
|
|
if (g_sounds[num].num > 0)
|
2010-07-03 08:53:57 +00:00
|
|
|
g_sounds[num].num--;
|
2010-06-22 21:50:01 +00:00
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
// MUSICANDSFX uses t_data[0] to control restarting the sound
|
2012-10-14 20:41:21 +00:00
|
|
|
// ST_2_UNDERWATER
|
2010-07-03 08:53:57 +00:00
|
|
|
if (i != -1 && sprite[i].picnum == MUSICANDSFX && sector[sprite[i].sectnum].lotag < 3 && sprite[i].lotag < 999)
|
|
|
|
actor[i].t_data[0] = 0;
|
2010-06-22 21:50:01 +00:00
|
|
|
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[num].SoundOwner[j].ow = -1;
|
2010-07-03 08:53:57 +00:00
|
|
|
g_sounds[num].SoundOwner[j].voice = 0;
|
2012-10-08 07:07:59 +00:00
|
|
|
g_sounds[num].SoundOwner[j].sndist = UINT32_MAX;
|
|
|
|
g_sounds[num].SoundOwner[j].clock = 0;
|
2010-06-22 21:50:01 +00:00
|
|
|
}
|
|
|
|
g_soundlocks[num]--;
|
|
|
|
}
|
|
|
|
while (ldnum);
|
|
|
|
}
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
// returns number of bytes read
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t S_LoadSound(uint32_t num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t fp = -1, l;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-01-10 23:44:49 +00:00
|
|
|
if (num > (unsigned)g_maxSoundPos || ud.config.SoundToggle == 0 || ud.config.FXDevice < 0) return 0;
|
2010-08-02 08:13:51 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (g_sounds[num].filename == NULL && g_sounds[num].filename1 == NULL)
|
2008-01-26 03:59:34 +00:00
|
|
|
{
|
2008-07-27 01:22:17 +00:00
|
|
|
OSD_Printf(OSD_ERROR "Sound (#%d) not defined!\n",num);
|
2008-01-26 03:59:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-08 07:07:17 +00:00
|
|
|
if (g_sounds[num].filename1)
|
|
|
|
fp = kopen4loadfrommod(g_sounds[num].filename1,g_loadFromGroupOnly);
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (fp == -1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-10-08 07:07:17 +00:00
|
|
|
fp = kopen4loadfrommod(g_sounds[num].filename,g_loadFromGroupOnly);
|
|
|
|
|
|
|
|
if (fp == -1)
|
|
|
|
{
|
|
|
|
OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
g_sounds[num].soundsiz = l = kfilelength(fp);
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
g_soundlocks[num] = 200;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
allocache((intptr_t *)&g_sounds[num].ptr, l, (char *)&g_soundlocks[num]);
|
2012-03-13 20:07:40 +00:00
|
|
|
l = kread(fp, g_sounds[num].ptr, l);
|
2006-11-14 21:35:50 +00:00
|
|
|
kclose(fp);
|
2010-01-05 21:53:14 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
return l;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
|
2012-10-08 07:07:17 +00:00
|
|
|
static int32_t S_GetPitch(int32_t num)
|
2012-08-13 18:25:48 +00:00
|
|
|
{
|
|
|
|
int32_t j = klabs(g_sounds[num].pe-g_sounds[num].ps);
|
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
if (j == 0)
|
|
|
|
return g_sounds[num].ps;
|
|
|
|
|
|
|
|
return min(g_sounds[num].ps, g_sounds[num].pe) + rand()%j;
|
2012-08-13 18:25:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
static int32_t S_TakeSlot(int32_t num)
|
2012-08-13 18:25:48 +00:00
|
|
|
{
|
2012-10-08 07:07:59 +00:00
|
|
|
uint32_t dist = 0, clock = UINT32_MAX;
|
|
|
|
int32_t i = 0, j = 0;
|
2012-08-13 18:25:48 +00:00
|
|
|
|
2012-10-14 22:09:16 +00:00
|
|
|
S_Cleanup();
|
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice > 0)
|
2012-10-08 07:07:59 +00:00
|
|
|
{
|
|
|
|
if (g_sounds[num].SoundOwner[j].sndist > dist ||
|
|
|
|
(g_sounds[num].SoundOwner[j].sndist == dist && g_sounds[num].SoundOwner[j].clock < clock))
|
|
|
|
{
|
|
|
|
clock = g_sounds[num].SoundOwner[j].clock;
|
|
|
|
dist = g_sounds[num].SoundOwner[j].sndist;
|
|
|
|
i = j;
|
|
|
|
}
|
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
j++;
|
2012-10-08 07:07:59 +00:00
|
|
|
}
|
2012-08-13 18:25:48 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
if (j != MAXSOUNDINSTANCES)
|
|
|
|
return j;
|
2012-10-08 07:07:17 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
if (FX_SoundActive(g_sounds[num].SoundOwner[i].voice))
|
|
|
|
FX_StopSound(g_sounds[num].SoundOwner[i].voice);
|
2012-10-08 07:07:17 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
mutex_lock(&s_mutex);
|
|
|
|
dq[dnum++] = (num * MAXSOUNDINSTANCES) + i;
|
|
|
|
mutex_unlock(&s_mutex);
|
|
|
|
S_Cleanup();
|
2012-10-08 07:07:17 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
return i;
|
|
|
|
}
|
2012-10-08 07:07:17 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
static int32_t S_GetSlot(int32_t num)
|
|
|
|
{
|
|
|
|
int32_t j = 0;
|
2012-10-08 07:07:17 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice > 0)
|
|
|
|
j++;
|
2012-10-08 07:07:17 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
if (j == MAXSOUNDINSTANCES)
|
|
|
|
j = S_TakeSlot(num);
|
2012-10-08 07:07:17 +00:00
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
2012-10-08 07:07:17 +00:00
|
|
|
static inline int32_t S_GetAngle(int32_t camang, const vec3_t *cam, const vec3_t *pos)
|
2012-08-13 18:25:53 +00:00
|
|
|
{
|
2012-10-08 07:07:59 +00:00
|
|
|
return (2048 + camang - getangle(cam->x-pos->x, cam->y-pos->y))&2047;
|
2012-08-13 18:25:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 18:25:51 +00:00
|
|
|
static int32_t S_CalcDistAndAng(int32_t i, int32_t num, int32_t camsect, int32_t camang,
|
|
|
|
const vec3_t *cam, const vec3_t *pos,
|
|
|
|
int32_t *sndistptr, int32_t *sndangptr)
|
|
|
|
{
|
|
|
|
int32_t sndang, sndist;
|
|
|
|
int32_t explosion = 0;
|
|
|
|
|
|
|
|
if (PN == APLAYER && sprite[i].yvel == screenpeek)
|
|
|
|
{
|
|
|
|
sndang = sndist = 0;
|
2012-08-13 18:25:53 +00:00
|
|
|
goto sound_further_processing;
|
2012-08-13 18:25:51 +00:00
|
|
|
}
|
2012-08-13 18:25:53 +00:00
|
|
|
|
2012-10-08 07:07:17 +00:00
|
|
|
sndang = S_GetAngle(camang, cam, pos);
|
2012-08-13 18:25:53 +00:00
|
|
|
|
|
|
|
sndist = FindDistance3D(cam->x-pos->x, cam->y-pos->y, (cam->z-pos->z)>>4);
|
|
|
|
|
2012-08-22 22:51:38 +00:00
|
|
|
if (g_fakeMultiMode==2)
|
2012-08-13 18:25:51 +00:00
|
|
|
{
|
2012-08-13 18:25:53 +00:00
|
|
|
// HACK for splitscreen mod: take the min of sound distances
|
|
|
|
// to 1st and 2nd player.
|
2012-08-13 18:25:51 +00:00
|
|
|
|
2012-08-13 18:25:53 +00:00
|
|
|
if (PN == APLAYER && sprite[i].yvel==1)
|
|
|
|
{
|
|
|
|
sndist = sndang = 0;
|
|
|
|
goto sound_further_processing;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const vec3_t *cam2 = &g_player[1].ps->pos;
|
|
|
|
int32_t sndist2 = FindDistance3D(cam2->x-pos->x, cam2->y-pos->y, (cam2->z-pos->z)>>4);
|
|
|
|
|
|
|
|
if (sndist2 < sndist)
|
|
|
|
{
|
|
|
|
cam = cam2;
|
|
|
|
camsect = g_player[1].ps->cursectnum;
|
|
|
|
camang = g_player[1].ps->ang;
|
|
|
|
|
|
|
|
sndist = sndist2;
|
2012-10-08 07:07:17 +00:00
|
|
|
sndang = S_GetAngle(camang, cam, pos);
|
2012-08-13 18:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-13 18:25:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-08 22:18:44 +00:00
|
|
|
if ((g_sounds[num].m&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9) // ST_9_SLIDING_ST_DOOR
|
2012-08-13 18:25:53 +00:00
|
|
|
sndist = divscale14(sndist, SHT+1);
|
|
|
|
|
|
|
|
sound_further_processing:
|
2012-08-13 18:25:51 +00:00
|
|
|
sndist += g_sounds[num].vo;
|
|
|
|
if (sndist < 0)
|
|
|
|
sndist = 0;
|
|
|
|
|
|
|
|
if (camsect > -1 && sndist && PN != MUSICANDSFX &&
|
|
|
|
!cansee(cam->x,cam->y,cam->z-(24<<8),camsect, SX,SY,SZ-(24<<8),SECT))
|
|
|
|
sndist += sndist>>5;
|
|
|
|
|
|
|
|
switch (num)
|
|
|
|
{
|
|
|
|
case PIPEBOMB_EXPLODE:
|
|
|
|
case LASERTRIP_EXPLODE:
|
|
|
|
case RPG_EXPLODE:
|
|
|
|
explosion = 1;
|
|
|
|
if (sndist > 6144)
|
|
|
|
sndist = 6144;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((g_sounds[num].m&16) || sndist < ((255-LOUDESTVOLUME)<<6))
|
|
|
|
sndist = ((255-LOUDESTVOLUME)<<6);
|
|
|
|
|
|
|
|
*sndistptr = sndist;
|
|
|
|
*sndangptr = sndang;
|
|
|
|
|
|
|
|
return explosion;
|
|
|
|
}
|
|
|
|
|
2009-08-06 10:12:13 +00:00
|
|
|
int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-08-13 18:25:51 +00:00
|
|
|
int32_t j = 0;
|
|
|
|
int32_t cs, ca;
|
|
|
|
int32_t sndist, sndang, explosionp;
|
|
|
|
int32_t voice, pitch;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
const DukePlayer_t *const myps = g_player[myconnectindex].ps;
|
|
|
|
const DukePlayer_t *peekps;
|
|
|
|
|
2012-05-17 17:33:29 +00:00
|
|
|
if (apScriptGameEvent[EVENT_SOUND])
|
|
|
|
num = VM_OnEvent(EVENT_SOUND, i, screenpeek, -1, num);
|
|
|
|
|
2012-01-10 23:44:49 +00:00
|
|
|
if ((unsigned)num > (unsigned)g_maxSoundPos ||
|
2007-08-27 00:20:15 +00:00
|
|
|
ud.config.FXDevice < 0 ||
|
2007-09-11 05:26:38 +00:00
|
|
|
((g_sounds[num].m&8) && ud.lockout) ||
|
2007-08-27 00:20:15 +00:00
|
|
|
ud.config.SoundToggle == 0 ||
|
2012-10-08 07:07:17 +00:00
|
|
|
/* g_sounds[num].num >= MAXSOUNDINSTANCES ||*/
|
2011-03-04 08:50:58 +00:00
|
|
|
(unsigned)i >= MAXSPRITES ||
|
2007-09-11 05:26:38 +00:00
|
|
|
FX_VoiceAvailable(g_sounds[num].pr) == 0 ||
|
2012-08-13 18:25:48 +00:00
|
|
|
(myps->timebeforeexit > 0 && myps->timebeforeexit <= GAMETICSPERSEC*3) ||
|
|
|
|
(myps->gm&MODE_MENU)) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-03-10 21:22:22 +00:00
|
|
|
if (g_sounds[num].m&128) // Duke-Tag sound
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-07-05 04:37:28 +00:00
|
|
|
if ((voice = S_PlaySound(num)) <= FX_Ok)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice != voice)
|
2010-06-22 21:50:01 +00:00
|
|
|
j++;
|
2010-01-05 21:53:14 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
if (j >= MAXSOUNDINSTANCES)
|
|
|
|
{
|
|
|
|
OSD_Printf(OSD_ERROR "%s %d: WTF?\n", __FILE__, __LINE__);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-01-05 21:53:14 +00:00
|
|
|
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[num].SoundOwner[j].ow = i;
|
2010-07-05 04:37:28 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
return voice;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
// Duke talk
|
2007-09-11 05:26:38 +00:00
|
|
|
if (g_sounds[num].m&4)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-01-16 23:08:17 +00:00
|
|
|
if ((g_netServer || ud.multimode > 1) && PN == APLAYER && sprite[i].yvel != screenpeek) // other player sound
|
2008-07-28 21:23:10 +00:00
|
|
|
{
|
|
|
|
if (!(ud.config.VoiceToggle&4))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (!(ud.config.VoiceToggle&1))
|
2006-04-16 03:42:36 +00:00
|
|
|
return -1;
|
2010-03-01 09:09:26 +00:00
|
|
|
|
|
|
|
// don't play if any Duke talk sounds are already playing
|
2009-07-24 02:31:34 +00:00
|
|
|
for (j=g_maxSoundPos; j>=0; j--)
|
2010-03-01 09:09:26 +00:00
|
|
|
if ((g_sounds[j].m&4) && g_sounds[j].num > 0)
|
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-07-24 02:31:34 +00:00
|
|
|
cs = ud.camerasect;
|
|
|
|
ca = ud.cameraang;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-08-13 18:25:51 +00:00
|
|
|
explosionp = S_CalcDistAndAng(i, num, cs, ca, &ud.camera, pos, &sndist, &sndang);
|
2009-07-27 05:33:12 +00:00
|
|
|
|
2012-10-08 07:07:17 +00:00
|
|
|
pitch = S_GetPitch(num);
|
2012-08-13 18:25:48 +00:00
|
|
|
peekps = g_player[screenpeek].ps;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-08-22 22:51:38 +00:00
|
|
|
if (g_fakeMultiMode==2)
|
2012-08-22 22:50:32 +00:00
|
|
|
{
|
|
|
|
// splitscreen HACK
|
|
|
|
if (g_player[1].ps->i == i)
|
|
|
|
peekps = g_player[1].ps;
|
|
|
|
}
|
|
|
|
|
2012-08-13 18:25:51 +00:00
|
|
|
if (peekps->sound_pitch)
|
|
|
|
pitch += peekps->sound_pitch;
|
|
|
|
|
|
|
|
if (explosionp)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-10-14 20:41:21 +00:00
|
|
|
if (peekps->cursectnum > -1 && sector[peekps->cursectnum].lotag == ST_2_UNDERWATER)
|
2006-11-16 03:02:42 +00:00
|
|
|
pitch -= 1024;
|
2012-08-13 18:25:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-04 08:50:58 +00:00
|
|
|
if (sndist > 32767 && PN != MUSICANDSFX && (g_sounds[num].m & 3) == 0)
|
|
|
|
return -1;
|
2012-08-13 18:25:51 +00:00
|
|
|
|
2012-10-14 20:41:21 +00:00
|
|
|
if (peekps->cursectnum > -1 && sector[peekps->cursectnum].lotag == ST_2_UNDERWATER && (g_sounds[num].m&4) == 0)
|
2006-11-16 03:02:42 +00:00
|
|
|
pitch = -768;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-11 05:26:38 +00:00
|
|
|
if (g_sounds[num].num > 0 && PN != MUSICANDSFX)
|
2010-03-01 09:09:26 +00:00
|
|
|
S_StopEnvSound(num, i);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-09-11 05:26:38 +00:00
|
|
|
if (g_sounds[num].ptr == 0)
|
2006-11-15 01:16:55 +00:00
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
if (S_LoadSound(num) == 0)
|
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2010-08-02 08:13:51 +00:00
|
|
|
else
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
|
|
|
if (g_soundlocks[num] < 200)
|
|
|
|
g_soundlocks[num] = 200;
|
|
|
|
else g_soundlocks[num]++;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
j = S_GetSlot(num);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (j >= MAXSOUNDINSTANCES)
|
|
|
|
{
|
|
|
|
g_soundlocks[num]--;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-01-05 21:53:14 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (g_sounds[num].m&1)
|
|
|
|
{
|
2010-06-22 21:50:01 +00:00
|
|
|
if (g_sounds[num].num > 0)
|
|
|
|
{
|
|
|
|
g_soundlocks[num]--;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-02-23 18:13:46 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
voice = FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1,
|
2010-08-02 08:13:51 +00:00
|
|
|
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,(num * MAXSOUNDINSTANCES) + j);
|
2010-03-01 09:09:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
voice = FX_PlayAuto3D(g_sounds[ num ].ptr, g_sounds[num].soundsiz, pitch,sndang>>4,sndist>>6, g_sounds[num].pr,
|
2010-08-02 08:13:51 +00:00
|
|
|
(num * MAXSOUNDINSTANCES) + j);
|
2010-03-01 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
if (voice <= FX_Ok)
|
2010-03-01 09:09:26 +00:00
|
|
|
{
|
2010-07-03 08:53:57 +00:00
|
|
|
g_soundlocks[num]--;
|
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2010-03-01 09:09:26 +00:00
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
g_sounds[num].num++;
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[num].SoundOwner[j].ow = i;
|
2010-07-03 08:53:57 +00:00
|
|
|
g_sounds[num].SoundOwner[j].voice = voice;
|
2012-10-08 07:07:59 +00:00
|
|
|
g_sounds[num].SoundOwner[j].sndist = sndist>>6;
|
|
|
|
g_sounds[num].SoundOwner[j].clock = totalclock;
|
2010-07-03 08:53:57 +00:00
|
|
|
return voice;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-07-15 01:26:38 +00:00
|
|
|
int32_t S_PlaySound(int32_t num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-08-13 18:25:48 +00:00
|
|
|
int32_t pitch;
|
2010-07-03 08:53:57 +00:00
|
|
|
int32_t voice, j;
|
2010-07-05 04:37:28 +00:00
|
|
|
int32_t doretry = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-05-17 17:33:29 +00:00
|
|
|
if (apScriptGameEvent[EVENT_SOUND])
|
|
|
|
num = VM_OnEvent(EVENT_SOUND, g_player[screenpeek].ps->i, screenpeek, -1, num);
|
|
|
|
|
2009-07-15 01:26:38 +00:00
|
|
|
if (ud.config.FXDevice < 0) return -1;
|
|
|
|
if (ud.config.SoundToggle==0) return -1;
|
|
|
|
if (!(ud.config.VoiceToggle&1) && (g_sounds[num].m&4)) return -1;
|
2012-01-10 23:44:49 +00:00
|
|
|
|
|
|
|
if ((unsigned)num > (unsigned)g_maxSoundPos || (g_sounds[num].filename == NULL && g_sounds[num].filename1 == NULL))
|
2007-08-15 03:05:14 +00:00
|
|
|
{
|
2007-08-25 01:05:00 +00:00
|
|
|
OSD_Printf("WARNING: invalid sound #%d\n",num);
|
2009-07-15 01:26:38 +00:00
|
|
|
return -1;
|
2007-08-15 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 23:44:49 +00:00
|
|
|
if ((g_sounds[num].m&8) && ud.lockout) return -1;
|
|
|
|
if (FX_VoiceAvailable(g_sounds[num].pr) == 0) return -1;
|
|
|
|
|
2012-10-08 07:07:17 +00:00
|
|
|
pitch = S_GetPitch(num);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-09-11 05:26:38 +00:00
|
|
|
if (g_sounds[num].ptr == 0)
|
2006-11-15 01:16:55 +00:00
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
if (S_LoadSound(num) == 0)
|
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2010-08-02 08:13:51 +00:00
|
|
|
else
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
|
|
|
if (g_soundlocks[num] < 200)
|
|
|
|
g_soundlocks[num] = 200;
|
|
|
|
else g_soundlocks[num]++;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
j = S_GetSlot(num);
|
2010-07-03 08:53:57 +00:00
|
|
|
|
2012-10-08 07:07:59 +00:00
|
|
|
if (j >= MAXSOUNDINSTANCES)
|
|
|
|
{
|
|
|
|
g_soundlocks[num]--;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-08-02 08:13:51 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
voice = (g_sounds[num].m&1) ?
|
2010-08-02 08:13:51 +00:00
|
|
|
FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1,
|
|
|
|
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].soundsiz, (num * MAXSOUNDINSTANCES) + j) :
|
|
|
|
FX_PlayAuto3D(g_sounds[ num ].ptr, g_sounds[num].soundsiz, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, (num * MAXSOUNDINSTANCES) + j);
|
2010-03-01 09:09:26 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
if (voice <= FX_Ok)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
g_soundlocks[num]--;
|
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
g_sounds[num].num++;
|
2012-03-10 21:22:44 +00:00
|
|
|
g_sounds[num].SoundOwner[j].ow = -1;
|
2010-07-03 08:53:57 +00:00
|
|
|
g_sounds[num].SoundOwner[j].voice = voice;
|
2012-10-08 07:07:59 +00:00
|
|
|
g_sounds[num].SoundOwner[j].sndist = 255-LOUDESTVOLUME;
|
|
|
|
g_sounds[num].SoundOwner[j].clock = totalclock;
|
2010-03-01 09:09:26 +00:00
|
|
|
return voice;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t A_PlaySound(uint32_t num, int32_t i)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-05-16 00:45:10 +00:00
|
|
|
if ((unsigned)num > (unsigned)g_maxSoundPos) return -1;
|
2012-05-14 18:12:27 +00:00
|
|
|
|
2012-05-16 00:45:10 +00:00
|
|
|
return i < 0 ? S_PlaySound(num) :
|
|
|
|
S_PlaySound3D(num, i, (vec3_t *)&sprite[i]);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
void S_StopEnvSound(int32_t num, int32_t i)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-07-03 08:53:57 +00:00
|
|
|
int32_t j, iter = 0;
|
2010-06-26 08:51:42 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
if ((unsigned)num > (unsigned)g_maxSoundPos || g_sounds[num].num <= 0)
|
2010-03-01 09:09:26 +00:00
|
|
|
return;
|
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
do
|
2010-06-26 08:51:42 +00:00
|
|
|
{
|
2010-07-03 08:53:57 +00:00
|
|
|
if (iter++ > MAXSOUNDINSTANCES<<1)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2010-07-03 08:53:57 +00:00
|
|
|
initprintf(OSD_ERROR "S_StopEnvSound(): too many iterations! The following IDs are still active for sound %d:\n", num);
|
|
|
|
for (j=MAXSOUNDINSTANCES-1; j>=0; j--)
|
2012-03-10 21:22:44 +00:00
|
|
|
if (g_sounds[num].SoundOwner[j].ow == i)
|
|
|
|
initprintf(OSD_ERROR "slot %d, voice %d, sprite %d\n", j, g_sounds[num].SoundOwner[j].voice, g_sounds[num].SoundOwner[j].ow);
|
2010-07-03 08:53:57 +00:00
|
|
|
return;
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2010-06-26 08:51:42 +00:00
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
for (j=MAXSOUNDINSTANCES-1; j>=0; j--)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2012-03-10 21:22:44 +00:00
|
|
|
if ((i == -1 && g_sounds[num].SoundOwner[j].voice > FX_Ok) || (i != -1 && g_sounds[num].SoundOwner[j].ow == i))
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2010-07-05 04:37:28 +00:00
|
|
|
if (i >= 0 && g_sounds[num].SoundOwner[j].voice <= FX_Ok)
|
2010-06-26 08:51:42 +00:00
|
|
|
initprintf(OSD_ERROR "S_StopEnvSound(): bad voice %d for sound ID %d index %d!\n", g_sounds[num].SoundOwner[j].voice, num, j);
|
2012-10-14 22:09:16 +00:00
|
|
|
else if (g_sounds[num].SoundOwner[j].voice > FX_Ok)
|
|
|
|
{
|
2010-06-26 08:51:42 +00:00
|
|
|
FX_StopSound(g_sounds[num].SoundOwner[j].voice);
|
2012-10-14 22:09:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-15 01:26:38 +00:00
|
|
|
}
|
2010-07-03 08:53:57 +00:00
|
|
|
while (j >= 0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2011-11-03 23:08:54 +00:00
|
|
|
void S_ChangeSoundPitch(int32_t num, int32_t i, int32_t pitchoffset)
|
|
|
|
{
|
|
|
|
int32_t j;
|
|
|
|
|
|
|
|
if ((unsigned)num > (unsigned)g_maxSoundPos || g_sounds[num].num <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (j=MAXSOUNDINSTANCES-1; j>=0; j--)
|
|
|
|
{
|
|
|
|
int32_t voice = g_sounds[num].SoundOwner[j].voice;
|
|
|
|
|
2012-03-10 21:22:44 +00:00
|
|
|
if ((i == -1 && voice > FX_Ok) || (i != -1 && g_sounds[num].SoundOwner[j].ow == i))
|
2011-11-03 23:08:54 +00:00
|
|
|
{
|
|
|
|
if (i >= 0 && voice <= FX_Ok)
|
|
|
|
initprintf(OSD_ERROR "S_ChangeSoundPitch(): bad voice %d for sound ID %d index %d!\n", voice, num, j);
|
|
|
|
else if (voice > FX_Ok && FX_SoundActive(voice))
|
|
|
|
FX_SetPitch(voice, pitchoffset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
void S_Update(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-08-13 18:25:51 +00:00
|
|
|
const vec3_t *c;
|
|
|
|
int32_t ca,cs;
|
2012-08-13 18:25:48 +00:00
|
|
|
int32_t num; // the sound index...
|
2010-08-02 08:13:51 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
S_Cleanup();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-07-05 04:37:28 +00:00
|
|
|
if ((g_player[myconnectindex].ps->gm & (MODE_GAME|MODE_DEMO)) == 0)
|
|
|
|
return;
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
g_numEnvSoundsPlaying = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (ud.camerasprite == -1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-08-13 18:25:48 +00:00
|
|
|
c = &ud.camera;
|
2009-07-24 02:31:34 +00:00
|
|
|
cs = ud.camerasect;
|
|
|
|
ca = ud.cameraang;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
c = (vec3_t *)&sprite[ud.camerasprite];
|
2006-04-13 20:47:06 +00:00
|
|
|
cs = sprite[ud.camerasprite].sectnum;
|
|
|
|
ca = sprite[ud.camerasprite].ang;
|
|
|
|
}
|
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
num = g_maxSoundPos;
|
2009-07-24 02:31:34 +00:00
|
|
|
|
2009-07-27 05:33:12 +00:00
|
|
|
do
|
2009-07-24 02:31:34 +00:00
|
|
|
{
|
2012-08-13 18:25:48 +00:00
|
|
|
int32_t k;
|
|
|
|
|
2010-01-05 21:53:14 +00:00
|
|
|
for (k=MAXSOUNDINSTANCES-1; k>=0; k--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-08-13 18:25:48 +00:00
|
|
|
int32_t i = g_sounds[num].SoundOwner[k].ow;
|
2012-08-13 18:25:51 +00:00
|
|
|
int32_t sndist, sndang;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
if ((unsigned)i >= MAXSPRITES || g_sounds[num].num == 0 || g_sounds[num].SoundOwner[k].voice <= FX_Ok)
|
2010-06-22 21:50:01 +00:00
|
|
|
continue;
|
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
if (!FX_SoundActive(g_sounds[num].SoundOwner[k].voice))
|
2010-06-22 21:50:01 +00:00
|
|
|
{
|
2010-08-02 08:13:51 +00:00
|
|
|
/*
|
2012-08-13 18:25:48 +00:00
|
|
|
OSD_Printf("S_Update(): stale voice %d from sound %d position %d sprite %d\n",
|
|
|
|
g_sounds[num].SoundOwner[k].voice, num, k, g_sounds[num].SoundOwner[k].ow);
|
2010-08-02 08:13:51 +00:00
|
|
|
*/
|
2009-08-09 05:32:17 +00:00
|
|
|
continue;
|
2010-06-22 21:50:01 +00:00
|
|
|
}
|
2010-01-23 22:12:02 +00:00
|
|
|
|
2012-08-13 18:25:51 +00:00
|
|
|
S_CalcDistAndAng(i, num, cs, ca, c, (const vec3_t *)&sprite[i], &sndist, &sndang);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
if (PN == MUSICANDSFX && SLT < 999)
|
2008-11-20 14:06:36 +00:00
|
|
|
g_numEnvSoundsPlaying++;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-08-13 18:25:48 +00:00
|
|
|
FX_Pan3D(g_sounds[num].SoundOwner[k].voice, sndang>>4, sndist>>6);
|
2012-10-08 07:07:59 +00:00
|
|
|
g_sounds[num].SoundOwner[k].sndist = sndist>>6;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2009-07-27 05:33:12 +00:00
|
|
|
}
|
2012-08-13 18:25:48 +00:00
|
|
|
while (num--);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2010-02-23 18:13:46 +00:00
|
|
|
void S_Callback(uint32_t num)
|
2010-01-05 21:53:14 +00:00
|
|
|
{
|
|
|
|
if ((int32_t)num == MUSIC_ID)
|
|
|
|
return;
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
mutex_lock(&s_mutex);
|
|
|
|
dq[dnum++] = num;
|
|
|
|
mutex_unlock(&s_mutex);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
void S_ClearSoundLocks(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
for (i=g_maxSoundPos; i >= 0 ; i--)
|
2009-07-12 01:55:34 +00:00
|
|
|
if (g_soundlocks[i] >= 200)
|
|
|
|
g_soundlocks[i] = 199;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<11; i++)
|
2010-08-02 08:13:51 +00:00
|
|
|
if (rts_lumplockbyte[i] >= 200)
|
|
|
|
rts_lumplockbyte[i] = 199;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t A_CheckSoundPlaying(int32_t i, int32_t num)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
if (num > g_maxSoundPos || num < 0) return 0;
|
2009-07-15 01:26:38 +00:00
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
if (g_sounds[num].num > 0 && i >= 0)
|
2009-07-15 01:26:38 +00:00
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
int32_t j=MAXSOUNDINSTANCES-1;
|
|
|
|
|
|
|
|
for (; j>=0; j--)
|
2012-03-10 21:22:44 +00:00
|
|
|
if (g_sounds[num].SoundOwner[j].ow == i)
|
2009-07-15 01:26:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-03-01 09:09:26 +00:00
|
|
|
return (i == -1) ? g_sounds[num].num : 0;
|
2006-04-16 03:42:36 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t S_CheckSoundPlaying(int32_t i, int32_t num)
|
2006-04-16 03:42:36 +00:00
|
|
|
{
|
2010-03-01 09:09:26 +00:00
|
|
|
if (num > g_maxSoundPos || num < 0) return 0;
|
|
|
|
return (i == -1) ? (g_soundlocks[num] >= 200) : g_sounds[num].num;
|
2006-04-16 03:42:36 +00:00
|
|
|
}
|