mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
- properly transitioned Exhumed's sound system to the OpenAL sound engine.
This commit is contained in:
parent
3aea6d1fad
commit
3a7067dbec
6 changed files with 128 additions and 453 deletions
|
@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "sound.h"
|
||||
#include "names.h"
|
||||
#include "version.h"
|
||||
#include "s_soundinternal.h"
|
||||
|
||||
|
||||
#include "menu/menu.h"
|
||||
|
@ -89,7 +90,7 @@ class PSMainMenu : public DListMenu
|
|||
void Init(DMenu* parent, FListMenuDescriptor* desc) override
|
||||
{
|
||||
DListMenu::Init(parent, desc);
|
||||
PlayLocalSound(StaticSound[kSound31], 0);
|
||||
PlayLocalSound(StaticSound[kSound31], 0, false, CHANF_UI);
|
||||
}
|
||||
|
||||
void Ticker() override
|
||||
|
@ -163,12 +164,12 @@ void GameInterface::MenuSound(EMenuSounds snd)
|
|||
switch (snd)
|
||||
{
|
||||
case CursorSound:
|
||||
PlayLocalSound(StaticSound[kSound35], 0);
|
||||
PlayLocalSound(StaticSound[kSound35], 0, false, CHANF_UI);
|
||||
break;
|
||||
|
||||
case AdvanceSound:
|
||||
case BackSound:
|
||||
PlayLocalSound(StaticSound[kSound33], 0);
|
||||
PlayLocalSound(StaticSound[kSound33], 0, false, CHANF_UI);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -74,6 +74,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "gamecvars.h"
|
||||
#include "savegamehelp.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "s_soundinternal.h"
|
||||
|
||||
BEGIN_PS_NS
|
||||
|
||||
|
@ -1339,7 +1340,7 @@ void FinishLevel()
|
|||
if (levelnum != kMap20)
|
||||
{
|
||||
EraseScreen(4);
|
||||
PlayLocalSound(StaticSound[59], 0, true);
|
||||
PlayLocalSound(StaticSound[59], 0, true, CHANF_UI);
|
||||
videoNextPage();
|
||||
WaitTicks(12);
|
||||
WaitVBL();
|
||||
|
@ -2538,7 +2539,7 @@ void DoTitle()
|
|||
SetOverscan(BASEPAL);
|
||||
GrabPalette();
|
||||
|
||||
PlayLocalSound(StaticSound[59], 0, true);
|
||||
PlayLocalSound(StaticSound[59], 0, true, CHANF_UI);
|
||||
|
||||
EraseScreen(4);
|
||||
|
||||
|
@ -2567,7 +2568,7 @@ void DoTitle()
|
|||
PlayGameOverSound();
|
||||
}
|
||||
else {
|
||||
PlayLocalSound(StaticSound[61], 0);
|
||||
PlayLocalSound(StaticSound[61], 0, false, CHANF_UI);
|
||||
}
|
||||
|
||||
int nStartTime = (int)totalclock;
|
||||
|
|
|
@ -777,7 +777,7 @@ void SetTorch(int nPlayer, int bTorchOnOff)
|
|||
}
|
||||
|
||||
if (bTorch) {
|
||||
PlayLocalSound(kSoundTorchOn, 0);
|
||||
PlayLocalSound(StaticSound[kSoundTorchOn], 0);
|
||||
}
|
||||
|
||||
strcpy(buf, "TORCH IS ");
|
||||
|
|
|
@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "object.h"
|
||||
#include "light.h"
|
||||
#include "cd.h"
|
||||
#include "s_soundinternal.h"
|
||||
#include "menu/menu.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include <string>
|
||||
|
@ -844,100 +845,6 @@ int menu_DrawTheMap(int nLevel, int nLevelNew, int nLevelBest)
|
|||
return nLevelNew + 1;
|
||||
}
|
||||
|
||||
void menu_AdjustVolume()
|
||||
{
|
||||
int nOption = 1;
|
||||
int var_8 = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
HandleAsync();
|
||||
|
||||
menu_DoPlasma();
|
||||
|
||||
overwritesprite(80, 50, kMenuMusicTile, (Sin((int)totalclock << 4) >> 9) * (nOption == 0), 2, kPalNormal);
|
||||
overwritesprite(55, 75, kMenuBlankTitleTile, 0, 2, kPalNormal);
|
||||
|
||||
/*
|
||||
seq_DrawGunSequence(
|
||||
SeqOffsets[kSeqSlider], // eax
|
||||
gMusicVolume % 3, // pick one of 3 frames?
|
||||
(gMusicVolume >> 1) - 93, // ebx. must be x???
|
||||
-22,
|
||||
0,
|
||||
0);*/
|
||||
|
||||
overwritesprite(80, 110, kMenuSoundFxTile, (Sin((int)totalclock << 4) >> 9) * (nOption == 1), 2, kPalNormal);
|
||||
overwritesprite(55, 135, kMenuBlankTitleTile, 0, 2, kPalNormal);
|
||||
|
||||
seq_DrawGunSequence(
|
||||
SeqOffsets[kSeqSlider],
|
||||
snd_fxvolume % 3,
|
||||
(snd_fxvolume / 2) - 93,
|
||||
38,
|
||||
0,
|
||||
0);
|
||||
|
||||
int y = (60 * nOption) + 38;
|
||||
|
||||
overwritesprite(60, y, kMenuCursorTile, 0, 2, kPalNormal);
|
||||
overwritesprite(206, y, kMenuCursorTile, 0, 10, kPalNormal);
|
||||
|
||||
videoNextPage();
|
||||
|
||||
if (inputState.CheckAllInput())
|
||||
{
|
||||
PlayLocalSound(StaticSound[kSound33], 0);
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (I_MenuUp())
|
||||
{
|
||||
I_MenuUpClear();
|
||||
if (nOption > 0)
|
||||
{
|
||||
nOption--;
|
||||
PlayLocalSound(StaticSound[kSound35], 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (I_MenuDown())
|
||||
{
|
||||
I_MenuDownClear();
|
||||
if (nOption < 1)
|
||||
{
|
||||
nOption++;
|
||||
PlayLocalSound(StaticSound[kSound35], 0);
|
||||
}
|
||||
}
|
||||
|
||||
if ((int)totalclock <= var_8) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var_8 = (int)totalclock + 5;
|
||||
|
||||
if (I_MenuLeft())
|
||||
{
|
||||
I_MenuLeftClear();
|
||||
}
|
||||
|
||||
if (I_MenuRight())
|
||||
{
|
||||
I_MenuRightClear();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (GetLocalSound() != 23) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
StopLocalSound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int menu_NewGameMenu()
|
||||
{
|
||||
|
||||
|
@ -1580,7 +1487,7 @@ void DoLastLevelCinema()
|
|||
|
||||
int nString = FindGString("LASTLEVEL");
|
||||
|
||||
PlayLocalSound(StaticSound[kSound75], 0);
|
||||
PlayLocalSound(StaticSound[kSound75], 0, false, CHANF_UI);
|
||||
|
||||
auto pixels = TileFiles.tileMakeWritable(kTileLoboLaptop);
|
||||
// uh, what?
|
||||
|
@ -1662,7 +1569,7 @@ void DoLastLevelCinema()
|
|||
HandleAsync();
|
||||
|
||||
if (*nChar != ' ') {
|
||||
PlayLocalSound(StaticSound[kSound71], 0);
|
||||
PlayLocalSound(StaticSound[kSound71], 0, false, CHANF_UI);
|
||||
}
|
||||
|
||||
xPos += CopyCharToBitmap(*nChar, kTileLoboLaptop, xPos, ebp);
|
||||
|
@ -1701,7 +1608,7 @@ void DoLastLevelCinema()
|
|||
while (inputState.keyGetChar() != 27);
|
||||
|
||||
LABEL_28:
|
||||
PlayLocalSound(StaticSound[kSound75], 0);
|
||||
PlayLocalSound(StaticSound[kSound75], 0, false, CHANF_UI);
|
||||
|
||||
nEndTime = (int)totalclock + 240;
|
||||
|
||||
|
|
|
@ -118,8 +118,6 @@ const char *SoundFiles[kMaxSoundFiles] =
|
|||
"jon_air2" // 79
|
||||
};
|
||||
|
||||
short nAmbientChannel = -1;
|
||||
|
||||
short nStopSound;
|
||||
short nStoneSound;
|
||||
short nSwitchSound;
|
||||
|
@ -129,36 +127,11 @@ short nCreepyTimer;
|
|||
|
||||
bool looped[kMaxSounds];
|
||||
|
||||
struct ActiveSound
|
||||
{
|
||||
short snd_sprite;
|
||||
short snd_id;
|
||||
short snd_volume;
|
||||
short snd_angle;
|
||||
short snd_ambientflag;
|
||||
short snd_priority;
|
||||
int snd_handle;
|
||||
FSoundChan* snd_channel;
|
||||
int snd_pitch;
|
||||
int snd_time;
|
||||
int snd_x;
|
||||
int snd_y;
|
||||
int snd_z;
|
||||
short snd_sector;
|
||||
};
|
||||
|
||||
ActiveSound sActiveSound[kMaxSounds];
|
||||
short StaticSound[kMaxSounds];
|
||||
int fakesources[] = { 0, 1, 2, 3 };
|
||||
int nLocalChan = 0;
|
||||
int swirlysources[4];
|
||||
|
||||
enum
|
||||
{
|
||||
nSwirlyChan1 = 1,
|
||||
nSwirlyChan2,
|
||||
nSwirlyChan3,
|
||||
nSwirlyChan4,
|
||||
};
|
||||
int nLocalChan = 0;
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
@ -171,14 +144,6 @@ class EXSoundEngine : public SoundEngine
|
|||
// client specific parts of the sound engine go in this class.
|
||||
void CalcPosVel(int type, const void* source, const float pt[3], int channum, int chanflags, FSoundID chanSound, FVector3* pos, FVector3* vel, FSoundChan* chan) override;
|
||||
TArray<uint8_t> ReadSound(int lumpnum) override;
|
||||
void ChannelEnded(FISoundChannel* chan) override
|
||||
{
|
||||
for (auto& inf : sActiveSound)
|
||||
{
|
||||
if (inf.snd_channel == chan) inf.snd_channel = nullptr;
|
||||
}
|
||||
SoundEngine::ChannelEnded(chan);
|
||||
}
|
||||
|
||||
public:
|
||||
EXSoundEngine()
|
||||
|
@ -279,14 +244,6 @@ void InitFX(void)
|
|||
StaticSound[i] = LoadSound(SoundFiles[i]);
|
||||
}
|
||||
soundEngine->HashSounds();
|
||||
|
||||
memset(sActiveSound, 255, sizeof(sActiveSound));
|
||||
for (int i = 0; i < kMaxSounds; i++)
|
||||
{
|
||||
sActiveSound[i].snd_channel = nullptr;
|
||||
sActiveSound[i].snd_handle = -1;
|
||||
}
|
||||
|
||||
nCreepyTimer = kCreepyCount;
|
||||
}
|
||||
|
||||
|
@ -297,11 +254,11 @@ void InitFX(void)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void GetSpriteSoundPitch(short nSector, int* pVolume, int* pPitch, int nLocalSectFlags)
|
||||
void GetSpriteSoundPitch(int* pVolume, int* pPitch)
|
||||
{
|
||||
if (nSector < 0)
|
||||
return;
|
||||
if ((SectFlag[nSector] ^ nLocalSectFlags) & kSectUnderwater)
|
||||
int nSoundSect = nPlayerViewSect[nLocalPlayer];
|
||||
int nLocalSectFlags = SectFlag[nSoundSect];
|
||||
if (nLocalSectFlags & kSectUnderwater)
|
||||
{
|
||||
*pVolume >>= 1;
|
||||
*pPitch -= 1200;
|
||||
|
@ -316,13 +273,14 @@ void GetSpriteSoundPitch(short nSector, int* pVolume, int* pPitch, int nLocalSec
|
|||
|
||||
void BendAmbientSound(void)
|
||||
{
|
||||
if (nAmbientChannel < 0)
|
||||
return;
|
||||
ActiveSound* pASound = &sActiveSound[nAmbientChannel];
|
||||
if (pASound->snd_channel)
|
||||
soundEngine->EnumerateChannels([](FSoundChan* chan)
|
||||
{
|
||||
soundEngine->SetPitch(pASound->snd_channel, (nDronePitch + 11800) / 11025.f);
|
||||
if (chan->SourceType == SOURCE_Ambient)
|
||||
{
|
||||
soundEngine->SetPitch(chan, (nDronePitch + 11800) / 11025.f);
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -331,41 +289,31 @@ void BendAmbientSound(void)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void PlayLocalSound(short nSound, short nRate, bool unattached)
|
||||
void PlayLocalSound(short nSound, short nRate, bool unattached, EChanFlags cflags)
|
||||
{
|
||||
if (nSound < 0 || nSound >= kMaxSounds || !soundEngine->isValidSoundId(nSound + 1))
|
||||
{
|
||||
initprintf("PlayLocalSound: Invalid sound nSound == %i, nRate == %i\n", nSound, nRate);
|
||||
return;
|
||||
}
|
||||
int bLoop = looped[nSound];
|
||||
|
||||
if (nLocalChan == nAmbientChannel)
|
||||
nAmbientChannel = -1;
|
||||
|
||||
|
||||
ActiveSound* pASound = nullptr;
|
||||
if (looped[nSound]) cflags |= CHANF_LOOP;
|
||||
|
||||
FSoundChan* chan;
|
||||
if (!unattached)
|
||||
{
|
||||
pASound = &sActiveSound[nLocalChan];
|
||||
if (pASound->snd_channel != nullptr)
|
||||
soundEngine->StopChannel(pASound->snd_channel);
|
||||
soundEngine->StopSound(SOURCE_None, nullptr, CHAN_BODY);
|
||||
chan = soundEngine->StartSound(SOURCE_None, nullptr, nullptr, CHAN_BODY, cflags, nSound + 1, 1.f, ATTN_NONE, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
chan = soundEngine->StartSound(SOURCE_None, nullptr, nullptr, CHAN_VOICE, CHANF_OVERLAP|cflags, nSound + 1, 1.f, ATTN_NONE, nullptr);
|
||||
}
|
||||
|
||||
// There is exactly one occurence in the entire game which alters the pitch, and that's the laugh on the logo.
|
||||
auto chan = soundEngine->StartSound(SOURCE_Unattached, nullptr, nullptr, CHAN_BODY, CHANF_OVERLAP, nSound + 1, 1.f, ATTN_NONE, nullptr);
|
||||
|
||||
if (nRate && chan)
|
||||
{
|
||||
float ratefac = (11025 + nRate) / 11025.f;
|
||||
soundEngine->SetPitch(chan, ratefac);
|
||||
}
|
||||
if (pASound)
|
||||
{
|
||||
pASound->snd_id = nSound;
|
||||
pASound->snd_channel = chan;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -376,15 +324,10 @@ void PlayLocalSound(short nSound, short nRate, bool unattached)
|
|||
|
||||
int LocalSoundPlaying(void)
|
||||
{
|
||||
return sActiveSound[nLocalChan].snd_channel != nullptr;
|
||||
}
|
||||
|
||||
int GetLocalSound(void)
|
||||
return soundEngine->EnumerateChannels([](FSoundChan* chan)
|
||||
{
|
||||
if (LocalSoundPlaying() == -1)
|
||||
return -1;
|
||||
|
||||
return sActiveSound[nLocalChan].snd_id & 0x1ff;
|
||||
return chan->SourceType == SOURCE_None;
|
||||
});
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -395,14 +338,7 @@ int GetLocalSound(void)
|
|||
|
||||
void StopLocalSound(void)
|
||||
{
|
||||
if (nLocalChan == nAmbientChannel)
|
||||
nAmbientChannel = -1;
|
||||
|
||||
if (LocalSoundPlaying())
|
||||
{
|
||||
soundEngine->StopChannel(sActiveSound[nLocalChan].snd_channel);
|
||||
sActiveSound[nLocalChan].snd_channel = nullptr;
|
||||
}
|
||||
soundEngine->StopSound(SOURCE_None, nullptr, -1);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -415,11 +351,9 @@ int nSwirlyFrames;
|
|||
|
||||
void StartSwirly(int nActiveSound)
|
||||
{
|
||||
ActiveSound* pASound = &sActiveSound[nActiveSound];
|
||||
pASound->snd_angle = rand() & 0x7ff;
|
||||
auto &swirly = swirlysources[nActiveSound];
|
||||
|
||||
short nPitch = nNextFreq - RandomSize(9);
|
||||
pASound->snd_pitch = nPitch;
|
||||
nNextFreq = 25000 - RandomSize(10) * 6;
|
||||
if (nNextFreq > 32000)
|
||||
nNextFreq = 32000;
|
||||
|
@ -428,10 +362,8 @@ void StartSwirly(int nActiveSound)
|
|||
if (nVolume >= 220)
|
||||
nVolume = 220;
|
||||
|
||||
pASound->snd_volume = nVolume;
|
||||
if (pASound->snd_channel) soundEngine->StopChannel(pASound->snd_channel);
|
||||
|
||||
pASound->snd_channel = soundEngine->StartSound(SOURCE_Swirly, &fakesources[nActiveSound-1], nullptr, CHAN_BODY, 0, StaticSound[kSoundMana1]+1, nVolume / 255.f, ATTN_NONE, nullptr, nPitch / 11025.f);
|
||||
soundEngine->StopSound(SOURCE_Swirly, &swirly, -1);
|
||||
soundEngine->StartSound(SOURCE_Swirly, &fakesources[nActiveSound-1], nullptr, CHAN_BODY, 0, StaticSound[kSoundMana1]+1, nVolume / 255.f, ATTN_NONE, nullptr, nPitch / 11025.f);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -447,7 +379,7 @@ void StartSwirlies()
|
|||
nNextFreq = 19000;
|
||||
nSwirlyFrames = 0;
|
||||
|
||||
for (int i = nSwirlyChan1; i <= nSwirlyChan4; i++)
|
||||
for (int i = 0; i <= 4; i++)
|
||||
StartSwirly(i);
|
||||
}
|
||||
|
||||
|
@ -460,11 +392,9 @@ void StartSwirlies()
|
|||
void UpdateSwirlies()
|
||||
{
|
||||
nSwirlyFrames++;
|
||||
for (int i = nSwirlyChan1; i <= nSwirlyChan4; i++)
|
||||
for (int i = 0; i <= 4; i++)
|
||||
{
|
||||
ActiveSound* pASound = &sActiveSound[i];
|
||||
|
||||
if (pASound->snd_channel == nullptr)
|
||||
if (!soundEngine->IsSourcePlayingSomething(SOURCE_Swirly, &swirlysources[i], -1))
|
||||
StartSwirly(i);
|
||||
}
|
||||
}
|
||||
|
@ -478,13 +408,12 @@ void UpdateSwirlies()
|
|||
void SoundBigEntrance(void)
|
||||
{
|
||||
StopAllSounds();
|
||||
ActiveSound* pASound = sActiveSound+1;
|
||||
for (int i = 0; i < 4; i++, pASound++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
short nPitch = i * 512 - 1200;
|
||||
pASound->snd_pitch = nPitch;
|
||||
if (pASound->snd_channel) soundEngine->StopChannel(pASound->snd_channel);
|
||||
pASound->snd_channel = soundEngine->StartSound(SOURCE_EXBoss, &fakesources[i], nullptr, CHAN_BODY, 0, StaticSound[kSoundTorchOn]+1, 200 / 255.f, ATTN_NONE, nullptr, nPitch / 11025.f);
|
||||
//pASound->snd_pitch = nPitch;
|
||||
soundEngine->StopSound(SOURCE_EXBoss, &fakesources[i], -1);
|
||||
soundEngine->StartSound(SOURCE_EXBoss, &fakesources[i], nullptr, CHAN_BODY, 0, StaticSound[kSoundTorchOn]+1, 200 / 255.f, ATTN_NONE, nullptr, nPitch / 11025.f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -514,7 +443,7 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3],
|
|||
}
|
||||
auto fcampos = GetSoundPos(&campos);
|
||||
|
||||
if (type == SOURCE_Unattached)
|
||||
if (type == SOURCE_Unattached || type == SOURCE_Ambient)
|
||||
{
|
||||
pos->X = pt[0];
|
||||
pos->Y = pt[1];
|
||||
|
@ -606,40 +535,18 @@ void UpdateSounds()
|
|||
|
||||
soundEngine->SetListener(listener);
|
||||
soundEngine->UpdateSounds((int)totalclock);
|
||||
ActiveSound* pASound = sActiveSound;
|
||||
pASound++;
|
||||
for (int i = 1; i < kMaxActiveSounds; i++, pASound++)
|
||||
soundEngine->EnumerateChannels([](FSoundChan* chan)
|
||||
{
|
||||
if (pASound->snd_channel != nullptr)
|
||||
if (!(chan->ChanFlags & (CHANF_UI|CHANF_FORGETTABLE)))
|
||||
{
|
||||
if (pASound->snd_channel->ChanFlags & CHANF_FORGETTABLE)
|
||||
{
|
||||
// If the channel has become invalid, remove the reference.
|
||||
// ChannelEnded may be called late so waiting for it is problematic.
|
||||
pASound->snd_channel = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
short nSoundSprite = pASound->snd_sprite;
|
||||
int nPitch = pASound->snd_pitch;
|
||||
short nSoundSect;
|
||||
if (nSoundSprite >= 0)
|
||||
{
|
||||
if (nSoundSprite == nLocalSpr)
|
||||
nSoundSect = nPlayerViewSect[nLocalPlayer];
|
||||
else
|
||||
nSoundSect = sprite[nSoundSprite].sectnum;
|
||||
}
|
||||
else
|
||||
nSoundSect = pASound->snd_sector;
|
||||
|
||||
int nVolume = pASound->snd_volume;
|
||||
GetSpriteSoundPitch(nSoundSect, &nVolume, &nPitch, nLocalSectFlags);
|
||||
soundEngine->SetPitch(pASound->snd_channel, (11025 + nPitch) / 11025.f);
|
||||
soundEngine->SetVolume(pASound->snd_channel, nVolume / 255.f);
|
||||
}
|
||||
}
|
||||
int nVolume = 255;
|
||||
int nPitch = int(chan->Pitch * (128.f * 11025.f)) - 11025;
|
||||
GetSpriteSoundPitch(&nVolume, &nPitch);
|
||||
soundEngine->SetPitch(chan, (11025 + nPitch) / 11025.f);
|
||||
soundEngine->SetVolume(chan, nVolume / 255.f);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -651,187 +558,57 @@ void UpdateSounds()
|
|||
int soundx, soundy, soundz;
|
||||
short soundsect;
|
||||
|
||||
short PlayFX2(unsigned short nSound, short nSprite)
|
||||
void PlayFX2(unsigned short nSound, short nSprite)
|
||||
{
|
||||
if ((nSound&0x1ff) >= kMaxSounds || !soundEngine->isValidSoundId((nSound & 0x1ff)+1))
|
||||
{
|
||||
initprintf("PlayFX2: Invalid sound nSound == %i, nSprite == %i\n", nSound, nSprite);
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
int nLocalSectFlags = SectFlag[nPlayerViewSect[nLocalPlayer]];
|
||||
short v1c;
|
||||
short vcx;
|
||||
if (nSprite < 0)
|
||||
if (nSprite >= 0)
|
||||
{
|
||||
vcx = 0;
|
||||
v1c = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
v1c = nSprite&0x2000;
|
||||
vcx = nSprite&0x4000;
|
||||
nSprite &= 0xfff;
|
||||
soundx = sprite[nSprite].x;
|
||||
soundy = sprite[nSprite].y;
|
||||
soundz = sprite[nSprite].z;
|
||||
}
|
||||
int dx, dy;
|
||||
|
||||
dx = initx-soundx;
|
||||
dy = inity-soundy;
|
||||
|
||||
dx >>= 8; dy >>= 8;
|
||||
|
||||
short nSoundAng;
|
||||
if ((dx|dy) == 0)
|
||||
nSoundAng = 0;
|
||||
else
|
||||
nSoundAng = AngleDelta(GetMyAngle(dx, dy), inita, 1024);
|
||||
int dx = (initx-soundx) >> 8;
|
||||
int dy = (inity-soundy) >> 8;
|
||||
|
||||
int nDist = GetDistFromDXDY(dx, dy);
|
||||
if (nDist >= 255)
|
||||
{
|
||||
if ((int16_t)nSound > -1)
|
||||
StopSpriteSound(nSound);
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
int nVolume;
|
||||
int nVolume = 255;
|
||||
|
||||
if (!v1c)
|
||||
{
|
||||
nVolume = snd_fxvolume+10-(Sin(nDist<<1)>>6)-10;
|
||||
if (nVolume <= 0)
|
||||
{
|
||||
if ((int16_t)nSound > -1)
|
||||
StopSpriteSound(nSound);
|
||||
return -1;
|
||||
}
|
||||
if (nVolume > 255)
|
||||
nVolume = 255;
|
||||
}
|
||||
else
|
||||
nVolume = snd_fxvolume;
|
||||
|
||||
short vc = nSound & (~0x1ff);
|
||||
short v4 = nSound & 0x2000;
|
||||
short v8 = nSound & 0x1000;
|
||||
short v14 = nSound & 0x4000;
|
||||
short v10 = (nSound&0xe00)>>9;
|
||||
int v2c = 0x7fffffff;
|
||||
ActiveSound* v38 = NULL;
|
||||
ActiveSound* v28 = NULL;
|
||||
ActiveSound* vdi = NULL;
|
||||
nSound &= 0x1ff;
|
||||
|
||||
short priority;
|
||||
int nPitch = 0;
|
||||
if (v10) nPitch = -(totalmoves&((1<<v10)-1))*16;
|
||||
|
||||
if (v8 || v14)
|
||||
priority = 1000;
|
||||
else if (nSprite != -1 && vcx)
|
||||
priority = 2000;
|
||||
else
|
||||
priority = 0;
|
||||
ActiveSound* pASound = sActiveSound;
|
||||
pASound++;
|
||||
for (int i = 1; i < kMaxActiveSounds; i++, pASound++)
|
||||
{
|
||||
if (pASound->snd_channel == nullptr)
|
||||
{
|
||||
vdi = pASound;
|
||||
}
|
||||
else if (priority >= pASound->snd_priority)
|
||||
{
|
||||
if (v2c > pASound->snd_time && pASound->snd_priority <= priority)
|
||||
{
|
||||
v28 = pASound;
|
||||
v2c = pASound->snd_time;
|
||||
}
|
||||
if (!v8)
|
||||
{
|
||||
if (nSound == pASound->snd_id)
|
||||
{
|
||||
if (v4 == 0 && nSprite == pASound->snd_sprite)
|
||||
return -1;
|
||||
if (priority >= pASound->snd_priority)
|
||||
v38 = pASound;
|
||||
}
|
||||
else if (nSprite == pASound->snd_sprite)
|
||||
{
|
||||
if (v4 || nSound != pASound->snd_id)
|
||||
{
|
||||
vdi = pASound;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!vdi)
|
||||
{
|
||||
if (v38)
|
||||
vdi = v38;
|
||||
else if (v28)
|
||||
vdi = v28;
|
||||
}
|
||||
|
||||
if (vdi->snd_channel != nullptr)
|
||||
{
|
||||
soundEngine->StopChannel(vdi->snd_channel);
|
||||
vdi->snd_channel = nullptr;
|
||||
if (short(vdi - sActiveSound) == nAmbientChannel) // f_2c was never set to anything other than 0.
|
||||
nAmbientChannel = -1;
|
||||
}
|
||||
|
||||
int nPitch;
|
||||
if (v10)
|
||||
nPitch = -(totalmoves&((1<<v10)-1))*16;
|
||||
else
|
||||
nPitch = 0;
|
||||
|
||||
if (vdi)
|
||||
{
|
||||
vdi->snd_pitch = nPitch;
|
||||
if (nSprite < 0)
|
||||
{
|
||||
vdi->snd_x = soundx;
|
||||
vdi->snd_y = soundy;
|
||||
vdi->snd_sector = soundsect;
|
||||
}
|
||||
GetSpriteSoundPitch(soundsect, &nVolume, &nPitch, nLocalSectFlags);
|
||||
vdi->snd_volume = nVolume;
|
||||
vdi->snd_angle = nSoundAng;
|
||||
vdi->snd_sprite = nSprite;
|
||||
vdi->snd_id = nSound;
|
||||
vdi->snd_time = (int)totalclock;
|
||||
vdi->snd_priority = priority;
|
||||
vdi->snd_ambientflag = vc;
|
||||
|
||||
int bLoop = looped[nSound];
|
||||
GetSpriteSoundPitch(&nVolume, &nPitch);
|
||||
|
||||
if (nSprite)
|
||||
{
|
||||
vdi->snd_channel = soundEngine->StartSound(SOURCE_Actor, &sprite[nSprite], nullptr, CHAN_BODY, CHANF_OVERLAP, nSound+1, nVolume / 255.f, ATTN_NORM, nullptr, (11025 + nPitch) / 11025.f);
|
||||
soundEngine->StartSound(SOURCE_Actor, &sprite[nSprite], nullptr, CHAN_BODY, CHANF_NONE, nSound+1, nVolume / 255.f, ATTN_NORM, nullptr, (11025 + nPitch) / 11025.f);
|
||||
}
|
||||
else
|
||||
{
|
||||
vec3_t v = { soundx, soundy, soundz };
|
||||
FVector3 vv = GetSoundPos(&v);
|
||||
vdi->snd_channel = soundEngine->StartSound(SOURCE_Unattached, nullptr, &vv, CHAN_BODY, CHANF_OVERLAP, nSound+1, nVolume / 255.f, ATTN_NORM, nullptr, (11025 + nPitch) / 11025.f);
|
||||
soundEngine->StartSound(SOURCE_Unattached, nullptr, &vv, CHAN_BODY, CHANF_OVERLAP, nSound+1, nVolume / 255.f, ATTN_NONE, nullptr, (11025 + nPitch) / 11025.f);
|
||||
}
|
||||
|
||||
if (v14)
|
||||
nAmbientChannel = v14;
|
||||
|
||||
// Nuke: added nSprite >= 0 check
|
||||
if (nSprite != nLocalSpr && nSprite >= 0 && (sprite[nSprite].cstat&257))
|
||||
nCreepyTimer = kCreepyCount;
|
||||
|
||||
return v14;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -840,16 +617,13 @@ short PlayFX2(unsigned short nSound, short nSprite)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
short PlayFXAtXYZ(unsigned short ax, int x, int y, int z, int nSector)
|
||||
void PlayFXAtXYZ(unsigned short ax, int x, int y, int z, int nSector)
|
||||
{
|
||||
soundx = x;
|
||||
soundy = y;
|
||||
soundz = z;
|
||||
soundsect = nSector&0x3fff;
|
||||
short nSnd = PlayFX2(ax, -1);
|
||||
if (nSnd > -1 && (nSector&0x4000))
|
||||
sActiveSound[nSnd].snd_priority = 2000;
|
||||
return nSnd;
|
||||
soundsect = nSector&0xfff;
|
||||
PlayFX2(ax, -1);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -864,32 +638,40 @@ void CheckAmbience(short nSector)
|
|||
{
|
||||
short nSector2 = SectSoundSect[nSector];
|
||||
walltype* pWall = &wall[sector[nSector2].wallptr];
|
||||
if (nAmbientChannel < 0)
|
||||
if (!soundEngine->IsSourcePlayingSomething(SOURCE_Ambient, nullptr, -1))
|
||||
{
|
||||
PlayFXAtXYZ(SectSound[nSector] | 0x4000, pWall->x, pWall->y, sector[nSector2].floorz, nSector);
|
||||
vec3_t v = { pWall->x, pWall->y, sector[nSector2].floorz };
|
||||
FVector3 vv = GetSoundPos(&v);
|
||||
soundEngine->StartSound(SOURCE_Ambient, nullptr, &vv, CHAN_BODY, CHANF_NONE, SectSound[nSector], 1.f, ATTN_NORM);
|
||||
return;
|
||||
}
|
||||
ActiveSound* pASound = &sActiveSound[nAmbientChannel];
|
||||
soundEngine->EnumerateChannels([=](FSoundChan* chan)
|
||||
{
|
||||
if (chan->SourceType == SOURCE_Ambient)
|
||||
{
|
||||
FVector3 vv;
|
||||
if (nSector == nSector2)
|
||||
{
|
||||
spritetype* pSprite = &sprite[PlayerList[0].nSprite];
|
||||
pASound->snd_x = pSprite->x;
|
||||
pASound->snd_y = pSprite->y;
|
||||
pASound->snd_z = pSprite->z;
|
||||
vv = GetSoundPos(&pSprite->pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
pASound->snd_x = pWall->x;
|
||||
pASound->snd_y = pWall->y;
|
||||
pASound->snd_z = sector[nSector2].floorz;
|
||||
vec3_t v = { pWall->x, pWall->y, sector[nSector2].floorz };
|
||||
vv = GetSoundPos(&v);
|
||||
}
|
||||
chan->Point[0] = vv.X;
|
||||
chan->Point[1] = vv.Y;
|
||||
chan->Point[2] = vv.Z;
|
||||
return 1;
|
||||
}
|
||||
else if (nAmbientChannel != -1)
|
||||
return 0;
|
||||
});
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sActiveSound[nAmbientChannel].snd_channel)
|
||||
soundEngine->StopChannel(sActiveSound[nAmbientChannel].snd_channel);
|
||||
sActiveSound[nAmbientChannel].snd_channel = nullptr;
|
||||
nAmbientChannel = -1;
|
||||
soundEngine->StopSound(SOURCE_Ambient, nullptr, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -934,33 +716,15 @@ void UpdateCreepySounds()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
short D3PlayFX(unsigned short nSound, short nVal)
|
||||
{
|
||||
return PlayFX2(nSound, nVal);
|
||||
}
|
||||
|
||||
void StopSpriteSound(short nSprite)
|
||||
{
|
||||
for (int i = 0; i < kMaxActiveSounds; i++)
|
||||
{
|
||||
if (sActiveSound[i].snd_channel != nullptr && nSprite == sActiveSound[i].snd_sprite)
|
||||
{
|
||||
soundEngine->StopChannel(sActiveSound[i].snd_channel);
|
||||
sActiveSound[i].snd_channel = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (nSprite >= 0 && nSprite < MAXSPRITES)
|
||||
soundEngine->StopSound(SOURCE_Actor, &sprite[nSprite], -1);
|
||||
}
|
||||
|
||||
void StopAllSounds(void)
|
||||
{
|
||||
soundEngine->StopAllChannels();
|
||||
for (int i = 0; i < kMaxActiveSounds; i++)
|
||||
{
|
||||
sActiveSound[i].snd_channel = nullptr;
|
||||
}
|
||||
|
||||
nAmbientChannel = -1;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -971,17 +735,17 @@ void StopAllSounds(void)
|
|||
|
||||
void PlayTitleSound(void)
|
||||
{
|
||||
PlayLocalSound(StaticSound[kSoundItemSpecial], 0);
|
||||
PlayLocalSound(StaticSound[kSoundItemSpecial], 0, false, CHANF_UI);
|
||||
}
|
||||
|
||||
void PlayLogoSound(void)
|
||||
{
|
||||
PlayLocalSound(StaticSound[kSoundJonLaugh2], 7000);
|
||||
PlayLocalSound(StaticSound[kSoundJonLaugh2], 7000, false, CHANF_UI);
|
||||
}
|
||||
|
||||
void PlayGameOverSound(void)
|
||||
{
|
||||
PlayLocalSound(StaticSound[kSoundJonLaugh2], 0);
|
||||
PlayLocalSound(StaticSound[kSoundJonLaugh2], 0, false, CHANF_UI);
|
||||
}
|
||||
|
||||
END_PS_NS
|
||||
|
|
|
@ -19,6 +19,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#ifndef __sound_h__
|
||||
#define __sound_h__
|
||||
|
||||
#include "s_soundinternal.h"
|
||||
|
||||
BEGIN_PS_NS
|
||||
|
||||
|
||||
|
@ -119,24 +121,24 @@ void UpdateSounds();
|
|||
void UpdateCreepySounds();
|
||||
|
||||
void InitFX();
|
||||
void UnInitFX();
|
||||
void FadeSong();
|
||||
int fadecdaudio();
|
||||
int LocalSoundPlaying();
|
||||
void LoadFX();
|
||||
void StopAllSounds();
|
||||
int GetLocalSound();
|
||||
void UpdateLocalSound();
|
||||
void StopLocalSound();
|
||||
void PlayLocalSound(short nSound, short val, bool unattached = false);
|
||||
void PlayLocalSound(short nSound, short val, bool unattached = false, EChanFlags cflags = CHANF_NONE);
|
||||
int LoadSound(const char* sound);
|
||||
|
||||
void BendAmbientSound();
|
||||
void CheckAmbience(short nSector);
|
||||
|
||||
short PlayFX2(unsigned short nSound, short nSprite);
|
||||
short PlayFXAtXYZ(unsigned short nSound, int x, int y, int z, int nSector);
|
||||
short D3PlayFX(unsigned short nSound, short nSprite);
|
||||
void PlayFX2(unsigned short nSound, short nSprite);
|
||||
void PlayFXAtXYZ(unsigned short nSound, int x, int y, int z, int nSector);
|
||||
inline void D3PlayFX(unsigned short nSound, short nVal)
|
||||
{
|
||||
PlayFX2(nSound, nVal);
|
||||
}
|
||||
void StopSpriteSound(short nSprite);
|
||||
|
||||
void StartSwirlies();
|
||||
|
|
Loading…
Reference in a new issue