- added refactored sound code to RR frontend.

- removed most code using the low level sound interface directly from Duke and RR frontends.
This commit is contained in:
Christoph Oelckers 2019-12-16 16:18:47 +01:00
parent a66fc98d24
commit d24bd0fc14
27 changed files with 636 additions and 1572 deletions

View file

@ -112,6 +112,6 @@ static FORCE_INLINE int FX_SoundActive(int handle) { return MV_VoicePlaying(hand
static FORCE_INLINE int FX_SoundValidAndActive(int handle) { return handle > 0 && MV_VoicePlaying(handle); }
static FORCE_INLINE int FX_SoundsPlaying(void) { return MV_VoicesPlaying(); }
static FORCE_INLINE int FX_StopSound(int handle) { return FX_CheckMVErr(MV_Kill(handle)); }
static FORCE_INLINE int FX_StopAllSounds(void) { return FX_CheckMVErr(MV_KillAllVoices()); }
static FORCE_INLINE int FX_StopAllSounds_(void) { return FX_CheckMVErr(MV_KillAllVoices()); }
#endif

View file

@ -1367,7 +1367,7 @@ RESTART:
{
UpdateDacs(0, true);
Mus_Stop();
FX_StopAllSounds();
FX_StopAllSounds_();
gQuitGame = 0;
gQuitRequest = 0;
gRestartGame = 0;

View file

@ -282,7 +282,7 @@ void credPlaySmk(const char *_pzSMK, const char *_pzWAV, int nWav)
Smacker_Close(hSMK);
ctrlClearAllInput();
FX_StopAllSounds();
FX_StopAllSounds_();
videoSetPalette(0, 0, 8+2);
tileDelete(kSMKTile);
Bfree(pzSMK_);

View file

@ -119,7 +119,7 @@ void CEndGameMgr::Finish(void)
{
levelSetupOptions(gGameOptions.nEpisode, gNextLevel);
gInitialNetPlayers = numplayers;
FX_StopAllSounds();
FX_StopAllSounds_();
sndKillAllSounds();
gStartNewGame = 1;
gInputMode = (INPUT_MODE)at1;

View file

@ -153,7 +153,7 @@ void NetworkHostGame(CGameMenuItemChain *pItem)
{
UNREFERENCED_PARAMETER(pItem);
Mus_Stop();
FX_StopAllSounds();
FX_StopAllSounds_();
UpdateDacs(0, true);
gNetPlayers = itemNetworkHostPlayerNum.nValue;
gNetPort = strtoul(zNetPortBuffer, NULL, 10);
@ -169,7 +169,7 @@ void NetworkJoinGame(CGameMenuItemChain *pItem)
{
UNREFERENCED_PARAMETER(pItem);
Mus_Stop();
FX_StopAllSounds();
FX_StopAllSounds_();
UpdateDacs(0, true);
strcpy(gNetAddress, zNetAddressBuffer);
gNetPort = strtoul(zNetPortBuffer, NULL, 10);

View file

@ -366,7 +366,7 @@ void M_StartControlPanel (bool makeSound)
created = true;
M_CreateMenus();
}
FX_StopAllSounds();
FX_StopAllSounds_();
gi->MenuOpened();
if (makeSound) gi->MenuSound(ActivateSound);

View file

@ -448,4 +448,8 @@ struct FReverbField
unsigned int Flag;
};
inline void FX_StopAllSounds(void)
{
soundEngine->StopAllChannels();
}

View file

@ -5364,7 +5364,6 @@ repeatcase:
case CON_DEFINESOUND:
{
int ps, pe, vo, pr, m;
float volume;
g_scriptPtr--;
C_GetNextValue(LABEL_DEFINE);
@ -5423,8 +5422,6 @@ repeatcase:
int res = S_DefineSound(k, buffer.Data(), ps, pe, pr, m, vo, 1.f);
volume = 1.f;
if (g_dynamicSoundMapping && j >= 0 && (labeltype[j] & LABEL_DEFINE))
G_ProcessDynamicSoundMapping(label + (j << 6), k);
continue;

View file

@ -3730,12 +3730,7 @@ void P_FragPlayer(int playerNum)
pPlayer->holoduke_on = -1;
S_StopEnvSound(DUKE_JETPACK_IDLE, pPlayer->i);
if (pPlayer->scream_voice > FX_Ok)
{
FX_StopSound(pPlayer->scream_voice);
pPlayer->scream_voice = -1;
}
S_StopEnvSound(-1, pPlayer->i, CHAN_VOICE);
}
#endif
@ -4996,11 +4991,9 @@ void P_ProcessInput(int playerNum)
if (pPlayer->vel.z > 2400 && pPlayer->falling_counter < 255)
{
pPlayer->falling_counter++;
if (pPlayer->falling_counter >= 38 && pPlayer->scream_voice <= FX_Ok)
if (pPlayer->falling_counter >= 38 && !A_CheckSoundPlaying(pPlayer->i, -1, CHAN_VOICE))
{
int32_t voice = A_PlaySound(DUKE_SCREAM,pPlayer->i);
if (voice <= 127) // XXX: p->scream_voice is an int8_t
pPlayer->scream_voice = voice;
A_PlaySound(DUKE_SCREAM, pPlayer->i, CHAN_VOICE);
}
}
@ -5044,11 +5037,7 @@ void P_ProcessInput(int playerNum)
{
pPlayer->falling_counter = 0;
if (pPlayer->scream_voice > FX_Ok)
{
FX_StopSound(pPlayer->scream_voice);
pPlayer->scream_voice = -1;
}
S_StopEnvSound(-1, pPlayer->i, CHAN_VOICE);
if ((sectorLotag != ST_1_ABOVE_WATER && sectorLotag != ST_2_UNDERWATER) &&
(pPlayer->on_ground == 0 && pPlayer->vel.z > (6144 >> 1)))

View file

@ -3025,11 +3025,7 @@ CHECKINV1:
if (pPlayer->jetpack_on)
{
pPlayer->inven_icon = ICON_JETPACK;
if (pPlayer->scream_voice > FX_Ok)
{
FX_StopSound(pPlayer->scream_voice);
pPlayer->scream_voice = -1;
}
S_StopEnvSound(-1, pPlayer->i, CHAN_VOICE);
#ifndef EDUKE32_STANDALONE
if (!FURY)
A_PlaySound(DUKE_JETPACK_ON,pPlayer->i);

View file

@ -350,11 +350,9 @@ void S_Update(void)
//
//
//==========================================================================
CVAR(Int, soundtest, -1, 0) // Debug aid to block all sounds except the one selected
int S_PlaySound3D(int num, int spriteNum, const vec3_t* pos, int flags)
{
if (soundtest > -1 && num != soundtest) return -1;
int sndnum = VM_OnEventWithReturn(EVENT_SOUND, spriteNum, screenpeek, num);
auto const pPlayer = g_player[myconnectindex].ps;
@ -455,7 +453,6 @@ int S_PlaySound3D(int num, int spriteNum, const vec3_t* pos, int flags)
int S_PlaySound(int num, int flags)
{
if (soundtest > -1 && num != soundtest) return -1;
int sndnum = VM_OnEventWithReturn(EVENT_SOUND, g_player[screenpeek].ps->i, screenpeek, num);
if (!soundEngine->isValidSoundId(sndnum+1) || !SoundEnabled()) return -1;
@ -483,12 +480,13 @@ int A_PlaySound(int soundNum, int spriteNum, int flags)
S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos, flags);
}
void S_StopEnvSound(int sndNum, int sprNum)
void S_StopEnvSound(int sndNum, int sprNum, int flags)
{
if (sprNum < -1 || sprNum >= MAXSPRITES) return;
if (sprNum == -1) soundEngine->StopSoundID(sndNum+1);
else soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], -1, sndNum+1);
else if (flags == -1) soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], -1, sndNum+1);
else soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], flags, -1);
}
void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset)
@ -511,11 +509,11 @@ void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset)
//
//==========================================================================
int A_CheckSoundPlaying(int spriteNum, int soundNum)
int A_CheckSoundPlaying(int spriteNum, int soundNum, int flags)
{
if (spriteNum == -1) return soundEngine->GetSoundPlayingInfo(SOURCE_Any, nullptr, soundNum+1);
if ((unsigned)spriteNum >= MAXSPRITES) return false;
return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, &sprite[spriteNum], CHAN_AUTO, soundNum+1);
return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, &sprite[spriteNum], flags, soundNum+1);
}
// Check if actor <i> is playing any sound.
@ -570,7 +568,6 @@ void S_PlayLevelMusicOrNothing(unsigned int m)
if (retval >= 0)
{
// Thanks to scripting that stupid slot hijack cannot be refactored - but we'll store the real data elsewhere anyway!
auto& mr = m == USERMAPMUSICFAKESLOT ? userMapRecord : mapList[m];
Mus_Play(mr.labelName, mr.music, true);
S_SetMusicIndex(m);

View file

@ -45,7 +45,7 @@ typedef struct
int priority, flags;
} sound_t;
int A_CheckSoundPlaying(int spriteNum,int soundNum);
int A_CheckSoundPlaying(int spriteNum, int soundNum, int flags = 0);
int A_PlaySound(int soundNum, int spriteNum, int flags = 0);
void S_Callback(intptr_t num);
int A_CheckAnySoundPlaying(int spriteNum);
@ -61,7 +61,7 @@ void S_PlaySpecialMusicOrNothing(unsigned int);
void S_ContinueLevelMusic(void);
int S_PlaySound(int num, int flags = 0);
int S_PlaySound3D(int num, int spriteNum, const vec3_t *pos, int flags = 0);
void S_StopEnvSound(int sndNum,int sprNum);
void S_StopEnvSound(int sndNum,int sprNum, int flags = -1);
void S_StopAllSounds(void);
void S_Update(void);
void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset);

