Skip to content

Commit

Permalink
Disable audio virtualization on special audio sources such as music a…
Browse files Browse the repository at this point in the history
…nd ambient sounds

This prevents the music from being muffled by HRTF virtualization
  • Loading branch information
smallmodel committed Jan 1, 2025
1 parent a067c58 commit 869075f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
47 changes: 43 additions & 4 deletions code/client/snd_openal_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,17 @@ qboolean S_OPENAL_Init()
return false;
}

//
// Disable sound virtualization on special channels
// (triggered music, ambient sounds...)
//
for (i = 0; i < MAX_SOUNDSYSTEM_SONGS; i++) {
openal.chan_song[i].set_no_virtualization();
}
openal.chan_mp3.set_no_virtualization();
openal.chan_trig_music.set_no_virtualization();
openal.chan_movie.set_no_virtualization();

Cmd_AddCommand("playmp3", S_OPENAL_PlayMP3);
Cmd_AddCommand("stopmp3", S_OPENAL_StopMP3);
Cmd_AddCommand("loadsoundtrack", S_loadsoundtrack);
Expand Down Expand Up @@ -1366,16 +1377,15 @@ static void S_OPENAL_Start2DSound(
pChannel->iBaseRate = pChannel->sample_playback_rate();
pChannel->set_no_3d();
fRealVolume = fRealVolume * s_fVolumeGain;
pChannel->set_gain(fRealVolume);
pChannel->play();
} else {
pChannel->stop();
pChannel->set_no_3d();
pChannel->set_sfx(pSfx);
pChannel->set_gain(fRealVolume);
pChannel->play();
}

pChannel->set_gain(fRealVolume);
pChannel->play();

if (s_show_sounds->integer > 0) {
Com_DPrintf(
"OpenAL: 2D - %d (#%i) - %s (vol %f, mindist %f, maxdist %f)\n",
Expand Down Expand Up @@ -2912,6 +2922,35 @@ void openal_channel::play()
alDieIfError();
}

/*
==============
openal_channel::set_no_virtualization
==============
*/
void openal_channel::set_no_virtualization()
{
#if AL_SOFT_direct_channels_remix
qalSourcei(source, AL_DIRECT_CHANNELS_SOFT, AL_REMIX_UNMATCHED_SOFT);
alDieIfError();
#elif AL_SOFT_direct_channels
qalSourcei(source, AL_DIRECT_CHANNELS_SOFT, AL_TRUE);
alDieIfError();
#endif
}

/*
==============
openal_channel::set_virtualization
==============
*/
void openal_channel::set_virtualization()
{
#if AL_SOFT_direct_channels_remix || AL_SOFT_direct_channels
qalSourcei(source, AL_DIRECT_CHANNELS_SOFT, AL_FALSE);
alDieIfError();
#endif
}

/*
==============
openal_channel::pause
Expand Down
2 changes: 2 additions & 0 deletions code/client/snd_openal_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct openal_channel {

void set_no_3d();
void set_3d();
void set_no_virtualization();
void set_virtualization();

void set_gain(float gain);
void set_velocity(float v0, float v1, float v2);
Expand Down

0 comments on commit 869075f

Please sign in to comment.