Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jun 12, 2022
1 parent 10a70d6 commit 9911d91
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 96 deletions.
27 changes: 4 additions & 23 deletions common/snd_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ static void SND_Callback_sfxvolume (cvar_t *var)
* ================
*/

void
S_Startup(void)
static void S_Startup(void)
{
if (!SNDDMA_Init(&sn))
{
Expand Down Expand Up @@ -173,19 +172,11 @@ S_FindName(const char *name)
int i;
sfx_t *sfx;

if (!name)
Sys_Error("%s: NULL", __func__);
if (strlen(name) >= MAX_QPATH)
Sys_Error("%s: name too long: %s", __func__, name);

/* see if already loaded */
for (i = 0; i < num_sfx; i++)
if (!strcmp(known_sfx[i].name, name))
return &known_sfx[i];

if (num_sfx == MAX_SFX)
Sys_Error("%s: out of sfx_t", __func__);

sfx = &known_sfx[i];
strcpy(sfx->name, name);

Expand Down Expand Up @@ -761,13 +752,9 @@ static void S_Play(void)
{
sfx_t *sfx;

strcpy(name, Cmd_Argv(i));
if (!strrchr(Cmd_Argv(i), '.'))
{
strcpy(name, Cmd_Argv(i));
strcat(name, ".wav");
}
else
strcpy(name, Cmd_Argv(i));
sfx = S_PrecacheSound(name);
S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 1.0);
i++;
Expand All @@ -785,13 +772,9 @@ static void S_PlayVol(void)
float vol;
sfx_t *sfx;

strcpy(name, Cmd_Argv(i));
if (!strrchr(Cmd_Argv(i), '.'))
{
strcpy(name, Cmd_Argv(i));
strcat(name, ".wav");
}
else
strcpy(name, Cmd_Argv(i));
sfx = S_PrecacheSound(name);
vol = Q_atof(Cmd_Argv(i + 1));
S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0);
Expand All @@ -807,10 +790,8 @@ void S_LocalSound(const char *sound)
return;

sfx = S_PrecacheSound(sound);
if (!sfx) {
Con_Printf("%s: can't cache %s\n", __func__, sound);
if (!sfx)
return;
}
#ifdef NQ_HACK
S_StartSound(cl.viewentity, -1, sfx, vec3_origin, 1, 1);
#endif
Expand Down
22 changes: 5 additions & 17 deletions common/snd_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ ResampleSfx(sfx_t *sfx, int inrate, int inwidth, const byte *data)
float stepscale;
int i;
int sample, samplefrac, fracstep;
sfxcache_t *sc;

sc = (sfxcache_t*)Cache_Check(&sfx->cache);
sfxcache_t *sc = (sfxcache_t*)Cache_Check(&sfx->cache);
if (!sc)
return;

Expand Down Expand Up @@ -115,21 +113,16 @@ S_LoadSound(sfx_t *s)
wavinfo_t *info;
int len;
float stepscale;
sfxcache_t *sc;
byte stackbuf[1024]; // avoid dirtying the cache heap

// see if still in memory
sc = (sfxcache_t*)Cache_Check(&s->cache);
// see if still in memory
sfxcache_t *sc = (sfxcache_t*)Cache_Check(&s->cache);
if (sc)
return sc;

//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
// load it in
// load it in
strcpy(namebuffer, "sound/");
strcat(namebuffer, s->name);

// Con_Printf ("loading %s\n",namebuffer);

data = (byte*)COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf), NULL);

if (!data) {
Expand Down Expand Up @@ -317,12 +310,7 @@ wavinfo_t *GetWavinfo (const char *name, byte *wav, int wavlength)
data_p += 4;
samples = GetLittleLong() / info.width;

if (info.samples)
{
if (samples < info.samples)
Sys_Error("Sound %s has a bad loop length", name);
}
else
if (!info.samples)
info.samples = samples;

info.dataofs = data_p - wav;
Expand Down
104 changes: 49 additions & 55 deletions common/snd_mix.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#define PAINTBUFFER_SIZE 16384
portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE];
int snd_scaletable[32][256];
int *snd_p, snd_linear_count;
short *snd_out;
static int snd_scaletable[32][256];
static int *snd_p, snd_linear_count;
static short *snd_out;

static int snd_vol;

static void Snd_WriteLinearBlastStereo16 (void)
{
int i;
int val;

for (i = 0; i < snd_linear_count; i += 2)
{
val = snd_p[i] >> 8;
int val = snd_p[i] >> 8;
if (val > 0x7fff)
snd_out[i] = 0x7fff;
else if (val < (short)0x8000)
Expand Down Expand Up @@ -100,8 +99,51 @@ CHANNEL MIXING
===============================================================================
*/

static void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int endtime, int paintbufferstart);
static void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int endtime, int paintbufferstart);
static void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count, int paintbufferstart)
{
int *lscale, *rscale;
unsigned char *sfx;
int i;

if (ch->leftvol > 255)
ch->leftvol = 255;
if (ch->rightvol > 255)
ch->rightvol = 255;

lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3];
sfx = (unsigned char *)sc->data + ch->pos;

for (i = 0; i < count; i++)
{
int data = sfx[i];
paintbuffer[paintbufferstart + i].left += lscale[data];
paintbuffer[paintbufferstart + i].right += rscale[data];
}

ch->pos += count;
}

static void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count, int paintbufferstart)
{
int i;
int leftvol = (ch->leftvol * snd_vol) >> 8;
int rightvol = (ch->rightvol * snd_vol) >> 8;
signed short *sfx = (signed short *)sc->data + ch->pos;

for (i = 0; i < count; i++)
{
int data = sfx[i];
// this was causing integer overflow as observed in quakespasm
// with the warpspasm mod moved >>8 to left/right volume above.
int left = data * leftvol;
int right = data * rightvol;
paintbuffer[paintbufferstart + i].left += left;
paintbuffer[paintbufferstart + i].right += right;
}

ch->pos += count;
}

void S_PaintChannels (int endtime)
{
Expand Down Expand Up @@ -221,51 +263,3 @@ void SND_InitScaletable (void)
}
}
}


static void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count, int paintbufferstart)
{
int *lscale, *rscale;
unsigned char *sfx;
int i;

if (ch->leftvol > 255)
ch->leftvol = 255;
if (ch->rightvol > 255)
ch->rightvol = 255;

lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3];
sfx = (unsigned char *)sc->data + ch->pos;

for (i = 0; i < count; i++)
{
int data = sfx[i];
paintbuffer[paintbufferstart + i].left += lscale[data];
paintbuffer[paintbufferstart + i].right += rscale[data];
}

ch->pos += count;
}

static void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count, int paintbufferstart)
{
int i;
int leftvol = (ch->leftvol * snd_vol) >> 8;
int rightvol = (ch->rightvol * snd_vol) >> 8;
signed short *sfx = (signed short *)sc->data + ch->pos;

for (i = 0; i < count; i++)
{
int data = sfx[i];
// this was causing integer overflow as observed in quakespasm
// with the warpspasm mod moved >>8 to left/right volume above.
int left = data * leftvol;
int right = data * rightvol;
paintbuffer[paintbufferstart + i].left += left;
paintbuffer[paintbufferstart + i].right += right;
}

ch->pos += count;
}

1 change: 0 additions & 1 deletion common/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ typedef struct
} wavinfo_t;

void S_Init(void);
void S_Startup(void);
void S_Shutdown(void);
void S_StartSound(int entnum, int entchannel, sfx_t *sfx,
vec3_t origin, float fvol, float attenuation);
Expand Down

0 comments on commit 9911d91

Please sign in to comment.