From 0b5e78fbea0620ae5eb563c283f3219f97946e52 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 20 Nov 2004 00:57:43 +0000 Subject: [PATCH] We now support stereo wav files. (I'm supprised I didn't do this earlier - the rest of the sound code was already stereo-capable) git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@485 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/snd_mem.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/engine/client/snd_mem.c b/engine/client/snd_mem.c index 7e2ff778b..107d45f93 100644 --- a/engine/client/snd_mem.c +++ b/engine/client/snd_mem.c @@ -87,6 +87,7 @@ void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, qbyte *data) { srcsample = samplefrac >> 8; samplefrac += fracstep; + if (inwidth == 2) sample = LittleShort ( ((short *)data)[(srcsample<<1)] ); else @@ -165,7 +166,6 @@ sfxcache_t *S_LoadSound (sfx_t *s) qbyte *data; wavinfo_t info; int len; - float stepscale; sfxcache_t *sc; qbyte stackbuf[1*1024]; // avoid dirtying the cache heap @@ -217,15 +217,13 @@ sfxcache_t *S_LoadSound (sfx_t *s) } info = GetWavinfo (s->name, data, com_filesize); - if (info.numchannels != 1) + if (info.numchannels < 1 || info.numchannels > 2) { - Con_Printf ("%s is a stereo sample\n",s->name); + Con_Printf ("%s has an unsupported quantity of channels.\n",s->name); return NULL; } - stepscale = (float)info.rate / snd_speed; - len = info.samples / stepscale; - + len = (int) ((double) info.samples * (double) snd_speed / (double) info.rate); len = len * info.width * info.numchannels; sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name); @@ -236,7 +234,7 @@ sfxcache_t *S_LoadSound (sfx_t *s) sc->loopstart = info.loopstart; sc->speed = info.rate; sc->width = info.width; - sc->stereo = 0;//info.numchannels; + sc->stereo = info.numchannels-1; ResampleSfx (s, sc->speed, sc->width, data + info.dataofs); @@ -416,7 +414,7 @@ wavinfo_t GetWavinfo (char *name, qbyte *wav, int wavlength) } data_p += 4; - samples = GetLittleLong () / info.width; + samples = GetLittleLong () / info.width /info.numchannels; if (info.samples) {