- int outcount;
- int srcsample, srclength;
- float stepscale;
- int i;
- int samplefrac, fracstep;
- sfxcache_t *sc;
-
- sc = sfx->sfxcache;
- if (!sc)
- return;
-
- stepscale = (float)inrate / shm->speed; // this is usually 0.5, 1, or 2
-
- srclength = sc->length << sc->stereo;
-
- outcount = sc->length / stepscale;
- sc->length = outcount;
- if (sc->loopstart != -1)
- sc->loopstart = sc->loopstart / stepscale;
-
- sc->speed = shm->speed;
-// if (loadas8bit.value)
-// sc->width = 1;
-// else
-// sc->width = inwidth;
-// sc->stereo = 0;
-
-// resample / decimate to the current source rate
-
- if (stepscale == 1/* && inwidth == 1*/ && sc->width == 1)
- {
-// fast special case
- /*
- // LordHavoc: I do not serve the readability gods...
- int *indata, *outdata;
- int count4, count1;
- count1 = outcount << sc->stereo;
- count4 = count1 >> 2;
- indata = (void *)data;
- outdata = (void *)sc->data;
- while (count4--)
- *outdata++ = *indata++ ^ 0x80808080;
- if (count1 & 2)
- ((short*)outdata)[0] = ((short*)indata)[0] ^ 0x8080;
- if (count1 & 1)
- ((char*)outdata)[2] = ((char*)indata)[2] ^ 0x80;
- */
- if (sc->stereo) // LordHavoc: stereo sound support
- outcount *= 2;
- for (i=0 ; i<outcount ; i++)
- ((signed char *)sc->data)[i] = ((unsigned char *)data)[i] - 128;
- }
- else if (stepscale == 1/* && inwidth == 2*/ && sc->width == 2) // LordHavoc: quick case for 16bit
+ size_t srclength, outcount;
+
+ srclength = in_length * in_format->channels;
+ outcount = (double)in_length * shm->format.speed / in_format->speed;
+
+ //Con_DPrintf("ResampleSfx(%s): %d samples @ %dHz -> %d samples @ %dHz\n",
+ // sfxname, in_length, in_format->speed, outcount, shm->format.speed);
+
+ // Trivial case (direct transfer)
+ if (in_format->speed == shm->format.speed)