Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions inc/client/sound/dma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,4 @@ typedef struct {
} snddma_driver_t;

extern dma_t dma;
extern int s_paintedtime;

extern cvar_t *s_khz;
65 changes: 65 additions & 0 deletions src/client/sound/SoundSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,71 @@ void SoundSystem::increment_registration_sequence()
++registration_sequence_;
}

SoundBackend SoundSystem::backend() const
{
return backend_;
}

void SoundSystem::set_backend(SoundBackend backend)
{
backend_ = backend;
}

const sndapi_t *SoundSystem::api() const
{
return api_;
}

void SoundSystem::set_api(const sndapi_t *api)
{
api_ = api;
}

bool SoundSystem::supports_float() const
{
return supports_float_;
}

void SoundSystem::set_supports_float(bool supports)
{
supports_float_ = supports;
}

bool SoundSystem::is_active() const
{
return active_;
}

void SoundSystem::set_active(bool active)
{
active_ = active;
}

bool SoundSystem::is_registering() const
{
return registering_;
}

void SoundSystem::set_registering(bool registering)
{
registering_ = registering;
}

int SoundSystem::painted_time() const
{
return painted_time_;
}

int &SoundSystem::painted_time()
{
return painted_time_;
}

void SoundSystem::set_painted_time(int time)
{
painted_time_ = time;
}

sfx_t *SoundSystem::known_sfx_data()
{
return known_sfx_.data();
Expand Down
25 changes: 25 additions & 0 deletions src/client/sound/SoundSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ class SoundSystem {
void reset_registration_sequence();
void increment_registration_sequence();

SoundBackend backend() const;
void set_backend(SoundBackend backend);

const sndapi_t *api() const;
void set_api(const sndapi_t *api);

bool supports_float() const;
void set_supports_float(bool supports);

bool is_active() const;
void set_active(bool active);

bool is_registering() const;
void set_registering(bool registering);

sfx_t *known_sfx_data();
const sfx_t *known_sfx_data() const;
int num_sfx() const;
Expand Down Expand Up @@ -60,6 +75,10 @@ class SoundSystem {
void StopAllSounds();
void Update();

int painted_time() const;
int &painted_time();
void set_painted_time(int time);

vec3_t &listener_origin();
vec3_t &listener_forward();
vec3_t &listener_right();
Expand All @@ -71,6 +90,12 @@ class SoundSystem {

Config config_{};
unsigned registration_sequence_ = 1;
SoundBackend backend_ = SoundBackend::Not;
const sndapi_t *api_ = nullptr;
bool supports_float_ = false;
bool active_ = false;
bool registering_ = false;
int painted_time_ = 0;
std::vector<sfx_t> known_sfx_;
int num_sfx_ = 0;
std::vector<channel_t> channels_;
Expand Down
56 changes: 29 additions & 27 deletions src/client/sound/al.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ static bool AL_Init(void)

s_loop_points = qalIsExtensionPresent("AL_SOFT_loop_points");
s_source_spatialize = qalIsExtensionPresent("AL_SOFT_source_spatialize");
s_supports_float = qalIsExtensionPresent("AL_EXT_float32");
soundSystem.set_supports_float(qalIsExtensionPresent("AL_EXT_float32"));

// init distance model
qalDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
Expand Down Expand Up @@ -765,7 +765,7 @@ static ALenum AL_GetSampleFormat(int width, int channels)
case 2:
return AL_FORMAT_MONO16 + (channels - 1) * 2;
case 4:
if (!s_supports_float)
if (!S_GetSoundSystem().supports_float())
return 0;
return AL_FORMAT_MONO_FLOAT32 + (channels - 1);
default:
Expand Down Expand Up @@ -832,7 +832,7 @@ static void AL_DeleteSfx(sfx_t *s)

static int AL_GetBeginofs(float timeofs)
{
return s_paintedtime + timeofs * 1000;
return S_GetSoundSystem().painted_time() + timeofs * 1000;
}

static void AL_Spatialize(channel_t *ch)
Expand Down Expand Up @@ -957,7 +957,7 @@ static void AL_IssuePlaysounds(void)
playsound_t *ps = soundSystem.PeekPendingPlay();
if (!ps)
break; // no more pending sounds
if (ps->begin > s_paintedtime)
if (ps->begin > soundSystem.painted_time())
break;
S_GetSoundSystem().IssuePlaysound(ps);
}
Expand Down Expand Up @@ -1012,6 +1012,7 @@ static void AL_MergeLoopSounds(void)
sfxcache_t *sc;
int num;
entity_state_t *ent;
SoundSystem &soundSystem = S_GetSoundSystem();
vec3_t origin;

if (!S_GetSoundSystem().BuildSoundList(sounds))
Expand All @@ -1021,7 +1022,7 @@ static void AL_MergeLoopSounds(void)
if (!sounds[i])
continue;

sfx = S_GetSoundSystem().SfxForHandle(cl.sound_precache[sounds[i]]);
sfx = soundSystem.SfxForHandle(cl.sound_precache[sounds[i]]);
if (!sfx)
continue; // bad sound effect
sc = sfx->cache;
Expand All @@ -1042,9 +1043,9 @@ static void AL_MergeLoopSounds(void)
VectorSubtract(origin, offset, base);
CL_DebugTrail(base, origin);
}
S_GetSoundSystem().SpatializeOrigin(origin, vol, att,
&left_total, &right_total,
S_GetEntityLoopStereoPan(ent));
soundSystem.SpatializeOrigin(origin, vol, att,
&left_total, &right_total,
S_GetEntityLoopStereoPan(ent));
for (j = i + 1; j < cl.frame.numEntities; j++) {
if (sounds[j] != sounds[i])
continue;
Expand All @@ -1059,11 +1060,11 @@ static void AL_MergeLoopSounds(void)
VectorSubtract(origin, offset, base);
CL_DebugTrail(base, origin);
}
S_GetSoundSystem().SpatializeOrigin(origin,
S_GetEntityLoopVolume(ent),
S_GetEntityLoopDistMult(ent),
&left, &right,
S_GetEntityLoopStereoPan(ent));
soundSystem.SpatializeOrigin(origin,
S_GetEntityLoopVolume(ent),
S_GetEntityLoopDistMult(ent),
&left, &right,
S_GetEntityLoopStereoPan(ent));
left_total += left;
right_total += right;
}
Expand All @@ -1084,16 +1085,16 @@ static void AL_MergeLoopSounds(void)
qalSourcef(ch->srcnum, AL_GAIN, gain);
qalSource3f(ch->srcnum, AL_POSITION, pan, 0.0f, pan2);
ch->autoframe = s_framecount;
ch->end = s_paintedtime + sc->length;
ch->end = soundSystem.painted_time() + sc->length;
continue;
}

