#define DWORD unsigned long
#endif
-#define PAINTBUFFER_SIZE 512
+// LordHavoc: was 512, expanded to 2048
+#define PAINTBUFFER_SIZE 2048
portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE];
int snd_scaletable[32][256];
int *snd_p, snd_linear_count, snd_vol;
void Snd_WriteLinearBlastStereo16 (void);
-extern cvar_t snd_swapstereo;
void Snd_WriteLinearBlastStereo16 (void)
{
int i;
for (i=0 ; i<snd_linear_count ; i+=2)
{
val = (snd_p[i+1]*snd_vol)>>8;
- if (val > 0x7fff)
- snd_out[i] = 0x7fff;
- else if (val < (short)0x8000)
- snd_out[i] = (short)0x8000;
- else
- snd_out[i] = val;
-
- val = (snd_p[i]*snd_vol)>>8;
- if (val > 0x7fff)
- snd_out[i+1] = 0x7fff;
- else if (val < (short)0x8000)
- snd_out[i+1] = (short)0x8000;
- else
- snd_out[i+1] = val;
+ snd_out[i ] = bound(-32768, val, 32767);
+ val = (snd_p[i ]*snd_vol)>>8;
+ snd_out[i+1] = bound(-32768, val, 32767);
}
}
else
for (i=0 ; i<snd_linear_count ; i+=2)
{
val = (snd_p[i]*snd_vol)>>8;
- if (val > 0x7fff)
- snd_out[i] = 0x7fff;
- else if (val < (short)0x8000)
- snd_out[i] = (short)0x8000;
- else
- snd_out[i] = val;
-
+ snd_out[i] = bound(-32768, val, 32767);
val = (snd_p[i+1]*snd_vol)>>8;
- if (val > 0x7fff)
- snd_out[i+1] = 0x7fff;
- else if (val < (short)0x8000)
- snd_out[i+1] = (short)0x8000;
- else
- snd_out[i+1] = val;
+ snd_out[i+1] = bound(-32768, val, 32767);
}
}
}
{
reps = 0;
- while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pbuf, &dwSize,
- &pbuf2, &dwSize2, 0)) != DS_OK)
+ while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pbuf, &dwSize, &pbuf2, &dwSize2, 0)) != DS_OK)
{
if (hresult != DSERR_BUFFERLOST)
{
{
reps = 0;
- while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pbuf, &dwSize,
- &pbuf2,&dwSize2, 0)) != DS_OK)
+ while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pbuf, &dwSize, &pbuf2,&dwSize2, 0)) != DS_OK)
{
if (hresult != DSERR_BUFFERLOST)
{
while (count--)
{
val = (*p * snd_vol) >> 8;
+ out[out_idx] = bound(-32768, val, 32767);
p+= step;
- if (val > 0x7fff)
- val = 0x7fff;
- else if (val < (short)0x8000)
- val = (short)0x8000;
- out[out_idx] = val;
out_idx = (out_idx + 1) & out_mask;
}
}
unsigned char *out = (unsigned char *) pbuf;
while (count--)
{
- val = (*p * snd_vol) >> 8;
+ val = ((*p * snd_vol) >> 16) + 128;
+ out[out_idx] = bound(0, val, 255);
p+= step;
- if (val > 0x7fff)
- val = 0x7fff;
- else if (val < (short)0x8000)
- val = (short)0x8000;
- out[out_idx] = (val>>8) + 128;
out_idx = (out_idx + 1) & out_mask;
}
}
#ifdef _WIN32
- if (pDSBuf) {
+ if (pDSBuf)
+ {
DWORD dwNewpos, dwWrite;
int il = paintedtime;
int ir = endtime - paintedtime;
while (paintedtime < endtime)
{
- // if paintbuffer is smaller than DMA buffer
+ // if paintbuffer is smaller than DMA buffer
end = endtime;
if (endtime - paintedtime > PAINTBUFFER_SIZE)
end = paintedtime + PAINTBUFFER_SIZE;
- // clear the paint buffer
+ // clear the paint buffer
memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
- // paint in the channels.
+ // paint in the channels.
ch = channels;
for (i=0; i<total_channels ; i++, ch++)
{
ltime = paintedtime;
while (ltime < end)
- { // paint up to end
+ {
+ // paint up to end
if (ch->end < end)
count = ch->end - ltime;
else
ltime += count;
}
- // if at end of loop, restart
+ // if at end of loop, restart
if (ltime >= ch->end)
{
if (sc->loopstart >= 0)
ch->end = ltime + sc->length - ch->pos;
}
else
- { // channel just stopped
+ {
+ // channel just stopped
ch->sfx = NULL;
break;
}
}
- // transfer out according to DMA format
+ // transfer out according to DMA format
S_TransferPaintBuffer(end);
paintedtime = end;
}
ch->leftvol = 255;
if (ch->rightvol > 255)
ch->rightvol = 255;
-
+
lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3];
- if (sc->stereo) // LordHavoc: stereo sound support, and optimizations
+ if (sc->stereo)
{
+ // LordHavoc: stereo sound support, and optimizations
sfx = (unsigned char *)sc->data + ch->pos * 2;
for (i=0 ; i<count ; i++)
leftvol = ch->leftvol;
rightvol = ch->rightvol;
- if (sc->stereo) // LordHavoc: stereo sound support, and optimizations
+ if (sc->stereo)
{
+ // LordHavoc: stereo sound support, and optimizations
sfx = (signed short *)sc->data + ch->pos * 2;
for (i=0 ; i<count ; i++)
{
- paintbuffer[i].left += (short) ((int) (*sfx++ * leftvol) >> 8);
- paintbuffer[i].right += (short) ((int) (*sfx++ * rightvol) >> 8);
+ paintbuffer[i].left += (*sfx++ * leftvol) >> 8;
+ paintbuffer[i].right += (*sfx++ * rightvol) >> 8;
}
}
else
for (i=0 ; i<count ; i++)
{
- paintbuffer[i].left += (short) ((int) (*sfx * leftvol) >> 8);
- paintbuffer[i].right += (short) ((int) (*sfx++ * rightvol) >> 8);
+ paintbuffer[i].left += (*sfx * leftvol) >> 8;
+ paintbuffer[i].right += (*sfx++ * rightvol) >> 8;
}
}