Merge pull request #655 from 0lvin/stereo_sound

Support of wav stereo sound
This commit is contained in:
Yamagi 2021-01-31 12:18:26 +01:00 committed by GitHub
commit 06d183b6db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 243 additions and 205 deletions

View file

@ -1509,7 +1509,7 @@ RE_SetMode(void)
vid_fullscreen->modified = false;
R_Printf(PRINT_ALL, "%s() - fullscreen unavailable in this mode\n", __func__);
if ((err = SWimp_SetMode(&vid.width, &vid.height, r_mode->value, 0)) == rserr_ok)
if (SWimp_SetMode(&vid.width, &vid.height, r_mode->value, 0) == rserr_ok)
{
return true;
}

View file

@ -1019,7 +1019,7 @@ qboolean RE_EndWorldRenderpass(void)
float underwaterTime;
if (vk_underwater->value)
{
underwaterTime= r_newrefdef.rdflags & RDF_UNDERWATER ? r_newrefdef.time : 0.f;
underwaterTime = (r_newrefdef.rdflags & RDF_UNDERWATER) ? r_newrefdef.time : 0.f;
}
else
{

View file

@ -33,25 +33,24 @@ struct sfx_s;
void S_Init(void);
void S_Shutdown(void);
/* if origin is NULL, the sound will be
/* if origin is NULL, the sound will be
dynamically sourced from the entity */
void S_StartSound(vec3_t origin, int entnum, int entchannel,
struct sfx_s *sfx, float fvol, float attenuation,
float timeofs);
void S_StartLocalSound(char *s);
void S_StartLocalSound(char *sound);
void S_RawSamples(int samples, int rate, int width, int channels,
byte *data, float volume);
void S_StopAllSounds(void);
void S_Update(vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up);
void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up);
void S_Activate(qboolean active);
void S_BeginRegistration(void);
struct sfx_s *S_RegisterSound(char *sample);
struct sfx_s *S_RegisterSound(char *name);
void S_EndRegistration(void);
struct sfx_s *S_FindName(char *name, qboolean create);
/* the sound code makes callbacks to the client for
entitiy position information, so entities can be
entitiy position information, so entities can be
dynamically re-spatialized */
void CL_GetEntitySoundOrigin(int ent, vec3_t org);
void CL_GetEntitySoundVelocity(int ent, vec3_t vel);

View file

@ -34,7 +34,7 @@ typedef enum
void OGG_InitTrackList(void);
void OGG_Init(void);
void OGG_PlayTrack(int track);
void OGG_PlayTrack(int trackNo);
void OGG_RecoverState(void);
void OGG_SaveState(void);
void OGG_Shutdown(void);

View file