View file

@ -1,720 +0,0 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 2016 EDuke32 developers and contributors
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
#include "compat.h"
#include "duke3d.h"
#include "renderlayer.h" // for win_gethwnd()
#include "al_midi.h"
#include "openaudio.h"
#include "z_music.h"
#include "mapinfo.h"
#include <atomic>
BEGIN_DUKE_NS
#define DQSIZE 256
int32_t g_numEnvSoundsPlaying, g_highestSoundIdx;
static char *MusicPtr;
static int32_t MusicIsWaveform;
static int32_t MusicVoice = -1;
static bool MusicPaused;
static bool SoundPaused;
static std::atomic<uint32_t> dnum, dq[DQSIZE];
static mutex_t m_callback;
static inline void S_SetProperties(assvoice_t *snd, int const owner, int const voice, int const dist, int const clock)
{
snd->owner = owner;
snd->id = voice;
snd->dist = dist;
snd->clock = clock;
}
void S_SoundStartup(void)
{
#ifdef _WIN32
void *initdata = (void *) win_gethwnd(); // used for DirectSound
#else
void *initdata = NULL;
#endif
initprintf("Initializing sound... ");
int status = FX_Init(snd_numvoices, snd_numchannels, snd_mixrate, initdata);
if (status != FX_Ok)
{
initprintf("failed! %s\n", FX_ErrorString(status));
return;
}
initprintf("%d voices, %d channels, 16-bit %d Hz\n", *snd_numvoices, *snd_numchannels, *snd_mixrate);
for (int i = 0; i <= g_highestSoundIdx; ++i)
{
for (auto & voice : g_sounds[i].voices)
{
g_sounds[i].num = 0;
S_SetProperties(&voice, -1, 0, UINT16_MAX, 0);
}
}
snd_fxvolume.Callback();
snd_reversestereo.Callback();
FX_SetCallBack(S_Callback);
FX_SetPrintf(OSD_Printf);
}
void S_SoundShutdown(void)
{
int status = FX_Shutdown();
if (status != FX_Ok)
{
Bsprintf(tempbuf, "S_SoundShutdown(): error: %s", FX_ErrorString(status));
G_GameExit(tempbuf);
}
}
void S_PauseSounds(bool paused)
{
if (SoundPaused == paused)
return;
SoundPaused = paused;
for (int i = 0; i <= g_highestSoundIdx; ++i)
{
for (auto & voice : g_sounds[i].voices)
if (voice.id > 0)
FX_PauseVoice(voice.id, paused);
}
}
void S_MenuSound(void)
{
static int SoundNum;
int const 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,
};
int s = VM_OnEventWithReturn(EVENT_OPENMENUSOUND, g_player[screenpeek].ps->i, screenpeek, FURY ? -1 : menusnds[SoundNum++ % ARRAY_SIZE(menusnds)]);
if (s != -1)
S_PlaySound(s);
}
static void S_SetMusicIndex(unsigned int m)
{
ud.music_episode = m / MAXLEVELS;
ud.music_level = m % MAXLEVELS;
}
void S_PlayLevelMusicOrNothing(unsigned int m)
{
ud.returnvar[0] = m / MAXLEVELS;
ud.returnvar[1] = m % MAXLEVELS;
int retval = VM_OnEvent(EVENT_PLAYLEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex);
if (retval >= 0)
{
// Thanks to scripting that stupid slot hijack cannot be refactored - but we'll store the real data elsewhere anyway!
auto &mr = m == USERMAPMUSICFAKESLOT ? userMapRecord : mapList[m];
Mus_Play(mr.labelName, mr.music, true);
S_SetMusicIndex(m);
}
}
int S_TryPlaySpecialMusic(unsigned int m)
{
auto &musicfn = mapList[m].music;
if (musicfn.IsNotEmpty())
{
if (!Mus_Play(nullptr, musicfn, true))
{
S_SetMusicIndex(m);
return 0;
}
}
return 1;
}
void S_PlaySpecialMusicOrNothing(unsigned int m)
{
if (S_TryPlaySpecialMusic(m))
{
S_SetMusicIndex(m);
}
}
void S_ContinueLevelMusic(void)
{
VM_OnEvent(EVENT_CONTINUELEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex);
}
void S_Cleanup(void)
{
static uint32_t ldnum = 0;
while (ldnum < dnum)
{
uint32_t num = dq[ldnum++ & (DQSIZE - 1)];
// negative index is RTS playback
if ((int32_t)num < 0)
{
continue;
}
// 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))
{
continue;
}
int const voiceindex = num & (MAXSOUNDINSTANCES - 1);
num = (num - voiceindex) / MAXSOUNDINSTANCES;
auto &snd = g_sounds[num];
auto &voice = snd.voices[voiceindex];
int const spriteNum = voice.owner;
if (EDUKE32_PREDICT_FALSE(snd.num > MAXSOUNDINSTANCES))
OSD_Printf(OSD_ERROR "S_Cleanup(): num exceeds MAXSOUNDINSTANCES! g_sounds[%d].num %d wtf?\n", num, snd.num);
else if (snd.num > 0)
--snd.num;
// MUSICANDSFX uses t_data[0] to control restarting the sound
// CLEAR_SOUND_T0
if (spriteNum != -1 && S_IsAmbientSFX(spriteNum) && sector[SECT(spriteNum)].lotag < 3) // ST_2_UNDERWATER
actor[spriteNum].t_data[0] = 0;
S_SetProperties(&voice, -1, 0, UINT16_MAX, 0);
}
}
// returns number of bytes read
int32_t S_LoadSound(int num)
{
if ((unsigned)num > (unsigned)g_highestSoundIdx || EDUKE32_PREDICT_FALSE(g_sounds[num].filename == NULL))
return 0;
auto &snd = g_sounds[num];
auto fp = S_OpenAudio(snd.filename, 0, 0);
if (!fp.isOpen())
{
OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n", snd.filename, num);
return 0;
}
int32_t l = fp.GetLength();
snd.siz = l;
cacheAllocateBlock((intptr_t *)&snd.ptr, l, nullptr);
l = fp.Read(snd.ptr, l);
return l;
}
void cacheAllSounds(void)
{
for (int i=0, j=0; i <= g_highestSoundIdx; ++i)
{
if (g_sounds[i].ptr == 0)
{
j++;
if ((j&7) == 0)
gameHandleEvents();
S_LoadSound(i);
}
}
}
static inline int S_GetPitch(int num)
{
auto const &snd = g_sounds[num];
int const range = klabs(snd.pe - snd.ps);
return (range == 0) ? snd.ps : min(snd.ps, snd.pe) + rand() % range;
}
static int S_TakeSlot(int soundNum)
{
S_Cleanup();
uint16_t dist = 0;
uint16_t clock = 0;
int bestslot = 0;
int slot = 0;
auto &snd = g_sounds[soundNum];
while (slot < MAXSOUNDINSTANCES && snd.voices[slot].id > 0)
{
auto &voice = snd.voices[slot];
if (voice.dist > dist || (voice.dist == dist && voice.clock > clock))
{
clock = voice.clock;
dist = voice.dist;
bestslot = slot;
}
slot++;
}
if (slot != MAXSOUNDINSTANCES)
return slot;
if (FX_SoundActive(snd.voices[bestslot].id))
FX_StopSound(snd.voices[bestslot].id);
mutex_lock(&m_callback);
unative_t const ldnum = dnum;
dq[ldnum & (DQSIZE-1)] = (soundNum * MAXSOUNDINSTANCES) + bestslot;
dnum++;
mutex_unlock(&m_callback);
S_Cleanup();
return bestslot;
}
static int S_GetSlot(int soundNum)
{
int slot = 0;
while (slot < MAXSOUNDINSTANCES && g_sounds[soundNum].voices[slot].id > 0)
slot++;
return slot == MAXSOUNDINSTANCES ? S_TakeSlot(soundNum) : slot;
}
static inline int S_GetAngle(int ang, const vec3_t *cam, const vec3_t *pos)
{
return (2048 + ang - getangle(cam->x - pos->x, cam->y - pos->y)) & 2047;
}
static int S_CalcDistAndAng(int spriteNum, int soundNum, int sectNum, int angle,
const vec3_t *cam, const vec3_t *pos, int *distPtr, int *angPtr)
{
int sndang = 0, sndist = 0, explosion = 0;
if (PN(spriteNum) == APLAYER && P_Get(spriteNum) == screenpeek)
goto sound_further_processing;
sndang = S_GetAngle(angle, cam, pos);
sndist = FindDistance3D(cam->x-pos->x, cam->y-pos->y, (cam->z-pos->z));
if ((g_sounds[soundNum].m & (SF_GLOBAL|SF_DTAG)) != SF_GLOBAL && S_IsAmbientSFX(spriteNum) && (sector[SECT(spriteNum)].lotag&0xff) < 9) // ST_9_SLIDING_ST_DOOR
sndist = divscale14(sndist, SHT(spriteNum)+1);
sound_further_processing:
sndist += g_sounds[soundNum].vo;
if (sndist < 0)
sndist = 0;
if (!FURY && sectNum > -1 && sndist && PN(spriteNum) != MUSICANDSFX
&& !cansee(cam->x, cam->y, cam->z - (24 << 8), sectNum, SX(spriteNum), SY(spriteNum), SZ(spriteNum) - (24 << 8), SECT(spriteNum)))
sndist += sndist>>5;
if ((g_sounds[soundNum].m & (SF_GLOBAL|SF_DTAG)) == (SF_GLOBAL|SF_DTAG))
{
boost:
int const sdist = g_sounds[soundNum].vo > 0 ? g_sounds[soundNum].vo : 6144;
explosion = true;
if (sndist > sdist)
sndist = sdist;
}
else if (!FURY)
{
switch (DYNAMICSOUNDMAP(soundNum))
{
case PIPEBOMB_EXPLODE__STATIC:
case LASERTRIP_EXPLODE__STATIC:
case RPG_EXPLODE__STATIC:
goto boost;
}
}
if ((g_sounds[soundNum].m & (SF_GLOBAL|SF_DTAG)) == SF_GLOBAL || sndist < ((255-LOUDESTVOLUME) << 6))
sndist = ((255-LOUDESTVOLUME) << 6);
*distPtr = sndist;
*angPtr = sndang;
return explosion;
}
int S_PlaySound3D(int num, int spriteNum, const vec3_t *pos)
{
int32_t j = VM_OnEventWithReturn(EVENT_SOUND, spriteNum, screenpeek, num);
if ((j == -1 && num != -1) || !SoundEnabled()) // check that the user returned -1, but only if -1 wasn't playing already (in which case, warn)
return -1;
int const sndNum = j;
sound_t & snd = g_sounds[sndNum];
if (EDUKE32_PREDICT_FALSE((unsigned) sndNum > (unsigned) g_highestSoundIdx || snd.filename == NULL || snd.ptr == NULL))
{
OSD_Printf("WARNING: invalid sound #%d\n", num);
return -1;
}
auto const pPlayer = g_player[myconnectindex].ps;
if (((snd.m & SF_ADULT) && adult_lockout) || (unsigned)spriteNum >= MAXSPRITES || (pPlayer->gm & MODE_MENU) || !FX_VoiceAvailable(snd.pr)
|| (pPlayer->timebeforeexit > 0 && pPlayer->timebeforeexit <= GAMETICSPERSEC * 3))
return -1;
// Duke talk
if (snd.m & SF_TALK)
{
if ((g_netServer || ud.multimode > 1) && PN(spriteNum) == APLAYER && P_Get(spriteNum) != screenpeek) // other player sound
{
if ((snd_speech & 4) != 4)
return -1;
}
else if ((snd_speech & 1) != 1)
return -1;
// don't play if any Duke talk sounds are already playing
for (j = 0; j <= g_highestSoundIdx; ++j)
if ((g_sounds[j].m & SF_TALK) && g_sounds[j].num > 0)
return -1;
}
else if ((snd.m & (SF_DTAG|SF_GLOBAL)) == SF_DTAG) // Duke-Tag sound
{
int const voice = S_PlaySound(sndNum);
if (voice <= FX_Ok)
return -1;
j = 0;
while (j < MAXSOUNDINSTANCES && snd.voices[j].id != voice)
j++;
snd.voices[j].owner = spriteNum;
return voice;
}
int32_t sndist, sndang;
int const explosionp = S_CalcDistAndAng(spriteNum, sndNum, CAMERA(sect), fix16_to_int(CAMERA(q16ang)), &CAMERA(pos), pos, &sndist, &sndang);
int pitch = S_GetPitch(sndNum);
auto const pOther = g_player[screenpeek].ps;
if (pOther->sound_pitch)
pitch += pOther->sound_pitch;
if (explosionp)
{
if (pOther->cursectnum > -1 && sector[pOther->cursectnum].lotag == ST_2_UNDERWATER)
pitch -= 1024;
}
else
{
if (sndist > 32767 && PN(spriteNum) != MUSICANDSFX && (snd.m & (SF_LOOP|SF_MSFX)) == 0)
return -1;
if (pOther->cursectnum > -1 && sector[pOther->cursectnum].lotag == ST_2_UNDERWATER
&& (snd.m & SF_TALK) == 0)
pitch = -768;
}
if (snd.num > 0 && PN(spriteNum) != MUSICANDSFX)
S_StopEnvSound(sndNum, spriteNum);
int const sndSlot = S_GetSlot(sndNum);
if (sndSlot >= MAXSOUNDINSTANCES)
{
return -1;
}
int const repeatp = (snd.m & SF_LOOP);
if (repeatp && (snd.m & SF_ONEINST_INTERNAL) && snd.num > 0)
{
return -1;
}
int const voice = FX_Play3D(snd.ptr, snd.siz, repeatp ? FX_LOOP : FX_ONESHOT, pitch, sndang >> 4, sndist >> 6,
snd.pr, snd.volume, (sndNum * MAXSOUNDINSTANCES) + sndSlot);
if (voice <= FX_Ok)
{
return -1;
}
snd.num++;
S_SetProperties(&snd.voices[sndSlot], spriteNum, voice, sndist >> 6, 0);
return voice;
}
int S_PlaySound(int num)
{
int sndnum = VM_OnEventWithReturn(EVENT_SOUND, g_player[screenpeek].ps->i, screenpeek, num);
if ((sndnum == -1 && num != -1) || !SoundEnabled()) // check that the user returned -1, but only if -1 wasn't playing already (in which case, warn)
return -1;
num = sndnum;
sound_t & snd = g_sounds[num];
if (EDUKE32_PREDICT_FALSE((unsigned)num > (unsigned)g_highestSoundIdx || snd.filename == NULL || snd.ptr == NULL))
{
OSD_Printf("WARNING: invalid sound #%d\n",num);
return -1;
}
if ((!(snd_speech & 1) && (snd.m & SF_TALK)) || ((snd.m & SF_ADULT) && adult_lockout) || !FX_VoiceAvailable(snd.pr))
return -1;
int const pitch = S_GetPitch(num);
sndnum = S_GetSlot(num);
if (sndnum >= MAXSOUNDINSTANCES)
{
return -1;
}
int const voice = (snd.m & SF_LOOP) ? FX_Play(snd.ptr, snd.siz, 0, -1, pitch, LOUDESTVOLUME, LOUDESTVOLUME,
LOUDESTVOLUME, snd.siz, snd.volume, (num * MAXSOUNDINSTANCES) + sndnum)
: FX_Play3D(snd.ptr, snd.siz, FX_ONESHOT, pitch, 0, 255 - LOUDESTVOLUME, snd.pr, snd.volume,
(num * MAXSOUNDINSTANCES) + sndnum);
if (voice <= FX_Ok)
{
return -1;
}
snd.num++;
S_SetProperties(&snd.voices[sndnum], -1, voice, 255-LOUDESTVOLUME, 0);
return voice;
}
int A_PlaySound(int soundNum, int spriteNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned)soundNum > (unsigned)g_highestSoundIdx))
return -1;
return (unsigned)spriteNum >= MAXSPRITES ? S_PlaySound(soundNum) :
S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos);
}
void S_StopEnvSound(int sndNum, int sprNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned)sndNum > (unsigned)g_highestSoundIdx) || g_sounds[sndNum].num <= 0)
return;
int j;
do
{
for (j=0; j<MAXSOUNDINSTANCES; ++j)
{
S_Cleanup();
auto &voice = g_sounds[sndNum].voices[j];
if ((sprNum == -1 && voice.id > FX_Ok) || (sprNum != -1 && voice.owner == sprNum))
{
if (voice.id > FX_Ok)
{
if (FX_SoundActive(voice.id))
FX_StopSound(voice.id);
break;
}
}
}
}
while (j < MAXSOUNDINSTANCES);
}
// Do not remove this or make it inline.
void S_StopAllSounds(void)
{
FX_StopAllSounds();
}
void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset)
{
if ((unsigned)soundNum > (unsigned)g_highestSoundIdx || g_sounds[soundNum].num <= 0)
return;
for (auto &voice : g_sounds[soundNum].voices)
{
if ((spriteNum == -1 && voice.id > FX_Ok) || (spriteNum != -1 && voice.owner == spriteNum))
{
if (EDUKE32_PREDICT_FALSE(spriteNum >= 0 && voice.id <= FX_Ok))
initprintf(OSD_ERROR "S_ChangeSoundPitch(): bad voice %d for sound ID %d!\n", voice.id, soundNum);
else if (voice.id > FX_Ok && FX_SoundActive(voice.id))
FX_SetPitch(voice.id, pitchoffset);
break;
}
}
}
void S_Update(void)
{
if ((g_player[myconnectindex].ps->gm & (MODE_GAME|MODE_DEMO)) == 0)
return;
g_numEnvSoundsPlaying = 0;
const vec3_t *c;
int32_t ca,cs;
if (ud.camerasprite == -1)
{
if (ud.overhead_on != 2)
{
c = &CAMERA(pos);
cs = CAMERA(sect);
ca = fix16_to_int(CAMERA(q16ang));
}
else
{
auto pPlayer = g_player[screenpeek].ps;
c = &pPlayer->pos;
cs = pPlayer->cursectnum;
ca = fix16_to_int(pPlayer->q16ang);
}
}
else
{
c = &sprite[ud.camerasprite].pos;
cs = sprite[ud.camerasprite].sectnum;
ca = sprite[ud.camerasprite].ang;
}
int sndnum = 0;
int const highest = g_highestSoundIdx;
do
{
if (g_sounds[sndnum].num == 0)
continue;
S_Cleanup();
for (auto &voice : g_sounds[sndnum].voices)
{
int const spriteNum = voice.owner;
if ((unsigned)spriteNum >= MAXSPRITES || voice.id <= FX_Ok || !FX_SoundActive(voice.id))
continue;
int sndist, sndang;
S_CalcDistAndAng(spriteNum, sndnum, cs, ca, c, (const vec3_t *)&sprite[spriteNum], &sndist, &sndang);
if (S_IsAmbientSFX(spriteNum))
g_numEnvSoundsPlaying++;
// AMBIENT_SOUND
FX_Pan3D(voice.id, sndang >> 4, sndist >> 6);
voice.dist = sndist >> 6;
voice.clock++;
}
} while (++sndnum <= highest);
}
// S_Callback() can be called from either the audio thread when a sound ends, or the main thread
// when playing back a new sound needs an existing sound to be stopped first
void S_Callback(intptr_t num)
{
if ((int32_t)num == MUSIC_ID)
return;
mutex_lock(&m_callback);
unative_t const ldnum = dnum;
dq[ldnum & (DQSIZE - 1)] = (uint32_t)num;
dnum++;
mutex_unlock(&m_callback);
}
int A_CheckSoundPlaying(int spriteNum, int soundNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned)soundNum > (unsigned)g_highestSoundIdx)) return 0;
if (g_sounds[soundNum].num > 0 && spriteNum >= 0)
{
for (auto &voice : g_sounds[soundNum].voices)
if (voice.owner == spriteNum)
return 1;
}
return (spriteNum == -1) ? (g_sounds[soundNum].num != 0) : 0;
}
// Check if actor <i> is playing any sound.
int A_CheckAnySoundPlaying(int spriteNum)
{
int const msp = g_highestSoundIdx;
for (int j = 0; j <= msp; ++j)
{
for (auto &voice : g_sounds[j].voices)
if (voice.owner == spriteNum)
return 1;
}
return 0;
}
int S_CheckSoundPlaying(int soundNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned)soundNum > (unsigned)g_highestSoundIdx)) return false;
return (g_sounds[soundNum].num != 0);
}
END_DUKE_NS

