Remove SDL 1.2 support from the SDL sound backend.

While at it do some minor cleanup.
This commit is contained in:
Yamagi Burmeister 2018-07-18 20:29:10 +02:00
parent 3f65f7254b
commit cc15f0c10c

View file

@ -34,11 +34,7 @@
*/ */
/* SDL includes */ /* SDL includes */
#ifdef SDL2
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#else // SDL1.2
#include <SDL/SDL.h>
#endif //SDL2
/* Local includes */ /* Local includes */
#include "../../client/header/client.h" #include "../../client/header/client.h"
@ -64,16 +60,11 @@ static int soundtime;
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* =============================== */
/* Low-pass filter */
/* Based on OpenAL implementation. */
/* Filter's context */
typedef struct { typedef struct {
float a; float a;
float gain_hf; float gain_hf;
portable_samplepair_t history[2]; portable_samplepair_t history[2];
qboolean is_history_initialized; qboolean is_history_initialized;
} LpfContext; } LpfContext;
static const int lpf_reference_frequency = 5000; static const int lpf_reference_frequency = 5000;
@ -82,101 +73,99 @@ static const float lpf_default_gain_hf = 0.25F;
static LpfContext lpf_context; static LpfContext lpf_context;
static qboolean lpf_is_enabled; static qboolean lpf_is_enabled;
static void lpf_initialize( static void lpf_initialize(LpfContext* lpf_context, float gain_hf, int target_frequency)
LpfContext* lpf_context,
float gain_hf,
int target_frequency)
{ {
assert(target_frequency > 0); assert(target_frequency > 0);
assert(lpf_context); assert(lpf_context);
float g; float g;
float cw; float cw;
float a; float a;
const float k_2_pi = 6.283185307F; const float k_2_pi = 6.283185307F;
g = gain_hf; g = gain_hf;
if (g < 0.01F) if (g < 0.01F)
g = 0.01F; {
else if (gain_hf > 1.0F) g = 0.01F;
g = 1.0F; }
else if (gain_hf > 1.0F)
{
g = 1.0F;
}
cw = cosf((k_2_pi * lpf_reference_frequency) / target_frequency); cw = cosf((k_2_pi * lpf_reference_frequency) / target_frequency);
a = 0.0F; a = 0.0F;
if (g < 0.9999F) { if (g < 0.9999F)
a = (1.0F - (g * cw) - sqrtf((2.0F * g * (1.0F - cw)) - {
(g * g * (1.0F - (cw * cw))))) / (1.0F - g); a = (1.0F - (g * cw) - sqrtf((2.0F * g * (1.0F - cw)) -
} (g * g * (1.0F - (cw * cw))))) / (1.0F - g);
}
lpf_context->a = a; lpf_context->a = a;
lpf_context->gain_hf = gain_hf; lpf_context->gain_hf = gain_hf;
lpf_context->is_history_initialized = false; lpf_context->is_history_initialized = false;
} }
static void lpf_update_samples( static void lpf_update_samples(LpfContext* lpf_context,int sample_count, portable_samplepair_t* samples)
LpfContext* lpf_context,
int sample_count,
portable_samplepair_t* samples)
{ {
assert(lpf_context); assert(lpf_context);
assert(sample_count >= 0); assert(sample_count >= 0);
assert(samples); assert(samples);
int s; int s;
float a; float a;
portable_samplepair_t y; portable_samplepair_t y;
portable_samplepair_t* history; portable_samplepair_t* history;
if (sample_count <= 0) if (sample_count <= 0)
return; {
return;
}
a = lpf_context->a; a = lpf_context->a;
history = lpf_context->history; history = lpf_context->history;
if (!lpf_context->is_history_initialized) { if (!lpf_context->is_history_initialized)
lpf_context->is_history_initialized = true; {
lpf_context->is_history_initialized = true;
for (s = 0; s < 2; ++s) { for (s = 0; s < 2; ++s)
history[s].left = 0; {
history[s].right = 0; history[s].left = 0;
} history[s].right = 0;
} }
}
for (s = 0; s < sample_count; ++s) { for (s = 0; s < sample_count; ++s)
/* Update left channel */ {
/* Update left channel */
y.left = samples[s].left;
y.left = samples[s].left; y.left = (int)(y.left + a * (history[0].left - y.left));
history[0].left = y.left;
y.left = (int)(y.left + a * (history[0].left - y.left)); y.left = (int)(y.left + a * (history[1].left - y.left));
history[0].left = y.left; history[1].left = y.left;
y.left = (int)(y.left + a * (history[1].left - y.left));
history[1].left = y.left;
/* Update right channel */ /* Update right channel */
y.right = samples[s].right;
y.right = samples[s].right; y.right = (int)(y.right + a * (history[0].right - y.right));
history[0].right = y.right;
y.right = (int)(y.right + a * (history[0].right - y.right)); y.right = (int)(y.right + a * (history[1].right - y.right));
history[0].right = y.right; history[1].right = y.right;
y.right = (int)(y.right + a * (history[1].right - y.right)); /* Update sample */
history[1].right = y.right; samples[s] = y;
}
/* Update sample */
samples[s] = y;
}
} }
/* End of low-pass filter stuff */
/* ============================ */
/* /*
* Transfers a mixed "paint buffer" to * Transfers a mixed "paint buffer" to
* the SDL output buffer and places it * the SDL output buffer and places it
@ -453,8 +442,7 @@ SDL_PaintChannels(int endtime)
break; break;
} }
memset(paintbuffer, 0, (end - paintedtime) memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
* sizeof(portable_samplepair_t));
/* paint in the channels. */ /* paint in the channels. */
ch = channels; ch = channels;
@ -584,8 +572,7 @@ SDL_DriftBeginofs(float timeofs)
* Spatialize a sound effect based on it's origin. * Spatialize a sound effect based on it's origin.
*/ */
void void
SDL_SpatializeOrigin(vec3_t origin, float master_vol, float dist_mult, SDL_SpatializeOrigin(vec3_t origin, float master_vol, float dist_mult, int *left_vol, int *right_vol)
int *left_vol, int *right_vol)
{ {
vec_t dot; vec_t dot;
vec_t dist; vec_t dist;
@ -667,8 +654,7 @@ SDL_Spatialize(channel_t *ch)
CL_GetEntitySoundOrigin(ch->entnum, origin); CL_GetEntitySoundOrigin(ch->entnum, origin);
} }
SDL_SpatializeOrigin(origin, (float)ch->master_vol, ch->dist_mult, SDL_SpatializeOrigin(origin, (float)ch->master_vol, ch->dist_mult, &ch->leftvol, &ch->rightvol);
&ch->leftvol, &ch->rightvol);
} }
/* /*
@ -734,8 +720,7 @@ SDL_AddLoopSounds(void)
CL_GetEntitySoundOrigin(ent->number, origin); CL_GetEntitySoundOrigin(ent->number, origin);
/* find the total contribution of all sounds of this type */ /* find the total contribution of all sounds of this type */
SDL_SpatializeOrigin(ent->origin, 255.0f, SDL_LOOPATTENUATE, SDL_SpatializeOrigin(ent->origin, 255.0f, SDL_LOOPATTENUATE, &left_total, &right_total);
&left_total, &right_total);
for (j = i + 1; j < cl.frame.num_entities; j++) for (j = i + 1; j < cl.frame.num_entities; j++)
{ {
@ -1003,8 +988,7 @@ SDL_Cache(sfx_t *sfx, wavinfo_t *info, byte *data)
* and cinematic playback. * and cinematic playback.
*/ */
void void
SDL_RawSamples(int samples, int rate, int width, SDL_RawSamples(int samples, int rate, int width, int channels, byte *data, float volume)
int channels, byte *data, float volume)
{ {
float scale; float scale;
int dst; int dst;
@ -1325,11 +1309,7 @@ SDL_BackendInit(void)
int sndchans = (Cvar_Get("sndchannels", "2", CVAR_ARCHIVE))->value; int sndchans = (Cvar_Get("sndchannels", "2", CVAR_ARCHIVE))->value;
#ifdef _WIN32 #ifdef _WIN32
#if SDL_VERSION_ATLEAST(2, 0, 0)
s_sdldriver = (Cvar_Get("s_sdldriver", "directsound", CVAR_ARCHIVE)); s_sdldriver = (Cvar_Get("s_sdldriver", "directsound", CVAR_ARCHIVE));
#else
s_sdldriver = (Cvar_Get("s_sdldriver", "dsound", CVAR_ARCHIVE));
#endif
#elif __linux__ #elif __linux__
s_sdldriver = (Cvar_Get("s_sdldriver", "alsa", CVAR_ARCHIVE)); s_sdldriver = (Cvar_Get("s_sdldriver", "alsa", CVAR_ARCHIVE));
#elif __APPLE__ #elif __APPLE__
@ -1351,22 +1331,12 @@ SDL_BackendInit(void)
return 0; return 0;
} }
} }
#if SDL_VERSION_ATLEAST(2, 0, 0)
const char* drivername = SDL_GetCurrentAudioDriver(); const char* drivername = SDL_GetCurrentAudioDriver();
if(drivername == NULL) if(drivername == NULL)
{ {
drivername = "(UNKNOWN)"; drivername = "(UNKNOWN)";
} }
#else
char drivername[128];
if (SDL_AudioDriverName(drivername, sizeof(drivername)) == NULL)
{
strcpy(drivername, "(UNKNOWN)");
}
#endif
Com_Printf("SDL audio driver is \"%s\".\n", drivername); Com_Printf("SDL audio driver is \"%s\".\n", drivername);
memset(&desired, '\0', sizeof(desired)); memset(&desired, '\0', sizeof(desired));
@ -1433,6 +1403,7 @@ SDL_BackendInit(void)
backend->channels = obtained.channels; backend->channels = obtained.channels;
tmp = (obtained.samples * obtained.channels) * 10; tmp = (obtained.samples * obtained.channels) * 10;
if (tmp & (tmp - 1)) if (tmp & (tmp - 1))
{ /* make it a power of two */ { /* make it a power of two */
val = 1; val = 1;
@ -1441,6 +1412,7 @@ SDL_BackendInit(void)
tmp = val; tmp = val;
} }
backend->samples = tmp; backend->samples = tmp;
backend->submission_chunk = 1; backend->submission_chunk = 1;