@ -20,7 +20,7 @@
* This file implements an interface to libvorbis for decoding
* OGG/Vorbis files. Strongly spoken this file isn't part of the sound
* system but part of the main client. It justs converts Vorbis streams
* into normal, raw Wave stream which are injected into the backends as
* into normal, raw Wave stream which are injected into the backends as
* if they were normal "raw" samples. At this moment only background
* music playback and in theory .cin movie file playback is supported.
*
@ -201,9 +201,8 @@ OGG_InitTrackList(void)
}
// the GOG case: music/Track02.ogg to Track21.ogg
int gogTrack = getMappedGOGtrack(8, gameType);
snprintf(testFileName, MAX_OSPATH, "%sTrack%02i.ogg", fullMusicPath, gogTrack);
snprintf(testFileName, MAX_OSPATH, "%sTrack%02i.ogg",
fullMusicPath, getMappedGOGtrack(8, gameType));
if(Sys_IsFile(testFileName))
{

View file

@ -54,7 +54,7 @@
/* Globals */
int active_buffers;
qboolean streamPlaying;
static qboolean streamPlaying;
static ALuint s_srcnums[MAX_CHANNELS - 1];
static ALuint streamSource;
static int s_framecount;
@ -127,6 +127,35 @@ AL_StreamUpdate(void)
/* ----------------------------------------------------------------- */
static ALenum
AL_GetFormat(int width, int channels)
{
if (width == 1)
{
if (channels == 1)
{
return AL_FORMAT_MONO8;
}
else if (channels == 2)
{
return AL_FORMAT_STEREO8;
}
}
else if (width == 2)
{
if (channels == 1)
{
return AL_FORMAT_MONO16;
}
else if (channels == 2)
{
return AL_FORMAT_STEREO16;
}
}
return AL_FORMAT_MONO8;
}
/*
* Uploads a sample to OpenAL and places
* a dummy entry in the frontends cache.
@ -142,7 +171,9 @@ AL_UploadSfx(sfx_t *s, wavinfo_t *s_info, byte *data)
ALuint name;
size = s_info->samples * s_info->width;
format = s_info->width == 2 ? AL_FORMAT_MONO16 : AL_FORMAT_MONO8;
/* Work out format */
format = AL_GetFormat(s_info->width, s_info->channels);
if (!size)
{
@ -166,6 +197,7 @@ AL_UploadSfx(sfx_t *s, wavinfo_t *s_info, byte *data)
sc->width = s_info->width;
sc->size = size;
sc->bufnum = name;
sc->stereo = s_info->channels - 1;
return sc;
}
@ -204,7 +236,7 @@ static void
AL_Spatialize(channel_t *ch)
{
vec3_t origin;
vec3_t velocity;
vec3_t velocity;
if ((ch->entnum == -1) || (ch->entnum == cl.playernum + 1) || !ch->dist_mult)
{
@ -233,8 +265,6 @@ AL_Spatialize(channel_t *ch)
return;
}
}
/*
@ -508,28 +538,7 @@ AL_RawSamples(int samples, int rate, int width, int channels,
ALuint format = 0;
/* Work out format */
if (width == 1)
{
if (channels == 1)
{
format = AL_FORMAT_MONO8;
}
else if (channels == 2)
{
format = AL_FORMAT_STEREO8;
}
}
else if (width == 2)
{
if (channels == 1)
{
format = AL_FORMAT_MONO16;
}
else if (channels == 2)
{
format = AL_FORMAT_STEREO16;
}
}
format = AL_GetFormat(width, channels);
/* Create a buffer, and stuff the data into it */
qalGenBuffers(1, &buffer);
@ -537,7 +546,7 @@ AL_RawSamples(int samples, int rate, int width, int channels,
(samples * width * channels), rate);
active_buffers++;
/* set volume */
/* set volume */
if (volume > 1.0f)
{
volume = 1.0f;
@ -563,47 +572,54 @@ AL_UnqueueRawSamples()
AL_StreamDie();
}
void oal_update_underwater()
static void
AL_UpdateUnderwater()
{
int i;
float gain_hf;
qboolean update = false;
ALuint filter;
int i;
float gain_hf;
qboolean update = false;
ALuint filter;
if (underwaterFilter == 0)
return;
if (underwaterFilter == 0) {
return;
}
if (s_underwater->modified) {
update = true;
s_underwater->modified = false;
snd_is_underwater_enabled = ((int)s_underwater->value != 0);
}
if (s_underwater->modified) {
update = true;
s_underwater->modified = false;
snd_is_underwater_enabled = ((int)s_underwater->value != 0);
}
if (s_underwater_gain_hf->modified) {
update = true;
s_underwater_gain_hf->modified = false;
}
if (s_underwater_gain_hf->modified) {
update = true;
s_underwater_gain_hf->modified = false;
}
if (!update)
return;
if (!update) {
return;
}
gain_hf = s_underwater_gain_hf->value;
gain_hf = s_underwater_gain_hf->value;
if (gain_hf < AL_LOWPASS_MIN_GAINHF)
gain_hf = AL_LOWPASS_MIN_GAINHF;
if (gain_hf < AL_LOWPASS_MIN_GAINHF) {
gain_hf = AL_LOWPASS_MIN_GAINHF;
}
if (gain_hf > AL_LOWPASS_MAX_GAINHF)
gain_hf = AL_LOWPASS_MAX_GAINHF;
if (gain_hf > AL_LOWPASS_MAX_GAINHF) {
gain_hf = AL_LOWPASS_MAX_GAINHF;
}
qalFilterf(underwaterFilter, AL_LOWPASS_GAINHF, gain_hf);
qalFilterf(underwaterFilter, AL_LOWPASS_GAINHF, gain_hf);
if (snd_is_underwater_enabled && snd_is_underwater)
filter = underwaterFilter;
else
filter = 0;
if (snd_is_underwater_enabled && snd_is_underwater) {
filter = underwaterFilter;
} else {
filter = 0;
}
for (i = 0; i < s_numchannels; ++i)
qalSourcei(s_srcnums[i], AL_DIRECT_FILTER, filter);
for (i = 0; i < s_numchannels; ++i) {
qalSourcei(s_srcnums[i], AL_DIRECT_FILTER, filter);
}
}
/*
@ -626,7 +642,7 @@ AL_Update(void)
Otherwise sound and game will become asynchronous and
the paint buffer may overflow. */
if (!QAL_RecoverLostDevice()) {
return;
return;
}
/* set listener (player) parameters */
@ -695,7 +711,7 @@ AL_Update(void)
AL_StreamUpdate();
AL_IssuePlaysounds();
oal_update_underwater();
AL_UpdateUnderwater();
}
/* ----------------------------------------------------------------- */
@ -792,10 +808,10 @@ AL_InitUnderwaterFilter()
return;
}
qalFilterf(underwaterFilter, AL_LOWPASS_GAIN, AL_LOWPASS_DEFAULT_GAIN);
qalFilterf(underwaterFilter, AL_LOWPASS_GAIN, AL_LOWPASS_DEFAULT_GAIN);
s_underwater->modified = true;
s_underwater_gain_hf->modified = true;
s_underwater->modified = true;
s_underwater_gain_hf->modified = true;
}
/*

View file

@ -156,10 +156,10 @@ LPALDELETEFILTERS qalDeleteFilters;
void QAL_SoundInfo()
{
Com_Printf("OpenAL settings:\n");
Com_Printf("AL_VENDOR: %s\n", qalGetString(AL_VENDOR));
Com_Printf("AL_RENDERER: %s\n", qalGetString(AL_RENDERER));
Com_Printf("AL_VERSION: %s\n", qalGetString(AL_VERSION));
Com_Printf("AL_EXTENSIONS: %s\n", qalGetString(AL_EXTENSIONS));
Com_Printf("AL_VENDOR: %s\n", qalGetString(AL_VENDOR));
Com_Printf("AL_RENDERER: %s\n", qalGetString(AL_RENDERER));
Com_Printf("AL_VERSION: %s\n", qalGetString(AL_VERSION));
Com_Printf("AL_EXTENSIONS: %s\n", qalGetString(AL_EXTENSIONS));
if (qalcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"))
{
@ -262,18 +262,18 @@ QAL_RecoverLostDevice()
void
QAL_Shutdown()
{
if (context)
{
qalcMakeContextCurrent( NULL );
qalcDestroyContext( context );
context = NULL;
}
if (context)
{
qalcMakeContextCurrent( NULL );
qalcDestroyContext( context );
context = NULL;
}
if (device)
{
qalcCloseDevice( device );
device = NULL;
}
qalcCloseDevice( device );
device = NULL;
}
/* Disconnect function pointers used
for OpenAL management calls */
@ -510,7 +510,7 @@ QAL_Init()
qalDistanceModel = ALSYMBOL(handle, alDistanceModel);
/* Open the OpenAL device */
Com_Printf("...opening OpenAL device: ");
Com_Printf("...opening OpenAL device: ");
device = qalcOpenDevice(al_device->string[0] ? al_device->string : NULL);
@ -547,17 +547,17 @@ QAL_Init()
return false;
}
if (qalcIsExtensionPresent(device, "ALC_EXT_EFX") != AL_FALSE) {
qalGenFilters = qalGetProcAddress("alGenFilters");
qalFilteri = qalGetProcAddress("alFilteri");
qalFilterf = qalGetProcAddress("alFilterf");
qalDeleteFilters = qalGetProcAddress("alDeleteFilters");
} else {
qalGenFilters = NULL;
qalFilteri = NULL;
qalFilterf = NULL;
qalDeleteFilters = NULL;
}
if (qalcIsExtensionPresent(device, "ALC_EXT_EFX") != AL_FALSE) {
qalGenFilters = qalGetProcAddress("alGenFilters");
qalFilteri = qalGetProcAddress("alFilteri");
qalFilterf = qalGetProcAddress("alFilterf");
qalDeleteFilters = qalGetProcAddress("alDeleteFilters");
} else {
qalGenFilters = NULL;
qalFilteri = NULL;
qalFilterf = NULL;
qalDeleteFilters = NULL;
}
Com_Printf("ok\n");