View file

@ -1359,7 +1359,8 @@ ACTOR_STATIC void G_MoveFX(void)
else if (pSprite->lotag < 999 && (unsigned)sector[pSprite->sectnum].lotag < 9 && // ST_9_SLIDING_ST_DOOR
snd_ambience && sector[SECT(spriteNum)].floorz != sector[SECT(spriteNum)].ceilingz)
{
if (g_sounds[pSprite->lotag].m & SF_MSFX)
auto flags = S_GetUserFlags(pSprite->lotag);
if (flags & SF_MSFX)
{
int playerDist = dist(&sprite[pPlayer->i], pSprite);
@ -1372,11 +1373,10 @@ ACTOR_STATIC void G_MoveFX(void)
}
#endif
if (playerDist < spriteHitag && T1(spriteNum) == 0 && FX_VoiceAvailable(g_sounds[pSprite->lotag].pr-1))
if (playerDist < spriteHitag && T1(spriteNum) == 0)// && FX_VoiceAvailable(g_sounds[pSprite->lotag].pr-1))
{
// Start playing an ambience sound.
char om = g_sounds[pSprite->lotag].m;
#if 0 // let the sound system handle this internally.
if (g_numEnvSoundsPlaying == snd_numvoices)
{
int32_t j;
@ -1392,10 +1392,8 @@ ACTOR_STATIC void G_MoveFX(void)
if (j == -1)
goto next_sprite;
}
g_sounds[pSprite->lotag].m |= SF_LOOP;
A_PlaySound(pSprite->lotag,spriteNum);
g_sounds[pSprite->lotag].m = om;
#endif
A_PlaySound(pSprite->lotag, spriteNum, CHAN_LOOP);
T1(spriteNum) = 1; // AMBIENT_SFX_PLAYING
}
else if (playerDist >= spriteHitag && T1(spriteNum) == 1)
@ -1408,7 +1406,7 @@ ACTOR_STATIC void G_MoveFX(void)
}
}
if (g_sounds[pSprite->lotag].m & SF_GLOBAL)
if (flags & SF_GLOBAL)
{
// Randomly playing global sounds (flyby of planes, screams, ...)

View file

@ -396,7 +396,7 @@ int32_t Anim_Play(const char *fn)
if (sound == -1)
FX_StopAllSounds();
else
S_PlaySound(sound);
S_PlaySound(sound, CHAN_UI);
soundidx++;
}
@ -410,7 +410,7 @@ int32_t Anim_Play(const char *fn)
if (sound == -1)
FX_StopAllSounds();
else
S_PlaySound(sound);
S_PlaySound(sound, CHAN_UI);
soundidx++;
}
@ -566,7 +566,7 @@ int32_t Anim_Play(const char *fn)
if (sound == -1)
FX_StopAllSounds();
else
S_PlaySound(sound);
S_PlaySound(sound, CHAN_UI);
soundidx++;
}

