Skip to content

Commit

Permalink
- continued refactoring on sound code.
Browse files Browse the repository at this point in the history
The game independent part of the code has been mostly isolated.
  • Loading branch information
coelckers committed Dec 8, 2019
1 parent fd181f4 commit b9582cc
Show file tree
Hide file tree
Showing 22 changed files with 1,524 additions and 1,310 deletions.
4 changes: 1 addition & 3 deletions src/console/c_dispatch.h
Expand Up @@ -208,9 +208,7 @@ extern bool ParsingKeyConf, UnsafeExecutionContext;
void ResetButtonTriggers (); // Call ResetTriggers for all buttons
void ResetButtonStates (); // Same as above, but also clear bDown

extern unsigned int MakeKey (const char *s);
extern unsigned int MakeKey (const char *s, size_t len);
extern unsigned int SuperFastHash (const char *data, size_t len);
#include "superfasthash.h"

void execLogfile(const char *fn, bool append = false);

Expand Down
2 changes: 1 addition & 1 deletion src/playsim/fragglescript/t_func.cpp
Expand Up @@ -364,7 +364,7 @@ static FSoundID T_FindSound(const char * name)
}

int id = S_AddSound(name, buffer);
S_HashSounds();
soundEngine->HashSounds();
return FSoundID(id);
}

Expand Down
22 changes: 11 additions & 11 deletions src/playsim/p_acs.cpp
Expand Up @@ -4387,11 +4387,11 @@ int DLevelScript::GetActorProperty (int tid, int property)
return 0;
}

case APROP_SeeSound: return GlobalACSStrings.AddString(actor->SeeSound);
case APROP_AttackSound: return GlobalACSStrings.AddString(actor->AttackSound);
case APROP_PainSound: return GlobalACSStrings.AddString(actor->PainSound);
case APROP_DeathSound: return GlobalACSStrings.AddString(actor->DeathSound);
case APROP_ActiveSound: return GlobalACSStrings.AddString(actor->ActiveSound);
case APROP_SeeSound: return GlobalACSStrings.AddString(S_GetSoundName(actor->SeeSound));
case APROP_AttackSound: return GlobalACSStrings.AddString(S_GetSoundName(actor->AttackSound));
case APROP_PainSound: return GlobalACSStrings.AddString(S_GetSoundName(actor->PainSound));
case APROP_DeathSound: return GlobalACSStrings.AddString(S_GetSoundName(actor->DeathSound));
case APROP_ActiveSound: return GlobalACSStrings.AddString(S_GetSoundName(actor->ActiveSound));
case APROP_Species: return GlobalACSStrings.AddString(actor->GetSpecies());
case APROP_NameTag: return GlobalACSStrings.AddString(actor->GetTag());
case APROP_StencilColor:return actor->fillcolor;
Expand Down Expand Up @@ -4464,11 +4464,11 @@ int DLevelScript::CheckActorProperty (int tid, int property, int value)