View file

@ -46,8 +46,8 @@
#define SDL_LOOPATTENUATE 0.003
/* Globals */
cvar_t *s_sdldriver;
int *snd_p;
static cvar_t *s_sdldriver;
static int *snd_p;
static sound_t *backend;
static portable_samplepair_t paintbuffer[SDL_PAINTBUFFER_SIZE];
static int beginofs;
@ -73,7 +73,8 @@ static const float lpf_default_gain_hf = 0.25F;
static LpfContext lpf_context;
static qboolean lpf_is_enabled;
static void lpf_initialize(LpfContext* lpf_context, float gain_hf, int target_frequency)
static void
lpf_initialize(LpfContext* lpf_context, float gain_hf, int target_frequency)
{
assert(target_frequency > 0);
assert(lpf_context);
@ -110,7 +111,8 @@ static void lpf_initialize(LpfContext* lpf_context, float gain_hf, int target_fr
lpf_context->is_history_initialized = false;
}
static void lpf_update_samples(LpfContext* lpf_context,int sample_count, portable_samplepair_t* samples)
static void
lpf_update_samples(LpfContext* lpf_context,int sample_count, portable_samplepair_t* samples)
{
assert(lpf_context);
assert(sample_count >= 0);
@ -171,20 +173,11 @@ static void lpf_update_samples(LpfContext* lpf_context,int sample_count, portabl
* the SDL output buffer and places it
* at the appropriate position.
*/
void
static void
SDL_TransferPaintBuffer(int endtime)
{
int i;
int lpos;
int ls_paintedtime;
int out_idx;
int count;
int out_mask;
int *p;
int snd_linear_count;
int step;
int val;
short *snd_out;
unsigned char *pbuf;
pbuf = sound.buffer;
@ -206,11 +199,18 @@ SDL_TransferPaintBuffer(int endtime)
if ((sound.samplebits == 16) && (sound.channels == 2))
{
int ls_paintedtime;
snd_p = (int *)paintbuffer;
ls_paintedtime = paintedtime;
while (ls_paintedtime < endtime)
{
int i;
short *snd_out;
int snd_linear_count;
int lpos;
lpos = ls_paintedtime & ((sound.samples >> 1) - 1);
snd_out = (short *)pbuf + (lpos << 1);
@ -263,6 +263,11 @@ SDL_TransferPaintBuffer(int endtime)
}
else
{
int count;
int step;
int *p;
int out_idx;
p = (int *)paintbuffer;
count = (endtime - paintedtime) * sound.channels;
out_mask = sound.samples - 1;
@ -322,10 +327,9 @@ SDL_TransferPaintBuffer(int endtime)
/*
* Mixes an 8 bit sample into a channel.
*/
void
static void
SDL_PaintChannelFrom8(channel_t *ch, sfxcache_t *sc, int count, int offset)
{
int data;
int *lscale, *rscale;
unsigned char *sfx;
int i;
@ -349,6 +353,8 @@ SDL_PaintChannelFrom8(channel_t *ch, sfxcache_t *sc, int count, int offset)
for (i = 0; i < count; i++, samp++)
{
int data;
data = sfx[i];
samp->left += lscale[data];
samp->right += rscale[data];
@ -360,11 +366,9 @@ SDL_PaintChannelFrom8(channel_t *ch, sfxcache_t *sc, int count, int offset)
/*
* Mixes an 16 bit sample into a channel
*/
void
static void
SDL_PaintChannelFrom16(channel_t *ch, sfxcache_t *sc, int count, int offset)
{
int data;
int left, right;
int leftvol, rightvol;
signed short *sfx;
int i;
@ -378,6 +382,9 @@ SDL_PaintChannelFrom16(channel_t *ch, sfxcache_t *sc, int count, int offset)
for (i = 0; i < count; i++, samp++)
{
int data;
int left, right;
data = sfx[i];
left = (data * leftvol) >> 8;
right = (data * rightvol) >> 8;
@ -392,11 +399,10 @@ SDL_PaintChannelFrom16(channel_t *ch, sfxcache_t *sc, int count, int offset)
* Mixes all pending sounds into
* the available output channels.
*/
void
static void
SDL_PaintChannels(int endtime)
{
int i;
int end;
channel_t *ch;
sfxcache_t *sc;
int ltime, count;
@ -406,6 +412,8 @@ SDL_PaintChannels(int endtime)
while (paintedtime < endtime)
{
int end;
/* if paintbuffer is smaller than SDL buffer */
end = endtime;
@ -512,24 +520,29 @@ SDL_PaintChannels(int endtime)
}
}
if (lpf_is_enabled && snd_is_underwater)
lpf_update_samples(&lpf_context, end - paintedtime, paintbuffer);
else
lpf_context.is_history_initialized = false;
if (lpf_is_enabled && snd_is_underwater)
{
lpf_update_samples(&lpf_context, end - paintedtime, paintbuffer);
}
else
{
lpf_context.is_history_initialized = false;
}
if (s_rawend >= paintedtime)
{
/* add from the streaming sound source */
int s;
int stop;
stop = (end < s_rawend) ? end : s_rawend;
for (i = paintedtime; i < stop; i++)
{
int s;
s = i & (MAX_RAW_SAMPLES - 1);
paintbuffer[i - paintedtime].left += s_rawsamples[s].left;
paintbuffer[i - paintedtime].right += s_rawsamples[s].right;
paintbuffer[i - paintedtime].right += s_rawsamples[s].right;
}
}
@ -571,7 +584,7 @@ SDL_DriftBeginofs(float timeofs)
/*
* Spatialize a sound effect based on it's origin.
*/
void
static void
SDL_SpatializeOrigin(vec3_t origin, float master_vol, float dist_mult, int *left_vol, int *right_vol)
{
vec_t dot;
@ -790,8 +803,6 @@ void
SDL_ClearBuffer(void)
{
int clear;
int i;
unsigned char *ptr = sound.buffer;
if (sound_started == SS_NOT)
{
@ -813,6 +824,9 @@ SDL_ClearBuffer(void)
if (sound.buffer)
{
int i;
unsigned char *ptr = sound.buffer;
i = sound.samples * sound.samplebits / 8;
while (i--)
@ -829,7 +843,7 @@ SDL_ClearBuffer(void)
* Calculates the absolute timecode
* of current playback.
*/
void
static void
SDL_UpdateSoundtime(void)
{
static int buffers;
@ -861,11 +875,10 @@ SDL_UpdateSoundtime(void)
* Updates the volume scale table
* based on current volume setting.
*/
void
static void
SDL_UpdateScaletable(void)
{
int i, j;
int scale;
int i;
if (s_volume->value > 2.0f)
{
@ -880,6 +893,8 @@ SDL_UpdateScaletable(void)
for (i = 0; i < 32; i++)
{
int j, scale;
scale = (int)(i * 8 * 256 * s_volume->value);
for (j = 0; j < 256; j++)
@ -901,12 +916,11 @@ SDL_Cache(sfx_t *sfx, wavinfo_t *info, byte *data)
int i;
int len;
int sample;
int srcsample;
sfxcache_t *sc;
unsigned int samplefrac = 0;
stepscale = (float)info->rate / sound.speed;
len = (int)(info->samples / stepscale);
len = (int)(info->samples / stepscale);
if ((info->samples == 0) || (len == 0))
{
@ -923,13 +937,14 @@ SDL_Cache(sfx_t *sfx, wavinfo_t *info, byte *data)
}
sc->loopstart = info->loopstart;
sc->stereo = 0;
sc->stereo = info->channels - 1;
sc->length = (int)(info->samples / stepscale);
sc->speed = sound.speed;
if ((int)(info->samples / stepscale) == 0)
{
Com_Printf("ResampleSfx: Invalid sound file '%s' (zero length)\n", sfx->name);
Com_Printf("%s: Invalid sound file '%s' (zero length)\n",
__func__, sfx->name);
Z_Free(sfx->cache);
sfx->cache = NULL;
return false;
@ -952,6 +967,8 @@ SDL_Cache(sfx_t *sfx, wavinfo_t *info, byte *data)
/* resample / decimate to the current source rate */
for (i = 0; i < (int)(info->samples / stepscale); i++)
{
int srcsample;
srcsample = samplefrac >> 8;
samplefrac += (int)(stepscale * 256);
@ -1083,20 +1100,20 @@ SDL_Update(void)
channel_t *ch;
int i;
int samps;
int total;
unsigned int endtime;
if (s_underwater->modified) {
s_underwater->modified = false;
lpf_is_enabled = ((int)s_underwater->value != 0);
}
if (s_underwater->modified) {
s_underwater->modified = false;
lpf_is_enabled = ((int)s_underwater->value != 0);
}
if (s_underwater_gain_hf->modified) {
s_underwater_gain_hf->modified = false;
if (s_underwater_gain_hf->modified) {
s_underwater_gain_hf->modified = false;
lpf_initialize(
&lpf_context, s_underwater_gain_hf->value, backend->speed);
}
lpf_initialize(
&lpf_context, s_underwater_gain_hf->value,
backend->speed);
}
/* if the loading plaque is up, clear everything
out to make sure we aren't looping a dirty
@ -1149,6 +1166,8 @@ SDL_Update(void)
/* debugging output */
if (s_show->value)
{
int total;
total = 0;
ch = channels;
@ -1173,7 +1192,7 @@ SDL_Update(void)
return;
}
/* Mix the samples */
/* Mix the samples */
SDL_LockAudio();
/* Updates SDL time */
@ -1187,7 +1206,7 @@ SDL_Update(void)
/* check to make sure that we haven't overshot */
if (paintedtime < soundtime)
{
Com_DPrintf("S_Update_ : overflow\n");
Com_DPrintf("%s: overflow\n", __func__);
paintedtime = soundtime;
}
@ -1274,7 +1293,7 @@ SDL_Callback(void *data, Uint8 *stream, int length)
playpos = (length2 / (backend->samplebits / 8));
}
if (playpos >= samplesize)
if (playpos >= samplesize)
{
playpos = 0;
}
@ -1416,9 +1435,9 @@ SDL_BackendInit(void)
backend->buffer = calloc(1, samplesize);
s_numchannels = MAX_CHANNELS;
s_underwater->modified = true;
s_underwater_gain_hf->modified = true;
lpf_initialize(&lpf_context, lpf_default_gain_hf, backend->speed);
s_underwater->modified = true;
s_underwater_gain_hf->modified = true;
lpf_initialize(&lpf_context, lpf_default_gain_hf, backend->speed);
SDL_UpdateScaletable();
SDL_PauseAudio(0);
@ -1438,13 +1457,13 @@ void
SDL_BackendShutdown(void)
{
Com_Printf("Closing SDL audio device...\n");
SDL_PauseAudio(1);
SDL_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
free(backend->buffer);
backend->buffer = NULL;
playpos = samplesize = 0;
snd_inited = 0;
Com_Printf("SDL audio device shut down.\n");
SDL_PauseAudio(1);
SDL_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
free(backend->buffer);
backend->buffer = NULL;
playpos = samplesize = 0;
snd_inited = 0;
Com_Printf("SDL audio device shut down.\n");
}

View file

@ -58,8 +58,8 @@ vec3_t listener_forward;
vec3_t listener_right;
vec3_t listener_up;
playsound_t s_playsounds[MAX_PLAYSOUNDS];
playsound_t s_freeplays;
static playsound_t s_playsounds[MAX_PLAYSOUNDS];
static playsound_t s_freeplays;
playsound_t s_pendingplays;
cvar_t *s_volume;
@ -75,14 +75,13 @@ cvar_t* s_doppler;
cvar_t* s_ps_sorting;
channel_t channels[MAX_CHANNELS];
int num_sfx;
static int num_sfx;
int paintedtime;
int s_numchannels;
int s_rawend;
int s_registration_sequence;
static int s_registration_sequence = 0;
portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
qboolean snd_initialized = false;
sfx_t known_sfx[MAX_SFX];
static sfx_t known_sfx[MAX_SFX];
sndstarted_t sound_started = SS_NOT;
sound_t sound;
static qboolean s_registering;
@ -263,9 +262,9 @@ S_LoadSound(sfx_t *s)
info = GetWavinfo(s->name, data, size);
if (info.channels != 1)
if (info.channels < 1 || info.channels > 2)
{
Com_Printf("%s is a stereo sample\n", s->name);
Com_Printf("%s has an invalid number of channels\n", s->name);
FS_FreeFile(data);
return NULL;
}
@ -301,7 +300,7 @@ S_LoadSound(sfx_t *s)
/*
* Returns the name of a sound
*/
sfx_t *
static sfx_t *
S_FindName(char *name, qboolean create)
{
int i;
@ -309,17 +308,18 @@ S_FindName(char *name, qboolean create)
if (!name)
{
Com_Error(ERR_FATAL, "S_FindName: NULL\n");
Com_Error(ERR_FATAL, "%s: NULL\n", __func__);
}
if (!name[0])
{
Com_Error(ERR_FATAL, "S_FindName: empty name\n");
Com_Error(ERR_FATAL, "%s: empty name\n", __func__);
}
if (strlen(name) >= MAX_QPATH)
{
Com_Error(ERR_FATAL, "Sound name too long: %s", name);
Com_Error(ERR_FATAL, "%s :Sound name too long: %s",
__func__, name);
}
/* see if already loaded */
@ -349,7 +349,7 @@ S_FindName(char *name, qboolean create)
{
if (num_sfx == MAX_SFX)
{
Com_Error(ERR_FATAL, "S_FindName: out of sfx_t");
Com_Error(ERR_FATAL, "%s: out of sfx_t", __func__);
}
num_sfx++;
@ -368,7 +368,7 @@ S_FindName(char *name, qboolean create)
* Registers an alias name
* for a sound
*/
sfx_t *
static sfx_t *
S_AliasName(char *aliasname, char *truename)
{
sfx_t *sfx;
@ -391,7 +391,7 @@ S_AliasName(char *aliasname, char *truename)
{
if (num_sfx == MAX_SFX)
{
Com_Error(ERR_FATAL, "S_FindName: out of sfx_t");
Com_Error(ERR_FATAL, "%s: out of sfx_t", __func__);
}
num_sfx++;
@ -441,14 +441,13 @@ S_RegisterSound(char *name)
return sfx;
}
struct sfx_s *
static struct sfx_s *
S_RegisterSexedSound(entity_state_t *ent, char *base)
{
int n;
struct sfx_s *sfx;
char model[MAX_QPATH];
char sexedFilename[MAX_QPATH];
char maleFilename[MAX_QPATH];
/* determine what model the client is using */
model[0] = 0;
@ -497,6 +496,8 @@ S_RegisterSexedSound(entity_state_t *ent, char *base)
}
else
{
char maleFilename[MAX_QPATH];
/* no, revert to the male sound in the pak0.pak */
Com_sprintf(maleFilename, sizeof(maleFilename),
"player/male/%s", base + 1);
@ -572,7 +573,7 @@ S_PickChannel(int entnum, int entchannel)
if (entchannel < 0)
{
Com_Error(ERR_DROP, "S_PickChannel: entchannel<0");
Com_Error(ERR_DROP, "%s: entchannel<0", __func__);
}
/* Check for replacement sound, or find the best one to replace */
@ -627,7 +628,7 @@ S_PickChannel(int entnum, int entchannel)
/*
* Picks a free playsound
*/
playsound_t *
static playsound_t *
S_AllocPlaysound(void)
{
playsound_t *ps;
@ -651,7 +652,7 @@ S_AllocPlaysound(void)
/*
* Frees a playsound
*/
void
static void
S_FreePlaysound(playsound_t *ps)
{
/* unlink from channel */
@ -920,7 +921,7 @@ S_StartLocalSound(char *sound)
if (!sfx)
{
Com_Printf("S_StartLocalSound: can't cache %s\n", sound);
Com_Printf("%s: can't cache %s\n", __func__, sound);
return;
}
@ -978,11 +979,12 @@ void
S_BuildSoundList(int *sounds)
{
int i;
int num;
entity_state_t *ent;
for (i = 0; i < cl.frame.num_entities; i++)
{
int num;
entity_state_t *ent;
if (i >= MAX_EDICTS)
{
break;
@ -1078,17 +1080,18 @@ S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
* Plays one sample. Called
* by the "play" cmd.
*/
void
static void
S_Play(void)
{
int i;
char name[256];
sfx_t *sfx;
i = 1;
while (i < Cmd_Argc())
{
char name[256];
sfx_t *sfx;
if (!strrchr(Cmd_Argv(i), '.'))
{
Q_strlcpy(name, Cmd_Argv(i), sizeof(name) - 4);
@ -1114,7 +1117,7 @@ S_Play(void)
/*
* List all loaded sounds
*/
void
static void
S_SoundList(void)
{
int i;
@ -1139,9 +1142,10 @@ S_SoundList(void)
{
size = sc->length * sc->width * (sc->stereo + 1);
total += size;
Com_Printf("%s(%2db) %8i : %s\n",
Com_Printf("%s(%2db) %8i(%d ch) : %s\n",
sc->loopstart != -1 ? "L" : " ",
sc->width * 8, size, sfx->name);
sc->width * 8, size,
(sc->stereo + 1), sfx->name);
}
else
{
@ -1168,7 +1172,7 @@ S_SoundList(void)
* Prints information about the
* active sound backend
*/
void
static void
S_SoundInfo_f(void)
{
if (sound_started == SS_NOT)
@ -1216,8 +1220,8 @@ S_Init(void)
s_show = Cvar_Get("s_show", "0", 0);
s_testsound = Cvar_Get("s_testsound", "0", 0);
s_ambient = Cvar_Get("s_ambient", "1", 0);
s_underwater = Cvar_Get("s_underwater", "1", CVAR_ARCHIVE);
s_underwater_gain_hf = Cvar_Get("s_underwater_gain_hf", "0.25", CVAR_ARCHIVE);
s_underwater = Cvar_Get("s_underwater", "1", CVAR_ARCHIVE);
s_underwater_gain_hf = Cvar_Get("s_underwater_gain_hf", "0.25", CVAR_ARCHIVE);
s_doppler = Cvar_Get("s_doppler", "0", CVAR_ARCHIVE);
s_ps_sorting = Cvar_Get("s_ps_sorting", "1", CVAR_ARCHIVE);

View file

@ -27,13 +27,13 @@
#include "../header/client.h"
#include "header/local.h"
byte *data_p;
byte *iff_end;
byte *last_chunk;
byte *iff_data;
int iff_chunk_len;
static byte *data_p;
static byte *iff_end;
static byte *last_chunk;
static byte *iff_data;
static int iff_chunk_len;
short
static short
GetLittleShort(void)
{
short val = 0;
@ -44,7 +44,7 @@ GetLittleShort(void)
return val;
}
int
static int
GetLittleLong(void)
{
int val = 0;
@ -57,7 +57,7 @@ GetLittleLong(void)
return val;
}
void
static void
FindNextChunk(char *name)
{
while (1)
@ -89,7 +89,7 @@ FindNextChunk(char *name)
}
}
void
static void
FindChunk(char *name)
{
last_chunk = iff_data;
@ -195,7 +195,8 @@ GetWavinfo(char *name, byte *wav, int wavlength)
{
if (samples < info.samples)
{
Com_Error(ERR_DROP, "Sound %s has a bad loop length", name);
Com_Error(ERR_DROP, "%s: Sound %s has a bad loop length",
__func__, name);
}
}
else