View file

@ -361,15 +361,15 @@ void GameInterface::MenuSound(EMenuSounds snd)
switch (snd)
{
case CursorSound:
S_PlaySound(RR ? 335 : KICK_HIT);
S_PlaySound(RR ? 335 : KICK_HIT, CHAN_UI);
break;
case AdvanceSound:
S_PlaySound(RR? 341 : PISTOL_BODYHIT);
S_PlaySound(RR? 341 : PISTOL_BODYHIT, CHAN_UI);
break;
case CloseSound:
S_PlaySound(EXITMENUSOUND);
S_PlaySound(EXITMENUSOUND, CHAN_UI);
break;
default:
@ -443,7 +443,16 @@ void GameInterface::StartGame(FGameStartup& gs)
}
ud.m_player_skill = gs.Skill + 1;
if (menu_sounds) g_skillSoundVoice = S_PlaySound(skillsound);
if (menu_sounds && skillsound >= 0 && SoundEnabled())
{
S_PlaySound(skillsound, CHAN_UI);
while (S_CheckSoundPlaying(skillsound))
{
S_Update();
G_HandleAsync();
}
}
ud.m_respawn_monsters = (gs.Skill == 3);
ud.m_monsters_off = ud.monsters_off = 0;
ud.m_respawn_items = 0;