// allocate a channel
ch = S_GetSoundSystem().PickChannel(0, 0);
ch = soundSystem.PickChannel(0, 0);
if (!ch)
continue;

channel_t *channels = S_GetSoundSystem().channels_data();
channel_t *channels = soundSystem.channels_data();
if (channels) {
ch->srcnum = s_srcnums[ch - channels];
} else {
Expand All @@ -1116,7 +1117,7 @@ static void AL_MergeLoopSounds(void)
ch->entnum = ent->number;
ch->master_vol = vol;
ch->dist_mult = att;
ch->end = s_paintedtime + sc->length;
ch->end = soundSystem.painted_time() + sc->length;

// play it
qalSourcePlay(ch->srcnum);
Expand All @@ -1139,13 +1140,13 @@ static void AL_AddLoopSounds(void)
if (cls.state != ca_active || sv_paused->integer || !s_ambient->integer)
return;

S_GetSoundSystem().BuildSoundList(sounds);
soundSystem.BuildSoundList(sounds);

Comment on lines +1148 to 1149

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Declare soundSystem inside AL_AddLoopSounds

The new OpenAL helper AL_AddLoopSounds now calls soundSystem.BuildSoundList and soundSystem.SfxForHandle, but the function never defines a soundSystem reference or variable in its scope. There is no file‑scope soundSystem either, so this code will not compile (soundSystem is undefined). Add SoundSystem &soundSystem = S_GetSoundSystem(); at the start of this function before using it.

Useful? React with 👍 / 👎.

for (i = 0; i < cl.frame.numEntities; i++) {
if (!sounds[i])
continue;

sfx = S_GetSoundSystem().SfxForHandle(cl.sound_precache[sounds[i]]);
sfx = soundSystem.SfxForHandle(cl.sound_precache[sounds[i]]);
if (!sfx)
continue; // bad sound effect
sc = sfx->cache;
Expand All @@ -1158,12 +1159,12 @@ static void AL_AddLoopSounds(void)
ch = AL_FindLoopingSound(ent->number, sfx);
if (ch) {
ch->autoframe = s_framecount;
ch->end = s_paintedtime + sc->length;
ch->end = soundSystem.painted_time() + sc->length;
continue;
}

// allocate a channel
ch = S_GetSoundSystem().PickChannel(0, 0);
ch = soundSystem.PickChannel(0, 0);
if (!ch)
continue;

Expand All @@ -1173,7 +1174,7 @@ static void AL_AddLoopSounds(void)
ch->entnum = ent->number;
ch->master_vol = S_GetEntityLoopVolume(ent);
ch->dist_mult = S_GetEntityLoopDistMult(ent);
ch->end = s_paintedtime + sc->length;
ch->end = soundSystem.painted_time() + sc->length;

AL_PlayChannel(ch);
}
Expand Down Expand Up @@ -1212,7 +1213,7 @@ static void AL_StreamPause(bool paused)
s_stream_paused = paused;

// force pause if not active
if (!s_active)
if (!S_GetSoundSystem().is_active())
paused = true;

ALint state = 0;
Expand Down Expand Up @@ -1311,14 +1312,15 @@ static void AL_Update(void)
channel_t *channels = soundSystem.channels_data();
int num_channels = soundSystem.num_channels();

if (!s_active)
if (!soundSystem.is_active())
return;

// handle time wraparound. FIXME: get rid of this?
i = cls.realtime & MASK(30);
if (i < s_paintedtime)
S_GetSoundSystem().StopAllSounds();
s_paintedtime = i;
int &painted_time = soundSystem.painted_time();
if (i < painted_time)
soundSystem.StopAllSounds();
painted_time = i;

// set listener parameters
qalListener3f(AL_POSITION, AL_UnpackVector(listener_origin));
Expand Down
Loading