-// general case
- Con_DPrintf("ResampleSfx: resampling sound %s\n", sfx->name);
- samplefrac = 0;
- fracstep = stepscale*256;
- if ((fracstep & 255) == 0) // skipping points on perfect multiple
- {
- srcsample = 0;
- fracstep >>= 8;
- if (sc->width == 2)
- {
- short *out = (void *)sc->data, *in = (void *)data;
- if (sc->stereo) // LordHavoc: stereo sound support
- {
- fracstep <<= 1;
- for (i=0 ; i<outcount ;)
- {
- *out++ = (short) LittleShort (in[srcsample ]);
- *out++ = (short) LittleShort (in[srcsample+1]);
- srcsample += fracstep;
- }
- }
- else
- {
- for (i=0 ; i<outcount ; i++)
- {
- *out++ = (short) LittleShort (in[srcsample ]);
- srcsample += fracstep;
- }
- }
- }
- else
- {
- signed char *out = (void *)sc->data, *in = (void *)data;
- if (sc->stereo) // LordHavoc: stereo sound support
- {
- fracstep <<= 1;
- for (i=0 ; i<outcount ;)
- {
- *out++ = (signed char) in[srcsample ] - 128;
- *out++ = (signed char) in[srcsample+1] - 128;
- srcsample += fracstep;
- }
- }
- else
- {
- for (i=0 ; i<outcount ; i++)
- {
- *out++ = (signed char) in[srcsample ] - 128;
- srcsample += fracstep;
- }
- }
- }
- }
- else
- {
- int sample;
- if (sc->width == 2)
- {
- short *out = (void *)sc->data, *in = (void *)data;
- if (sc->stereo) // LordHavoc: stereo sound support
- {
- for (i=0 ; i<outcount ;)
- {
- srcsample = (samplefrac >> 7) & ~1;
- samplefrac += fracstep;
- sample = (LittleShort (in[srcsample ]) * (256 - (samplefrac & 255)) + LittleShort (in[srcsample+2]) * (samplefrac & 255)) >> 8;
- *out++ = (short) sample;
- sample = (LittleShort (in[srcsample+1]) * (256 - (samplefrac & 255)) + LittleShort (in[srcsample+3]) * (samplefrac & 255)) >> 8;
- *out++ = (short) sample;
- }
- }
- else
- {
- for (i=0 ; i<outcount ; i++)
- {
- srcsample = samplefrac >> 8;
- samplefrac += fracstep;
- sample = (LittleShort (in[srcsample ]) * (256 - (samplefrac & 255)) + LittleShort (in[srcsample+1]) * (samplefrac & 255)) >> 8;
- *out++ = (short) sample;
- }
- }
- }
- else
- {
- signed char *out = (void *)sc->data, *in = (void *)data;
- if (sc->stereo) // LordHavoc: stereo sound support
- {
- for (i=0 ; i<outcount ;)
- {
- srcsample = (samplefrac >> 7) & ~1;
- samplefrac += fracstep;
- sample = ((((unsigned char) in[srcsample ] - 128) * (256 - (samplefrac & 255))) + (((unsigned char) in[srcsample+2] - 128) * (samplefrac & 255))) >> 8;
- *out++ = (signed char) sample;
- sample = ((((unsigned char) in[srcsample+1] - 128) * (256 - (samplefrac & 255))) + (((unsigned char) in[srcsample+3] - 128) * (samplefrac & 255))) >> 8;
- *out++ = (signed char) sample;
- }
- }
- else
- {
- for (i=0 ; i<outcount ; i++)
- {
- srcsample = samplefrac >> 8;
- samplefrac += fracstep;
- sample = ((((unsigned char) in[srcsample ] - 128) * (256 - (samplefrac & 255))) + (((unsigned char) in[srcsample+1] - 128) * (samplefrac & 255))) >> 8;
- *out++ = (signed char) sample;
- }
- }
- }
- }