View file

@ -162,9 +162,7 @@ enum gametokens
static void gameTimerHandler(void)
{
S_Cleanup();
MUSIC_Update();
S_Update();
G_HandleSpecialKeys();
}
@ -6046,7 +6044,7 @@ void G_HandleLocalKeys(void)
{
if (G_ChangeHudLayout(1))
{
S_PlaySound(RR ? 341 : THUD);
S_PlaySound(RR ? 341 : THUD, CHAN_UI);
}
}
else
@ -6065,7 +6063,7 @@ void G_HandleLocalKeys(void)
{
if (G_ChangeHudLayout(-1))
{
S_PlaySound(RR ? 341 : THUD);
S_PlaySound(RR ? 341 : THUD, CHAN_UI);
}
}
else
@ -6311,43 +6309,6 @@ void G_HandleLocalKeys(void)
}
}
static int32_t S_DefineAudioIfSupported(char **fn, const char *name)
{
#if !defined HAVE_FLAC || !defined HAVE_VORBIS
const char *extension = Bstrrchr(name, '.');
# if !defined HAVE_FLAC
if (extension && !Bstrcasecmp(extension, ".flac"))
return -2;
# endif
# if !defined HAVE_VORBIS
if (extension && !Bstrcasecmp(extension, ".ogg"))
return -2;
# endif
#endif
realloc_copy(fn, name);
return 0;
}
static int32_t S_DefineSound(int sndidx, const char *name, int minpitch, int maxpitch, int priority, int type, int distance, float volume)
{
if ((unsigned)sndidx >= MAXSOUNDS || S_DefineAudioIfSupported(&g_sounds[sndidx].filename, name))
return -1;
auto &snd = g_sounds[sndidx];
snd.ps = clamp(minpitch, INT16_MIN, INT16_MAX);
snd.pe = clamp(maxpitch, INT16_MIN, INT16_MAX);
snd.pr = priority & 255;
snd.m = type & ~SF_ONEINST_INTERNAL;
snd.vo = clamp(distance, INT16_MIN, INT16_MAX);
snd.volume = volume;
if (snd.m & SF_LOOP)
snd.m |= SF_ONEINST_INTERNAL;
return 0;
}
// Returns:
// 0: all OK
// -1: ID declaration was invalid:
@ -6816,10 +6777,6 @@ static void G_Cleanup(void)
Bfree(g_player[i].inputBits);
}
for (i=MAXSOUNDS-1; i>=0; i--)
{
Bfree(g_sounds[i].filename);
}
if (label != (char *)&sprite[0]) Bfree(label);
if (labelcode != (int32_t *)&sector[0]) Bfree(labelcode);
Bfree(apScript);
@ -6843,7 +6800,6 @@ static void G_Cleanup(void)
void G_Shutdown(void)
{
S_SoundShutdown();
G_SetFog(0);
engineUnInit();
G_Cleanup();
@ -7306,6 +7262,7 @@ int GameInterface::app_main()
{
I_Error("app_main: There was a problem initializing the Build engine: %s\n", engineerrstr);
}
S_InitSound();
g_logFlushWindow = 0;
@ -7487,7 +7444,6 @@ int GameInterface::app_main()
}
videoSetPalette(0, g_player[myconnectindex].ps->palette, 0);
S_SoundStartup();
}
// check if the minifont will support lowercase letters (3136-3161)
@ -7656,7 +7612,6 @@ MAIN_LOOP_RESTART:
(g_player[myconnectindex].ps->gm&MODE_GAME))
{
G_MoveLoop();
S_Update();
}
if (totalclock - moveClock >= TICSPERFRAME)

