set resampler for sfx channels, remove alsoft config (#995)

* report used resampler in I_InitSound()

* set resampler for sfx channels, remove `alsoft` config

---------

Co-authored-by: Roman Fomin <rfomin@gmail.com>
This commit is contained in:
Fabian Greffrath 2023-04-18 14:50:37 +02:00 committed by GitHub
parent aa17f83ac0
commit 7490f90b0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 6 deletions

View File

@ -85,7 +85,6 @@ configure_file(config.h.in config.h)
if(WIN32)
install(FILES COPYING DESTINATION .)
install(FILES README.md DESTINATION .)
install(FILES data/alsoft DESTINATION . RENAME alsoft.ini)
install(DIRECTORY docs/ DESTINATION docs)
install(DIRECTORY examples/ DESTINATION docs/examples)
install(DIRECTORY autoload/ DESTINATION autoload)
@ -95,7 +94,6 @@ if(WIN32)
else()
install(FILES COPYING DESTINATION "share/doc/${PROJECT_SHORTNAME}")
install(FILES README.md DESTINATION "share/doc/${PROJECT_SHORTNAME}")
install(FILES data/alsoft DESTINATION "share/${PROJECT_SHORTNAME}" RENAME alsoft.conf)
install(DIRECTORY autoload/ DESTINATION "share/${PROJECT_SHORTNAME}/autoload")
if(EXISTS "${CMAKE_SOURCE_DIR}/docs")
install(DIRECTORY docs/ DESTINATION "share/doc/${PROJECT_SHORTNAME}")

View File

@ -1,3 +0,0 @@
# OpenAL configuration. More options at
# https://github.com/kcat/openal-soft/blob/master/alsoftrc.sample
resampler = linear

View File

@ -34,4 +34,4 @@ typedef uint32_t (*callback_func_t)(byte *buffer, uint32_t buffer_samples);
void I_OAL_HookMusic(callback_func_t callback_func);
void I_OAL_SetGain(float gain);
#endif
#endif

View File

@ -22,6 +22,7 @@
#include "al.h"
#include "alc.h"
#include "alext.h"
#include "doomstat.h"
#include "i_sndfile.h"
@ -521,6 +522,69 @@ void I_ShutdownSound(void)
snd_init = false;
}
// C doesn't allow casting between function and non-function pointer types, so
// with C99 we need to use a union to reinterpret the pointer type. Pre-C99
// still needs to use a normal cast and live with the warning (C++ is fine with
// a regular reinterpret_cast).
#if __STDC_VERSION__ >= 199901L
#define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f
#else
#define FUNCTION_CAST(T, ptr) (T)(ptr)
#endif
char *snd_resampler;
static void SetResampler(void)
{
LPALGETSTRINGISOFT alGetStringiSOFT = NULL;
ALint i, num_resamplers, def_resampler;
if (!alIsExtensionPresent("AL_SOFT_source_resampler"))
{
printf(" Resampler info not available!\n");
return;
}
alGetStringiSOFT = FUNCTION_CAST(LPALGETSTRINGISOFT, alGetProcAddress("alGetStringiSOFT"));
if (!alGetStringiSOFT)
{
fprintf(stderr, "I_SetResampler: alGetStringiSOFT() is not avaible.\n");
return;
}
num_resamplers = alGetInteger(AL_NUM_RESAMPLERS_SOFT);
def_resampler = alGetInteger(AL_DEFAULT_RESAMPLER_SOFT);
if (!num_resamplers)
{
printf(" No resamplers found!\n");
return;
}
for (i = 0; i < num_resamplers; ++i)
{
if (!strcasecmp(snd_resampler, alGetStringiSOFT(AL_RESAMPLER_NAME_SOFT, i)))
{
def_resampler = i;
break;
}
}
if (i == num_resamplers)
{
printf(" Failed to find resampler: '%s'.\n", snd_resampler);
return;
}
for (i = 0; i < MAX_CHANNELS; ++i)
{
alSourcei(openal_sources[i], AL_SOURCE_RESAMPLER_SOFT, def_resampler);
}
printf(" Using '%s' resampler.\n",
alGetStringiSOFT(AL_RESAMPLER_NAME_SOFT, def_resampler));
}
// [FG] add links for likely missing sounds
struct {
@ -591,6 +655,8 @@ void I_InitSound(void)
openal_sources = malloc(MAX_CHANNELS * sizeof(*openal_sources));
alGenSources(MAX_CHANNELS, openal_sources);
SetResampler();
I_AtExit(I_ShutdownSound, true);
snd_init = true;

View File

@ -97,6 +97,7 @@ extern int winmm_chorus_level;
#endif
extern int opl_gain;
extern int midi_player_menu;
extern char *snd_resampler;
extern boolean demobar;
extern boolean smoothlight;
extern boolean brightmaps;
@ -406,6 +407,13 @@ default_t defaults[] = {
"number of sound effects handled simultaneously"
},
{
"snd_resampler",
(config_t *) &snd_resampler, NULL,
{.s = "linear"}, {0}, string, ss_gen, wad_no,
"OpenAL resampler (\"nearest\", \"linear\"(default), \"cubic\")"
},
// [FG] music backend
{
"midi_player",