diff --git a/source/blood/src/asound.cpp b/source/blood/src/asound.cpp index 15ea72066..12334c2e0 100644 --- a/source/blood/src/asound.cpp +++ b/source/blood/src/asound.cpp @@ -94,7 +94,7 @@ void ambProcess(void) else if (pChannel->distance > 0) { FVector3 pt{}; - soundEngine->StartSound(SOURCE_Ambient, pChannel, &pt, CHAN_BODY, CHANF_LOOP, pChannel->soundID, pChannel->distance / 255.f, ATTN_NONE); + soundEngine->StartSound(SOURCE_Ambient, pChannel, &pt, CHAN_BODY, CHANF_LOOP|CHANF_TRANSIENT, pChannel->soundID, pChannel->distance / 255.f, ATTN_NONE); } pChannel->distance = 0; } diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index 6e7dcd179..1bf49ef50 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -836,7 +836,6 @@ void WeaponLoadSaveConstruct(void); #ifdef NOONE_EXTENSIONS void NNLoadSaveConstruct(void); #endif -void ASoundLoadSaveConstruct(void); void LoadSaveSetup(void) { @@ -858,7 +857,6 @@ void LoadSaveSetup(void) #ifdef NOONE_EXTENSIONS NNLoadSaveConstruct(); #endif - ASoundLoadSaveConstruct(); } END_BLD_NS diff --git a/source/blood/src/seq.cpp b/source/blood/src/seq.cpp index b279e5c7d..4aede988c 100644 --- a/source/blood/src/seq.cpp +++ b/source/blood/src/seq.cpp @@ -332,7 +332,7 @@ void SEQINST::Update(ACTIVE *pActive) auto snd = soundEngine->FindSoundByResID(sndId); if (snd > 0) { - auto udata = (int*)soundEngine->GetUserData(snd); + auto udata = soundEngine->GetUserData(snd); int relVol = udata ? udata[2] : 255; sfxPlay3DSoundCP(pSprite, sndId, -1, 0, 0, (surfSfxMove[surf][2] != relVol) ? relVol : surfSfxMove[surf][3]); } diff --git a/source/blood/src/sfx.cpp b/source/blood/src/sfx.cpp index f0b8cd1a5..c82ea6189 100644 --- a/source/blood/src/sfx.cpp +++ b/source/blood/src/sfx.cpp @@ -133,7 +133,7 @@ void sfxUpdate3DSounds(void) FSoundID getSfx(FSoundID soundId, float &attenuation, int &pitch, int &relvol) { - auto udata = (int*)soundEngine->GetUserData(soundId); + auto udata = soundEngine->GetUserData(soundId); if (pitch < 0) pitch = udata ? udata[0] : 0x10000; if (relvol < 0) relvol = udata && udata[2] ? udata[2] : 80; diff --git a/source/blood/src/sound.cpp b/source/blood/src/sound.cpp index 43fdcbe02..3d55c56c7 100644 --- a/source/blood/src/sound.cpp +++ b/source/blood/src/sound.cpp @@ -90,7 +90,7 @@ static void S_AddBloodSFX(int lumpnum) S_sfx[sfxnum].bLoadRAW = true; S_sfx[sfxnum].LoopStart = LittleLong(sfx->loopStart); //S_sfx[sfxnum].Volume = sfx->relVol / 255.f; This cannot be done because this volume setting is optional. - S_sfx[sfxnum].UserData.Resize(8); + S_sfx[sfxnum].UserData.Resize(2); int* udata = (int*)S_sfx[sfxnum].UserData.Data(); udata[0] = sfx->pitch; udata[1] = sfx->pitchRange; @@ -159,7 +159,7 @@ void sndStartSample(unsigned int nSound, int nVolume, int nChannel, bool bLoop) { if (nVolume < 0) { - auto udata = (int*)soundEngine->GetUserData(snd); + auto udata = soundEngine->GetUserData(snd); if (udata) nVolume = udata[2]; else nVolume = 255; } diff --git a/source/common/serializer.cpp b/source/common/serializer.cpp index 720b1e237..93ac3bca4 100644 --- a/source/common/serializer.cpp +++ b/source/common/serializer.cpp @@ -1479,7 +1479,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundI { #if 1 int id = sid; - Serialize(arc, key, sid, def); + Serialize(arc, key, id, nullptr); if (arc.isReading()) sid = FSoundID(id); #else if (arc.isWriting()) diff --git a/source/common/sound/backend/i_soundinternal.h b/source/common/sound/backend/i_soundinternal.h index 0e5730978..f5631b4f5 100644 --- a/source/common/sound/backend/i_soundinternal.h +++ b/source/common/sound/backend/i_soundinternal.h @@ -31,6 +31,7 @@ enum EChanFlag CHANF_NOSTOP = 4096, // only for A_PlaySound. Does not start if channel is playing something. CHANF_OVERLAP = 8192, // [MK] Does not stop any sounds in the channel and instead plays over them. CHANF_ENDED = 16384, // Helper to detect broken ChannelEnded implementations. + CHANF_TRANSIENT = 32768, // Do not record in savegames - used for sounds that get restarted outside the sound system (e.g. ambients in SW and Blood) }; typedef TFlags EChanFlags; diff --git a/source/common/sound/s_soundinternal.h b/source/common/sound/s_soundinternal.h index 30b73f139..7ca857b20 100644 --- a/source/common/sound/s_soundinternal.h +++ b/source/common/sound/s_soundinternal.h @@ -37,7 +37,7 @@ struct sfxinfo_t unsigned bSingular:1; unsigned bTentative:1; - TArray UserData; + TArray UserData; int RawRate; // Sample rate to use when bLoadRAW is true @@ -369,7 +369,7 @@ public: { S_rnd.Clear(); } - void *GetUserData(int snd) + int *GetUserData(int snd) { return S_sfx[snd].UserData.Data(); } diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index 255dd0dae..8ca14b3b4 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -100,11 +100,10 @@ void cacheAllSounds(void) static inline int S_GetPitch(int num) { - auto const* snd = (sound_t*)soundEngine->GetUserData(num + 1); + auto const* snd = soundEngine->GetUserData(num + 1); if (!snd) return 0; - int const range = abs(snd->pitchEnd - snd->pitchStart); - - return (range == 0) ? snd->pitchStart : min(snd->pitchStart, snd->pitchEnd) + rand() % range; + int const range = abs(snd[kPitchEnd] - snd[kPitchStart]); + return (range == 0) ? snd[kPitchStart] : min(snd[kPitchStart], snd[kPitchEnd]) + rand() % range; } float S_ConvertPitch(int lpitch) @@ -115,9 +114,9 @@ float S_ConvertPitch(int lpitch) int S_GetUserFlags(int num) { if (!soundEngine->isValidSoundId(num+1)) return 0; - auto const* snd = (sound_t*)soundEngine->GetUserData(num + 1); + auto const* snd = soundEngine->GetUserData(num + 1); if (!snd) return 0; - return snd->flags; + return snd[kFlags]; } //========================================================================== @@ -126,7 +125,7 @@ int S_GetUserFlags(int num) // //========================================================================== -int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpitch, int priority, int type, int distance, float volume) +int S_DefineSound(unsigned index, const char* filename, int minpitch, int maxpitch, int priority, int type, int distance, float volume) { if ((unsigned)index >= MAXSOUNDS) return -1; @@ -144,17 +143,17 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit } auto sfx = &S_sfx[index]; bool alreadydefined = !sfx->bTentative; - sfx->UserData.Resize(sizeof(sound_t)); - auto sndinf = (sound_t*)sfx->UserData.Data(); - sndinf->flags = type & ~SF_ONEINST_INTERNAL; - if (sndinf->flags & SF_LOOP) - sndinf->flags |= SF_ONEINST_INTERNAL; + sfx->UserData.Resize(kMaxUserData); + auto sndinf = sfx->UserData.Data(); + sndinf[kFlags] = type & ~SF_ONEINST_INTERNAL; + if (sndinf[kFlags] & SF_LOOP) + sndinf[kFlags] |= SF_ONEINST_INTERNAL; sfx->lumpnum = S_LookupSound(filename); - sndinf->pitchStart = clamp(minpitch, INT16_MIN, INT16_MAX); - sndinf->pitchEnd = clamp(maxpitch, INT16_MIN, INT16_MAX); - sndinf->priority = priority & 255; - sndinf->volAdjust = clamp(distance, INT16_MIN, INT16_MAX); + sndinf[kPitchStart] = clamp(minpitch, INT16_MIN, INT16_MAX); + sndinf[kPitchEnd] = clamp(maxpitch, INT16_MIN, INT16_MAX); + sndinf[kPriority] = priority & 255; + sndinf[kVolAdjust] = clamp(distance, INT16_MIN, INT16_MAX); sfx->Volume = volume; sfx->NearLimit = 6; sfx->bTentative = false; @@ -176,9 +175,9 @@ static int S_CalcDistAndAng(int spriteNum, int soundNum, int sectNum, // However, ultimately rolloff would also just reposition the sound source so this can remain as it is. int orgsndist = 0, sndang = 0, sndist = 0, explosion = 0; - auto const* snd = (sound_t*)soundEngine->GetUserData(soundNum+1); - int userflags = snd? snd->flags : 0; - int dist_adjust = snd? snd->volAdjust : 0; + auto const* snd = soundEngine->GetUserData(soundNum+1); + int userflags = snd? snd[kFlags] : 0; + int dist_adjust = snd? snd[kVolAdjust] : 0; if (PN(spriteNum) != APLAYER || P_Get(spriteNum) != screenpeek) { diff --git a/source/duke3d/src/sounds.h b/source/duke3d/src/sounds.h index db0ec6e08..54c336e32 100644 --- a/source/duke3d/src/sounds.h +++ b/source/duke3d/src/sounds.h @@ -39,11 +39,15 @@ BEGIN_DUKE_NS #define MAXSOUNDS 4096 #define LOUDESTVOLUME 111 -typedef struct +enum esound_t { - int pitchStart, pitchEnd, volAdjust; - int priority, flags; -} sound_t; + kPitchStart, + kPitchEnd, + kVolAdjust, + kPriority, + kFlags, + kMaxUserData +}; int A_CheckSoundPlaying(int spriteNum, int soundNum, int channel = 0); int A_PlaySound(int soundNum, int spriteNum, int channel = CHAN_AUTO, EChanFlags flags = 0); diff --git a/source/rr/src/sounds.cpp b/source/rr/src/sounds.cpp index 34cab3d4c..a9c0a2444 100644 --- a/source/rr/src/sounds.cpp +++ b/source/rr/src/sounds.cpp @@ -99,11 +99,10 @@ void cacheAllSounds(void) static inline int S_GetPitch(int num) { - auto const* snd = (sound_t*)soundEngine->GetUserData(num+1); + auto const* snd = soundEngine->GetUserData(num+1); if (!snd) return 0; - int const range = abs(snd->pitchEnd - snd->pitchStart); - - return (range == 0) ? snd->pitchStart : min(snd->pitchStart, snd->pitchEnd) + rand() % range; + int const range = abs(snd[kPitchEnd] - snd[kPitchStart]); + return (range == 0) ? snd[kPitchStart] : min(snd[kPitchStart], snd[kPitchEnd]) + rand() % range; } float S_ConvertPitch(int lpitch) @@ -114,9 +113,9 @@ float S_ConvertPitch(int lpitch) int S_GetUserFlags(int num) { if (!soundEngine->isValidSoundId(num+1)) return 0; - auto const* snd = (sound_t*)soundEngine->GetUserData(num + 1); + auto const* snd = soundEngine->GetUserData(num + 1); if (!snd) return 0; - return snd->flags; + return snd[kFlags]; } //========================================================================== @@ -143,17 +142,17 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit } auto sfx = &S_sfx[index]; bool alreadydefined = !sfx->bTentative; - sfx->UserData.Resize(sizeof(sound_t)); - auto sndinf = (sound_t*)sfx->UserData.Data(); - sndinf->flags = type & ~SF_ONEINST_INTERNAL; - if (sndinf->flags & SF_LOOP) - sndinf->flags |= SF_ONEINST_INTERNAL; + sfx->UserData.Resize(kMaxUserData); + auto sndinf = sfx->UserData.Data(); + sndinf[kFlags] = type & ~SF_ONEINST_INTERNAL; + if (sndinf[kFlags] & SF_LOOP) + sndinf[kFlags] |= SF_ONEINST_INTERNAL; sfx->lumpnum = S_LookupSound(filename); - sndinf->pitchStart = clamp(minpitch, INT16_MIN, INT16_MAX); - sndinf->pitchEnd = clamp(maxpitch, INT16_MIN, INT16_MAX); - sndinf->priority = priority & 255; - sndinf->volAdjust = clamp(distance, INT16_MIN, INT16_MAX); + sndinf[kPitchStart] = clamp(minpitch, INT16_MIN, INT16_MAX); + sndinf[kPitchEnd] = clamp(maxpitch, INT16_MIN, INT16_MAX); + sndinf[kPriority] = priority & 255; + sndinf[kVolAdjust] = clamp(distance, INT16_MIN, INT16_MAX); sfx->Volume = volume; sfx->NearLimit = 6; sfx->bTentative = false; @@ -175,9 +174,9 @@ static int S_CalcDistAndAng(int spriteNum, int soundNum, int sectNum, // However, ultimately rolloff would also just reposition the sound source so this can remain as it is. int orgsndist = 0, sndang = 0, sndist = 0, explosion = 0; - auto const* snd = (sound_t*)soundEngine->GetUserData(soundNum + 1); - int userflags = snd ? snd->flags : 0; - int dist_adjust = snd ? snd->volAdjust : 0; + auto const* snd = soundEngine->GetUserData(soundNum + 1); + int userflags = snd ? snd[kFlags] : 0; + int dist_adjust = snd ? snd[kVolAdjust] : 0; if (PN(spriteNum) != APLAYER || P_Get(spriteNum) != screenpeek) { diff --git a/source/rr/src/sounds.h b/source/rr/src/sounds.h index 9f39702f3..719ae0beb 100644 --- a/source/rr/src/sounds.h +++ b/source/rr/src/sounds.h @@ -39,11 +39,15 @@ BEGIN_RR_NS #define MAXSOUNDS 4096 #define LOUDESTVOLUME 111 -typedef struct +enum esound_t { - int pitchStart, pitchEnd, volAdjust; - int priority, flags; -} sound_t; + kPitchStart, + kPitchEnd, + kVolAdjust, + kPriority, + kFlags, + kMaxUserData +}; int A_CheckSoundPlaying(int spriteNum, int soundNum, int channel = 0); int A_PlaySound(int soundNum, int spriteNum, int channel = CHAN_AUTO, EChanFlags flags = 0);