View file

@ -199,6 +199,9 @@ extern user_defs ud;
extern const char *s_buildDate;
extern char boardfilename[BMAX_PATH];
#define USERMAPMUSICFAKEVOLUME MAXVOLUMES
#define USERMAPMUSICFAKELEVEL (MAXLEVELS-1)
#define USERMAPMUSICFAKESLOT ((USERMAPMUSICFAKEVOLUME * MAXLEVELS) + USERMAPMUSICFAKELEVEL)
static inline int G_HaveUserMap(void)
{

View file

@ -945,6 +945,7 @@ static inline void C_FinishBitOr(int32_t value)
static int32_t C_ParseCommand(int32_t loop)
{
int32_t i, j=0, k=0, tw;
TArray<char> buffer;
do
{
@ -1940,8 +1941,8 @@ static int32_t C_ParseCommand(int32_t loop)
C_SkipSpace();
TArray<char> buffer;
while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0)
buffer.Clear();
while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0)
{
buffer.Push(*textptr);
textptr++;
@ -1951,77 +1952,68 @@ static int32_t C_ParseCommand(int32_t loop)
continue;
}
case CON_DEFINESOUND:
{
int ps, pe, vo, pr, m;
g_scriptPtr--;
C_GetNextValue(LABEL_DEFINE);
// Ideally we could keep the value of i from C_GetNextValue() instead of having to hash_find() again.
// This depends on tempbuf remaining in place after C_GetNextValue():
j = hash_find(&h_labels,tempbuf);
j = hash_find(&h_labels, tempbuf);
k = *(g_scriptPtr-1);
if (EDUKE32_PREDICT_FALSE((unsigned)k >= MAXSOUNDS-1))
k = g_scriptPtr[-1];
if ((unsigned)k >= MAXSOUNDS - 1)
{
initprintf("%s:%d: error: index exceeds sound limit of %d.\n",g_scriptFileName,g_lineNumber, MAXSOUNDS-1);
initprintf("%s:%d: error: sound index exceeds limit of %d.\n", g_scriptFileName, g_lineNumber, MAXSOUNDS - 1);
g_errorCnt++;
k = MAXSOUNDS-1;
k = MAXSOUNDS - 1;
}
/*else if (g_sounds[k].filename != NULL)
{
initprintf("%s:%d: warning: sound %d already defined (%s)\n", g_scriptFileName, g_lineNumber, k, g_sounds[k].filename);
g_warningCnt++;
}*/
g_scriptPtr--;
i = 0;
C_SkipComments();
if (g_sounds[k].filename == NULL)
g_sounds[k].filename = (char *)Xcalloc(BMAX_PATH,sizeof(uint8_t));
buffer.Clear();
if (*textptr == '\"')
{
textptr++;
while (*textptr && *textptr != '\"')
{
g_sounds[k].filename[i++] = *textptr++;
if (EDUKE32_PREDICT_FALSE(i >= BMAX_PATH-1))
{
initprintf("%s:%d: error: sound filename exceeds limit of %d characters.\n",g_scriptFileName,g_lineNumber,BMAX_PATH-1);
g_errorCnt++;
C_SkipComments();
break;
}
buffer.Push(*textptr++);
}
textptr++;
}
else while (*textptr != ' ' && *textptr != '\t' && *textptr != '\r' && *textptr != '\n')
{
g_sounds[k].filename[i++] = *textptr++;
if (EDUKE32_PREDICT_FALSE(i >= BMAX_PATH-1))
{
initprintf("%s:%d: error: sound filename exceeds limit of %d characters.\n",g_scriptFileName,g_lineNumber,BMAX_PATH-1);
g_errorCnt++;
C_SkipComments();
break;
}
buffer.Push(*textptr++);
}
g_sounds[k].filename[i] = '\0';
buffer.Push(0);
C_GetNextValue(LABEL_DEFINE);
g_sounds[k].ps = *(g_scriptPtr-1);
ps = g_scriptPtr[-1];
C_GetNextValue(LABEL_DEFINE);
g_sounds[k].pe = *(g_scriptPtr-1);
pe = g_scriptPtr[-1];
C_GetNextValue(LABEL_DEFINE);
g_sounds[k].pr = *(g_scriptPtr-1);
pr = g_scriptPtr[-1];
C_GetNextValue(LABEL_DEFINE);
g_sounds[k].m = *(g_scriptPtr-1) & ~SF_ONEINST_INTERNAL;
if (*(g_scriptPtr-1) & SF_LOOP)
g_sounds[k].m |= SF_ONEINST_INTERNAL;
m = g_scriptPtr[-1];
C_GetNextValue(LABEL_DEFINE);
g_sounds[k].vo = *(g_scriptPtr-1);
vo = g_scriptPtr[-1];
g_scriptPtr -= 5;
g_sounds[k].volume = 1.f;
int res = S_DefineSound(k, buffer.Data(), ps, pe, pr, m, vo, 1.f);
if (k > g_highestSoundIdx)
g_highestSoundIdx = k;
continue;
}
case CON_ENDA:
if (EDUKE32_PREDICT_FALSE(!g_parsingActorPtr))

View file

@ -246,7 +246,6 @@ G_EXTERN input_t inputfifo[MOVEFIFOSIZ][MAXPLAYERS];
G_EXTERN int32_t g_noEnemies;
G_EXTERN int32_t g_restorePalette;
G_EXTERN int32_t g_screenCapture;
G_EXTERN sound_t g_sounds[MAXSOUNDS];
G_EXTERN uint32_t everyothertime;
G_EXTERN uint32_t g_moveThingsCount;
G_EXTERN double g_gameUpdateTime;

View file

@ -4417,12 +4417,7 @@ void P_FragPlayer(int playerNum)
if (!RR)
S_StopEnvSound(DUKE_JETPACK_IDLE, pPlayer->i);
if (pPlayer->scream_voice > FX_Ok)
{
FX_StopSound(pPlayer->scream_voice);
S_Cleanup();
pPlayer->scream_voice = -1;
}
S_StopEnvSound(-1, pPlayer->i, CHAN_VOICE);
if (pSprite->pal != 1 && (pSprite->cstat & 32768) == 0)
pSprite->cstat = 0;
@ -7123,11 +7118,9 @@ check_enemy_sprite:
if (pPlayer->vel.z > 2400 && pPlayer->falling_counter < 255)
{
pPlayer->falling_counter++;
if (pPlayer->falling_counter >= 38 && pPlayer->scream_voice <= FX_Ok)
if (pPlayer->falling_counter >= 38 && !A_CheckSoundPlaying(pPlayer->i, -1, CHAN_VOICE))
{
int32_t voice = A_PlaySound(DUKE_SCREAM,pPlayer->i);
if (voice <= 127) // XXX: p->scream_voice is an int8_t
pPlayer->scream_voice = voice;
A_PlaySound(DUKE_SCREAM, pPlayer->i, CHAN_VOICE);
}
}
@ -7179,12 +7172,7 @@ check_enemy_sprite:
{
pPlayer->falling_counter = 0;
if (pPlayer->scream_voice > FX_Ok)
{
FX_StopSound(pPlayer->scream_voice);
S_Cleanup();
pPlayer->scream_voice = -1;
}
S_StopEnvSound(-1, pPlayer->i, CHAN_VOICE);
if ((sectorLotag != ST_1_ABOVE_WATER && sectorLotag != ST_2_UNDERWATER) &&
(pPlayer->on_ground == 0 && pPlayer->vel.z > (6144 >> 1)))

View file

@ -575,7 +575,7 @@ void G_CacheMapData(void)
starttime = timerGetTicks();
S_PrecacheSounds();
cacheAllSounds();
G_PrecacheSprites();
for (i=0; i<numwalls; i++)
@ -1873,12 +1873,6 @@ void G_NewGame(int volumeNum, int levelNum, int skillNum)
G_HandleAsync();
if (g_skillSoundVoice >= 0 && SoundEnabled())
{
while (FX_SoundActive(g_skillSoundVoice))
G_HandleAsync();
}
g_skillSoundVoice = -1;
ready2send = 0;
@ -2282,7 +2276,7 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName)
}
}
userMapRecord.music = "dethtoll.mid";
if (!RR) userMapRecord.music = "dethtoll.mid";
}
int G_EnterLevel(int gameMode)
@ -2425,7 +2419,11 @@ int G_EnterLevel(int gameMode)
if (ud.recstat != 2)
{
S_PlayLevelMusicOrNothing(mii);
if (Menu_HaveUserMap())
{
S_PlayLevelMusicOrNothing(USERMAPMUSICFAKESLOT);
}
else S_PlayLevelMusicOrNothing(mii);
}
if (RR && !(gameMode & MODE_DEMO))