// Strings are covered by GetActorProperty, but they're fairly
// heavy-duty, so make the check here.
case APROP_SeeSound: string = actor->SeeSound; break;
case APROP_AttackSound: string = actor->AttackSound; break;
case APROP_PainSound: string = actor->PainSound; break;
case APROP_DeathSound: string = actor->DeathSound; break;
case APROP_ActiveSound: string = actor->ActiveSound; break;
case APROP_SeeSound: string = S_GetSoundName(actor->SeeSound); break;
case APROP_AttackSound: string = S_GetSoundName(actor->AttackSound); break;
case APROP_PainSound: string = S_GetSoundName(actor->PainSound); break;
case APROP_DeathSound: string = S_GetSoundName(actor->DeathSound); break;
case APROP_ActiveSound: string = S_GetSoundName(actor->ActiveSound); break;
case APROP_Species: string = actor->GetSpecies(); break;
case APROP_NameTag: string = actor->GetTag(); break;
case APROP_DamageType: string = actor->DamageType; break;
Expand Down Expand Up @@ -5265,7 +5265,7 @@ int DLevelScript::SwapActorTeleFog(AActor *activator, int tid)
}
else if (rettype == TypeSound)
{
retval = GlobalACSStrings.AddString(FSoundID(retval));
retval = GlobalACSStrings.AddString(S_GetSoundName(FSoundID(retval)));
}
}
else if (rettype == TypeFloat64)
Expand Down
4 changes: 2 additions & 2 deletions src/r_data/sprites.cpp
Expand Up @@ -731,7 +731,7 @@ void R_InitSkins (void)
}
else
{
int sndref = S_FindSoundNoHash (key);
int sndref = soundEngine->FindSoundNoHash (key);
if (sndref != 0)
{
S_AddPlayerSound (Skins[i].Name, Skins[i].gender, sndref, lump, true);
Expand Down Expand Up @@ -911,7 +911,7 @@ void R_InitSkins (void)

if (Skins.Size() > PlayerClasses.Size ())
{ // The sound table may have changed, so rehash it.
S_HashSounds ();
soundEngine->HashSounds ();
S_ShrinkPlayerSoundLists ();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/backend/codegen.cpp
Expand Up @@ -1243,7 +1243,7 @@ FxExpression *FxStringCast::Resolve(FCompileContext &ctx)
if (basex->isConstant())
{
ExpVal constval = static_cast<FxConstant *>(basex)->GetValue();
FxExpression *x = new FxConstant(S_sfx[constval.GetInt()].name, ScriptPosition);
FxExpression *x = new FxConstant(S_GetSoundName(constval.GetInt()), ScriptPosition);
delete this;
return x;
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/types.cpp
Expand Up @@ -1184,7 +1184,7 @@ PSound::PSound()

void PSound::WriteValue(FSerializer &ar, const char *key,const void *addr) const
{
const char *cptr = *(const FSoundID *)addr;
const char *cptr = S_GetSoundName(*(const FSoundID *)addr);
ar.StringPtr(key, cptr);
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripting/vm/jit_move.cpp
Expand Up @@ -51,7 +51,7 @@ static void CastN2S(FString *a, int b) { FName name = FName(ENamedName(b)); *a =
static int CastS2Co(FString *b) { return V_GetColor(nullptr, *b); }
static void CastCo2S(FString *a, int b) { PalEntry c(b); a->Format("%02x %02x %02x", c.r, c.g, c.b); }
static int CastS2So(FString *b) { return FSoundID(*b); }
static void CastSo2S(FString *a, int b) { *a = S_sfx[b].name; }
static void CastSo2S(FString* a, int b) { *a = S_GetSoundName(b); }
static void CastSID2S(FString *a, unsigned int b) { *a = (b >= sprites.Size()) ? "TNT1" : sprites[b].name; }
static void CastTID2S(FString *a, int b) { auto tex = TexMan.GetTexture(*(FTextureID*)&b); *a = (tex == nullptr) ? "(null)" : tex->GetName().GetChars(); }

Expand Down
2 changes: 1 addition & 1 deletion src/scripting/vm/vmexec.h
Expand Up @@ -1837,7 +1837,7 @@ static void DoCast(const VMRegisters &reg, const VMFrame *f, int a, int b, int c

case CAST_So2S:
ASSERTS(a); ASSERTD(b);
reg.s[a] = S_sfx[reg.d[b]].name;
reg.s[a] = S_GetSoundName(reg.d[b]);
break;

case CAST_SID2S:
Expand Down
2 changes: 1 addition & 1 deletion src/serializer.cpp
Expand Up @@ -1663,7 +1663,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundI
if (!arc.w->inObject() || def == nullptr || sid != *def)
{
arc.WriteKey(key);
const char *sn = (const char*)sid;
const char *sn = S_GetSoundName(sid);
if (sn != nullptr) arc.w->String(sn);
else arc.w->Null();
}
Expand Down
7 changes: 3 additions & 4 deletions src/sound/backend/i_sound.cpp
Expand Up @@ -35,8 +35,6 @@
#include <stdio.h>
#include <stdlib.h>

#include "doomtype.h"

#include "oalsound.h"

#include "i_module.h"
Expand All @@ -52,6 +50,7 @@
#include "s_music.h"
#include "zmusic/zmusic.h"


EXTERN_CVAR (Float, snd_sfxvolume)
EXTERN_CVAR (Float, snd_musicvolume)
CVAR (Int, snd_samplerate, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
Expand Down Expand Up @@ -300,8 +299,8 @@ void I_InitSound ()

void I_CloseSound ()
{
// Free all loaded samples
S_UnloadAllSounds();
// Free all loaded samples. Beware that the sound engine may already have been deleted.
if (soundEngine) soundEngine->UnloadAllSounds();

delete GSnd;
GSnd = NULL;
Expand Down
6 changes: 1 addition & 5 deletions src/sound/backend/i_sound.h
Expand Up @@ -174,11 +174,7 @@ extern bool nosfx;
extern bool nosound;

void I_InitSound ();

void S_ChannelEnded(FISoundChannel *schan);
void S_ChannelVirtualChanged(FISoundChannel *schan, bool is_virtual);
float S_GetRolloff(FRolloffInfo *rolloff, float distance, bool logarithmic);
FISoundChannel *S_GetChannel(void *syschan);
void I_CloseSound();

extern ReverbContainer *DefaultEnvironments[26];

Expand Down
1 change: 1 addition & 0 deletions src/sound/backend/i_soundinternal.h
Expand Up @@ -122,4 +122,5 @@ class SoundStream;




#endif
41 changes: 13 additions & 28 deletions src/sound/backend/oalsound.cpp
Expand Up @@ -544,22 +544,7 @@ static size_t GetChannelCount(ChannelConfig chans)

static float GetRolloff(const FRolloffInfo *rolloff, float distance)
{
if(distance <= rolloff->MinDistance)
return 1.f;
// Logarithmic rolloff has no max distance where it goes silent.
if(rolloff->RolloffType == ROLLOFF_Log)
return rolloff->MinDistance /
(rolloff->MinDistance + rolloff->RolloffFactor*(distance-rolloff->MinDistance));
if(distance >= rolloff->MaxDistance)
return 0.f;

float volume = (rolloff->MaxDistance - distance) / (rolloff->MaxDistance - rolloff->MinDistance);
if(rolloff->RolloffType == ROLLOFF_Linear)
return volume;

if(rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve.Size() > 0)
return S_SoundCurve[int(S_SoundCurve.Size() * (1.f - volume))] / 127.f;
return (powf(10.f, volume) - 1.f) / 9.f;
return soundEngine->GetRolloff(rolloff, distance);
}

ALCdevice *OpenALSoundRenderer::InitDevice()
Expand Down Expand Up @@ -983,7 +968,7 @@ void OpenALSoundRenderer::SetSfxVolume(float volume)
{
SfxVolume = volume;

FSoundChan *schan = Channels;
FSoundChan *schan = soundEngine->GetChannels();
while(schan)
{
if(schan->SysChannel != NULL)
Expand Down Expand Up @@ -1359,7 +1344,7 @@ void OpenALSoundRenderer::UnloadSound(SoundHandle sfx)
return;

ALuint buffer = GET_PTRID(sfx.data);
FSoundChan *schan = Channels;
FSoundChan *schan = soundEngine->GetChannels();
while(schan)
{
if(schan->SysChannel)
Expand Down Expand Up @@ -1495,7 +1480,7 @@ FISoundChannel *OpenALSoundRenderer::StartSound(SoundHandle sfx, float vol, int
FreeSfx.Pop();

FISoundChannel *chan = reuse_chan;
if(!chan) chan = S_GetChannel(MAKE_PTRID(source));
if(!chan) chan = soundEngine->GetChannel(MAKE_PTRID(source));
else chan->SysChannel = MAKE_PTRID(source);

chan->Rolloff.RolloffType = ROLLOFF_Log;
Expand Down Expand Up @@ -1706,7 +1691,7 @@ FISoundChannel *OpenALSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener
FreeSfx.Pop();

FISoundChannel *chan = reuse_chan;
if(!chan) chan = S_GetChannel(MAKE_PTRID(source));
if(!chan) chan = soundEngine->GetChannel(MAKE_PTRID(source));
else chan->SysChannel = MAKE_PTRID(source);

chan->Rolloff = *rolloff;
Expand Down Expand Up @@ -1765,7 +1750,7 @@ void OpenALSoundRenderer::StopChannel(FISoundChannel *chan)

ALuint source = GET_PTRID(chan->SysChannel);
// Release first, so it can be properly marked as evicted if it's being killed
S_ChannelEnded(chan);
soundEngine->ChannelEnded(chan);

ALint state = AL_INITIAL;
alGetSourcei(source, AL_SOURCE_STATE, &state);
Expand All @@ -1789,7 +1774,7 @@ void OpenALSoundRenderer::ForceStopChannel(FISoundChannel *chan)
ALuint source = GET_PTRID(chan->SysChannel);
if(!source) return;

S_ChannelEnded(chan);
soundEngine->ChannelEnded(chan);
FreeSource(source);
}

Expand Down Expand Up @@ -2009,7 +1994,7 @@ void OpenALSoundRenderer::UpdateListener(SoundListener *listener)
alFilterf(EnvFilters[1], AL_LOWPASS_GAINHF, 1.f);

// Apply the updated filters on the sources
FSoundChan *schan = Channels;
FSoundChan *schan = soundEngine->GetChannels();
while (schan)
{
ALuint source = GET_PTRID(schan->SysChannel);
Expand All @@ -2022,7 +2007,7 @@ void OpenALSoundRenderer::UpdateListener(SoundListener *listener)
}
}

FSoundChan *schan = Channels;
FSoundChan *schan = soundEngine->GetChannels();
while (schan)
{
ALuint source = GET_PTRID(schan->SysChannel);
Expand All @@ -2047,7 +2032,7 @@ void OpenALSoundRenderer::UpdateListener(SoundListener *listener)
alFilterf(EnvFilters[1], AL_LOWPASS_GAIN, 1.f);
alFilterf(EnvFilters[1], AL_LOWPASS_GAINHF, 1.f);

FSoundChan *schan = Channels;
FSoundChan *schan = soundEngine->GetChannels();
while (schan)
{
ALuint source = GET_PTRID(schan->SysChannel);
Expand All @@ -2060,7 +2045,7 @@ void OpenALSoundRenderer::UpdateListener(SoundListener *listener)
}
}

FSoundChan *schan = Channels;
FSoundChan *schan = soundEngine->GetChannels();
while (schan)
{
ALuint source = GET_PTRID(schan->SysChannel);
Expand Down Expand Up @@ -2236,7 +2221,7 @@ void OpenALSoundRenderer::PurgeStoppedSources()
if(state == AL_INITIAL || state == AL_PLAYING || state == AL_PAUSED)
continue;

FSoundChan *schan = Channels;
FSoundChan *schan = soundEngine->GetChannels();
while(schan)
{
if(schan->SysChannel != NULL && src == GET_PTRID(schan->SysChannel))
Expand Down Expand Up @@ -2358,7 +2343,7 @@ void OpenALSoundRenderer::LoadReverb(const ReverbContainer *env)

FSoundChan *OpenALSoundRenderer::FindLowestChannel()
{
FSoundChan *schan = Channels;
FSoundChan *schan = soundEngine->GetChannels();
FSoundChan *lowest = NULL;
while(schan)
{
Expand Down

0 comments on commit b9582cc

Please sign in to comment.