View file

@ -2979,7 +2979,7 @@ void G_BonusScreenRRRA(int32_t bonusonly)
Net_GetPackets();
break;
}
S_Cleanup();
if (!S_CheckSoundPlaying(-1,35)) break;
if (I_CheckAllInput())
{

View file

@ -75,9 +75,10 @@ int A_CallSound(int sectNum, int spriteNum)
if (spriteNum == -1)
spriteNum = SFXsprite;
auto flags = S_GetUserFlags(soundNum);
if (T1(SFXsprite) == 0)
{
if ((g_sounds[soundNum].m & SF_GLOBAL) == 0)
if ((flags & (SF_GLOBAL | SF_DTAG)) != SF_GLOBAL)
{
if (soundNum)
{
@ -98,7 +99,7 @@ int A_CallSound(int sectNum, int spriteNum)
if (SHT(SFXsprite))
A_PlaySound(SHT(SFXsprite), spriteNum);
if ((g_sounds[soundNum].m & SF_LOOP) || (SHT(SFXsprite) && SHT(SFXsprite) != soundNum))
if ((flags & SF_LOOP) || (SHT(SFXsprite) && SHT(SFXsprite) != soundNum))
S_StopEnvSound(soundNum, T6(SFXsprite));
T6(SFXsprite) = spriteNum;
@ -1783,7 +1784,9 @@ default_case:
S_PlaySound3D(SWITCH_ON, (switchType == SWITCH_SPRITE) ? wallOrSprite : g_player[playerNum].ps->i, &davector);
else if (hitag)
{
if (switchType == SWITCH_SPRITE && (g_sounds[hitag].m & SF_TALK) == 0)
auto flags = S_GetUserFlags(hitag);
if (switchType == SWITCH_SPRITE && (flags & SF_TALK) == 0)
S_PlaySound3D(hitag, wallOrSprite, &davector);
else
A_PlaySound(hitag, g_player[playerNum].ps->i);
@ -3037,7 +3040,7 @@ void A_DamageObject(int spriteNum, int const dmgSrc)
sprite[dmgSrc].xvel = (sprite[spriteNum].xvel>>1)+(sprite[spriteNum].xvel>>2);
sprite[dmgSrc].ang -= (SA(spriteNum)<<1)+1024;
SA(spriteNum) = getangle(SX(spriteNum)-sprite[dmgSrc].x,SY(spriteNum)-sprite[dmgSrc].y)-512;
if (g_sounds[POOLBALLHIT].num < 2)
if (S_CheckSoundPlaying(POOLBALLHIT) < 2)
A_PlaySound(POOLBALLHIT, spriteNum);
}
else if (RR && (sprite[dmgSrc].picnum == RRTILE3440 || sprite[dmgSrc].picnum == RRTILE3440+1))
@ -4192,11 +4195,7 @@ rrtripbomb_case:
if (pPlayer->jetpack_on)
{
pPlayer->inven_icon = ICON_JETPACK;
if (pPlayer->scream_voice > FX_Ok)
{
FX_StopSound(pPlayer->scream_voice);
pPlayer->scream_voice = -1;
}
S_StopEnvSound(-1, pPlayer->i, CHAN_VOICE);
A_PlaySound(DUKE_JETPACK_ON,pPlayer->i);

File diff suppressed because it is too large Load diff

View file

@ -30,61 +30,46 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define sounds_public_h_
#include "sounds_common.h"
#include "sound/s_soundinternal.h"
#include "z_music.h"
BEGIN_RR_NS
// KEEPINSYNC lunatic/con_lang.lua
#define MAXSOUNDS 4096
#define MAXSOUNDINSTANCES 8
#define LOUDESTVOLUME 111
#define MUSIC_ID -65536
typedef struct
{
int16_t owner;
int16_t id;
uint16_t dist;
uint16_t clock;
} assvoice_t;
typedef struct
{
char * ptr, *filename; // 8b/16b
int32_t length, num, siz; // 12b
float volume; // 4b
assvoice_t voices[MAXSOUNDINSTANCES]; // 64b
int16_t ps, pe, vo; // 6b
char pr, m; // 2b
int pitchStart, pitchEnd, volAdjust;
int priority, flags;
} sound_t;
extern sound_t g_sounds[MAXSOUNDS];
extern int32_t g_skillSoundVoice;
extern int32_t g_numEnvSoundsPlaying,g_highestSoundIdx;
bool A_CheckSoundPlaying(int spriteNum,int soundNum);
int A_PlaySound(int soundNum, int spriteNum);
int A_CheckSoundPlaying(int spriteNum, int soundNum, int flags = 0);
int A_PlaySound(int soundNum, int spriteNum, int flags = 0);
void S_Callback(intptr_t num);
bool A_CheckAnySoundPlaying(int spriteNum);
bool S_CheckSoundPlaying(int spriteNum,int soundNum);
void S_Cleanup(void);
int A_CheckAnySoundPlaying(int spriteNum);
int S_CheckSoundPlaying(int soundNum);
inline int S_CheckSoundPlaying(int sprnum, int soundNum) { return S_CheckSoundPlaying(soundNum); }
inline void S_ClearSoundLocks(void) {}
int32_t S_LoadSound(uint32_t num);
void S_PrecacheSounds(void);
void cacheAllSounds(void);
void S_MenuSound(void);
void S_PauseMusic(bool paused);
void S_PauseSounds(bool paused);
void S_PlayRRMusic(int newTrack = -1);
void S_PlayLevelMusicOrNothing(unsigned int);
int S_TryPlaySpecialMusic(unsigned int);
void S_PlaySpecialMusicOrNothing(unsigned int);
int S_PlaySound(int num);
int S_PlaySound3D(int num, int spriteNum, const vec3_t *pos);
void S_SoundShutdown(void);
void S_SoundStartup(void);
void S_StopEnvSound(int32_t num,int32_t i);
void S_ContinueLevelMusic(void);
int S_PlaySound(int num, int flags = 0);
int S_PlaySound3D(int num, int spriteNum, const vec3_t *pos, int flags = 0);
void S_StopEnvSound(int sndNum,int sprNum, int flags = -1);
void S_StopAllSounds(void);
void S_Update(void);
void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset);
int S_GetUserFlags(int sndnum);
int S_DefineSound(unsigned index, const char* filename, int ps, int pe, int pr, int m, int vo, float vol);
void S_InitSound();
void S_PlayRRMusic(int newTrack = -1);
static inline bool S_IsAmbientSFX(int spriteNum)
{

View file

@ -326,7 +326,7 @@ SWBOOL PlaySong(const char* mapname, const char* song_file_name, int cdaudio_tra
void
StopFX(void)
{
FX_StopAllSounds();
FX_StopAllSounds_();
}
void