2004-08-23 00:15:46 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// snd_mix.c -- portable code to mix sounds for snd_dma.c
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
|
|
|
#ifndef NOSOUNDASM
|
|
|
|
#define NOSOUNDASM //since channels per sound card went to 6 (portable_samplegroup_t was changed)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PAINTBUFFER_SIZE 2048
|
2006-05-09 07:26:14 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
portable_samplegroup_t paintbuffer[PAINTBUFFER_SIZE];
|
2006-05-09 07:26:14 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
int *snd_p, snd_vol;
|
|
|
|
short *snd_out;
|
|
|
|
|
2006-05-09 07:26:14 +00:00
|
|
|
static int paintskip[6][6] =
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2006-05-09 07:26:14 +00:00
|
|
|
{6},
|
|
|
|
{1, 5},
|
|
|
|
{1, 1, 4},
|
|
|
|
{1, 1, 1, 3},
|
|
|
|
{1, 1, 1, 1, 2},
|
|
|
|
{1, 1, 1, 1, 1, 1}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int chnskip[6][6] =
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2006-05-09 07:26:14 +00:00
|
|
|
{0},
|
|
|
|
{1, -1},
|
|
|
|
{1, 1, -2},
|
|
|
|
{1, 1, 1, -3},
|
|
|
|
{1, 1, 1, 1, -4},
|
|
|
|
{1, 1, 1, 1, 1, -5}
|
|
|
|
};
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
void S_TransferPaintBuffer(soundcardinfo_t *sc, int endtime)
|
|
|
|
{
|
2007-10-03 09:09:08 +00:00
|
|
|
unsigned int startidx, out_idx;
|
|
|
|
unsigned int count;
|
|
|
|
unsigned int outlimit;
|
|
|
|
int *p;
|
|
|
|
int *skip;
|
|
|
|
int *cskip;
|
|
|
|
int val;
|
|
|
|
int snd_vol;
|
|
|
|
short *pbuf;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
p = (int *) paintbuffer;
|
2006-05-09 07:26:14 +00:00
|
|
|
skip = paintskip[sc->sn.numchannels-1];
|
|
|
|
cskip = chnskip[sc->sn.numchannels-1];
|
2004-08-23 00:15:46 +00:00
|
|
|
count = (endtime - sc->paintedtime) * sc->sn.numchannels;
|
2006-05-09 19:29:14 +00:00
|
|
|
outlimit = sc->sn.samples;
|
|
|
|
startidx = out_idx = (sc->paintedtime * sc->sn.numchannels) % outlimit;
|
2004-08-23 00:15:46 +00:00
|
|
|
snd_vol = volume.value*256;
|
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
pbuf = sc->Lock(sc);
|
|
|
|
if (!pbuf)
|
|
|
|
return;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
if (sc->sn.samplebits == 16)
|
|
|
|
{
|
|
|
|
short *out = (short *) pbuf;
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
val = (*p * snd_vol) >> 8;
|
2006-05-09 07:26:14 +00:00
|
|
|
p += *skip;
|
2004-08-23 00:15:46 +00:00
|
|
|
if (val > 0x7fff)
|
|
|
|
val = 0x7fff;
|
|
|
|
else if (val < (short)0x8000)
|
|
|
|
val = (short)0x8000;
|
|
|
|
out[out_idx] = val;
|
2006-05-09 19:29:14 +00:00
|
|
|
out_idx = (out_idx + 1) % outlimit;
|
2006-05-09 07:26:14 +00:00
|
|
|
skip += *cskip;
|
|
|
|
cskip += *cskip;
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
else if (sc->sn.samplebits == 8)
|
|
|
|
{
|
|
|
|
unsigned char *out = (unsigned char *) pbuf;
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
val = (*p * snd_vol) >> 8;
|
2006-05-09 07:26:14 +00:00
|
|
|
p += *skip;
|
2004-08-23 00:15:46 +00:00
|
|
|
if (val > 0x7fff)
|
|
|
|
val = 0x7fff;
|
|
|
|
else if (val < (short)0x8000)
|
|
|
|
val = (short)0x8000;
|
|
|
|
out[out_idx] = (val>>8) + 128;
|
2006-05-09 19:30:57 +00:00
|
|
|
out_idx = (out_idx + 1) % outlimit;
|
2006-05-09 07:26:14 +00:00
|
|
|
skip += *cskip;
|
|
|
|
cskip += *cskip;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
sc->Unlock(sc, pbuf);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
CHANNEL MIXING
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int endtime);
|
|
|
|
void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int endtime);
|
|
|
|
void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count);
|
|
|
|
void SND_PaintChannelFrom16_4Speaker (channel_t *ch, sfxcache_t *sc, int count);
|
|
|
|
void SND_PaintChannelFrom8_6Speaker (channel_t *ch, sfxcache_t *sc, int count);
|
|
|
|
void SND_PaintChannelFrom16_6Speaker (channel_t *ch, sfxcache_t *sc, int count);
|
|
|
|
void SND_PaintChannelFrom8Stereo (channel_t *ch, sfxcache_t *sc, int count);
|
|
|
|
void SND_PaintChannelFrom16Stereo (channel_t *ch, sfxcache_t *sc, int count);
|
|
|
|
|
|
|
|
void S_PaintChannels(soundcardinfo_t *sc, int endtime)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int end;
|
|
|
|
channel_t *ch;
|
|
|
|
sfxcache_t *scache;
|
|
|
|
sfx_t *s;
|
|
|
|
int ltime, count;
|
|
|
|
|
|
|
|
// sc->rawstart += sc->paintedtime - sc->oldpaintedtime;
|
|
|
|
// sc->oldpaintedtime = sc->paintedtime;
|
|
|
|
while (sc->paintedtime < endtime)
|
|
|
|
{
|
|
|
|
// if paintbuffer is smaller than DMA buffer
|
|
|
|
end = endtime;
|
|
|
|
if (endtime - sc->paintedtime > PAINTBUFFER_SIZE)
|
|
|
|
end = sc->paintedtime + PAINTBUFFER_SIZE;
|
|
|
|
|
|
|
|
// clear the paint buffer
|
|
|
|
Q_memset(paintbuffer, 0, (end - sc->paintedtime) * sizeof(portable_samplegroup_t));
|
|
|
|
|
|
|
|
// paint in the channels.
|
|
|
|
ch = sc->channel;
|
|
|
|
for (i=0; i<sc->total_chans ; i++, ch++)
|
|
|
|
{
|
|
|
|
if (!ch->sfx)
|
|
|
|
continue;
|
|
|
|
if (!ch->vol[0] && !ch->vol[1] && !ch->vol[2] && !ch->vol[3] && !ch->vol[4] && !ch->vol[5])
|
|
|
|
continue;
|
2004-10-04 07:25:05 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
scache = S_LoadSound (ch->sfx);
|
|
|
|
if (!scache)
|
|
|
|
continue;
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if ((ch->pos>>PITCHSHIFT) > scache->length) //cache was flushed and gamedir changed.
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-11-06 23:05:29 +00:00
|
|
|
ch->pos = scache->length*ch->rate;
|
|
|
|
ch->end = scache->length*ch->rate;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ltime = sc->paintedtime;
|
|
|
|
|
|
|
|
if (ch->sfx->decoder)
|
|
|
|
{
|
2005-04-16 16:21:27 +00:00
|
|
|
int len_diff;
|
2004-08-23 00:15:46 +00:00
|
|
|
soundcardinfo_t *sndc;
|
|
|
|
#define qmax(x, y) (x>y)?(x):(y)
|
2005-04-16 16:21:27 +00:00
|
|
|
len_diff = scache->length;
|
2005-05-26 12:55:34 +00:00
|
|
|
// start = ch->end - scache->length;
|
|
|
|
// samples = end - start;
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
#pragma message("pitch fix needed")
|
2004-08-23 00:15:46 +00:00
|
|
|
ch->sfx->decoder->decodemore(ch->sfx,
|
2005-05-26 12:55:34 +00:00
|
|
|
end - (ch->end - scache->length) + 1);
|
|
|
|
// ch->pos + end-ltime+1);
|
2005-04-16 16:21:27 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
scache = S_LoadSound (ch->sfx);
|
|
|
|
if (!scache)
|
|
|
|
continue;
|
2005-04-16 16:21:27 +00:00
|
|
|
len_diff = scache->length - len_diff;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
for (sndc = sndcardinfo; sndc; sndc=sndc->next)
|
|
|
|
{
|
|
|
|
for (j = 0; j < sndc->total_chans; j++)
|
|
|
|
if (sndc->channel[j].sfx == ch->sfx) //extend all of these.
|
2010-11-06 23:05:29 +00:00
|
|
|
ch->end += len_diff*ch->rate;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ltime < end)
|
|
|
|
{ // paint up to end
|
|
|
|
if (ch->end < end)
|
|
|
|
count = ch->end - ltime;
|
|
|
|
else
|
|
|
|
count = end - ltime;
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
if (ch->pos < 0) //delay the sound a little
|
|
|
|
{
|
|
|
|
if (count > -ch->pos)
|
|
|
|
count = -ch->pos;
|
|
|
|
ltime += count;
|
2010-11-06 23:05:29 +00:00
|
|
|
ch->pos += count*ch->rate;
|
2004-08-23 00:15:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-05-08 21:02:39 +00:00
|
|
|
if (scache->width == 1)
|
|
|
|
{
|
|
|
|
if (scache->numchannels==2)
|
|
|
|
SND_PaintChannelFrom8Stereo(ch, scache, count);
|
|
|
|
else if (sc->sn.numchannels == 6)
|
|
|
|
SND_PaintChannelFrom8_6Speaker(ch, scache, count);
|
|
|
|
else if (sc->sn.numchannels == 4)
|
|
|
|
SND_PaintChannelFrom8_4Speaker(ch, scache, count);
|
|
|
|
else
|
|
|
|
SND_PaintChannelFrom8(ch, scache, count);
|
|
|
|
}
|
|
|
|
else
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2006-05-08 21:02:39 +00:00
|
|
|
if (scache->numchannels==2)
|
|
|
|
SND_PaintChannelFrom16Stereo(ch, scache, count);
|
|
|
|
else if (sc->sn.numchannels == 6)
|
|
|
|
SND_PaintChannelFrom16_6Speaker(ch, scache, count);
|
|
|
|
else if (sc->sn.numchannels == 4)
|
|
|
|
SND_PaintChannelFrom16_4Speaker(ch, scache, count);
|
2004-08-23 00:15:46 +00:00
|
|
|
else
|
2006-05-08 21:02:39 +00:00
|
|
|
SND_PaintChannelFrom16(ch, scache, count);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
ltime += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if at end of loop, restart
|
|
|
|
if (ltime >= ch->end)
|
|
|
|
{
|
|
|
|
if (scache->loopstart >= 0)
|
|
|
|
{
|
2005-07-14 01:57:34 +00:00
|
|
|
if (scache->length == scache->loopstart)
|
2006-05-08 21:02:39 +00:00
|
|
|
break;
|
2010-11-06 23:05:29 +00:00
|
|
|
ch->pos = scache->loopstart*ch->rate;
|
|
|
|
ch->end = ltime + ((scache->length - scache->loopstart)<<PITCHSHIFT)/ch->rate;
|
2004-08-23 00:15:46 +00:00
|
|
|
if (!scache->length)
|
|
|
|
{
|
|
|
|
scache->loopstart=-1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-11-23 00:18:51 +00:00
|
|
|
else if (ch->looping && scache->length)
|
|
|
|
{
|
|
|
|
ch->pos = 0;
|
2010-11-06 23:05:29 +00:00
|
|
|
ch->end = ltime + ((scache->length)<<PITCHSHIFT)/ch->rate;
|
2004-11-23 00:18:51 +00:00
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
else
|
|
|
|
{ // channel just stopped
|
|
|
|
s = ch->sfx;
|
|
|
|
ch->sfx = NULL;
|
|
|
|
if (s->decoder)
|
|
|
|
{
|
|
|
|
if (!S_IsPlayingSomewhere(s))
|
|
|
|
s->decoder->abort(s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// transfer out according to DMA format
|
|
|
|
S_TransferPaintBuffer(sc, end);
|
|
|
|
sc->paintedtime = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
|
|
|
|
{
|
|
|
|
int data;
|
2006-05-08 21:02:39 +00:00
|
|
|
signed char *sfx;
|
2004-08-23 00:15:46 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ch->vol[0] > 255)
|
|
|
|
ch->vol[0] = 255;
|
|
|
|
if (ch->vol[1] > 255)
|
|
|
|
ch->vol[1] = 255;
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if (ch->rate != (1<<PITCHSHIFT))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-11-06 23:05:29 +00:00
|
|
|
sfx = (signed char *)sc->data;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
data = sfx[ch->pos>>PITCHSHIFT];
|
|
|
|
ch->pos += ch->rate;
|
|
|
|
paintbuffer[i].s[0] += ch->vol[0] * data;
|
|
|
|
paintbuffer[i].s[1] += ch->vol[1] * data;
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
2010-11-06 23:05:29 +00:00
|
|
|
else
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-11-06 23:05:29 +00:00
|
|
|
sfx = (signed char *)sc->data + (ch->pos>>PITCHSHIFT);
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
data = sfx[i];
|
|
|
|
paintbuffer[i].s[0] += ch->vol[0] * data;
|
|
|
|
paintbuffer[i].s[1] += ch->vol[1] * data;
|
|
|
|
}
|
|
|
|
ch->pos += count<<PITCHSHIFT;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom8Stereo (channel_t *ch, sfxcache_t *sc, int count)
|
|
|
|
{
|
|
|
|
// int data;
|
2006-05-08 21:02:39 +00:00
|
|
|
signed char *sfx;
|
2004-08-23 00:15:46 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ch->vol[0] > 255)
|
|
|
|
ch->vol[0] = 255;
|
|
|
|
if (ch->vol[1] > 255)
|
|
|
|
ch->vol[1] = 255;
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if (ch->rate != (1<<PITCHSHIFT))
|
|
|
|
{
|
|
|
|
sfx = (signed char *)sc->data;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
paintbuffer[i].s[0] += ch->vol[0] * sfx[(ch->pos>>(PITCHSHIFT-1))&~1];
|
|
|
|
paintbuffer[i].s[1] += ch->vol[1] * sfx[(ch->pos>>(PITCHSHIFT-1))|1];
|
|
|
|
ch->pos += ch->rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sfx = (signed char *)sc->data + (ch->pos>>PITCHSHIFT)*2;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
paintbuffer[i].s[0] += ch->vol[0] * sfx[(i<<1)];
|
|
|
|
paintbuffer[i].s[1] += ch->vol[1] * sfx[(i<<1)+1];
|
|
|
|
}
|
|
|
|
ch->pos += count<<PITCHSHIFT;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count)
|
|
|
|
{
|
2006-05-08 21:02:39 +00:00
|
|
|
signed char *sfx;
|
2004-08-23 00:15:46 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ch->vol[0] > 255)
|
|
|
|
ch->vol[0] = 255;
|
|
|
|
if (ch->vol[1] > 255)
|
|
|
|
ch->vol[1] = 255;
|
|
|
|
if (ch->vol[2] > 255)
|
|
|
|
ch->vol[2] = 255;
|
|
|
|
if (ch->vol[3] > 255)
|
|
|
|
ch->vol[3] = 255;
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if (ch->rate != (1<<PITCHSHIFT))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-11-06 23:05:29 +00:00
|
|
|
signed char data;
|
|
|
|
sfx = (signed char *)sc->data;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
data = sfx[ch->pos>>PITCHSHIFT];
|
|
|
|
ch->pos += ch->rate;
|
|
|
|
paintbuffer[i].s[0] += ch->vol[0] * data;
|
|
|
|
paintbuffer[i].s[1] += ch->vol[1] * data;
|
|
|
|
paintbuffer[i].s[2] += ch->vol[2] * data;
|
|
|
|
paintbuffer[i].s[3] += ch->vol[3] * data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sfx = (signed char *)sc->data + (ch->pos>>PITCHSHIFT);
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
paintbuffer[i].s[0] += ch->vol[0] * sfx[i];
|
|
|
|
paintbuffer[i].s[1] += ch->vol[1] * sfx[i];
|
|
|
|
paintbuffer[i].s[2] += ch->vol[2] * sfx[i];
|
|
|
|
paintbuffer[i].s[3] += ch->vol[3] * sfx[i];
|
|
|
|
}
|
|
|
|
ch->pos += count<<PITCHSHIFT;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom8_6Speaker (channel_t *ch, sfxcache_t *sc, int count)
|
|
|
|
{
|
2006-05-08 21:02:39 +00:00
|
|
|
signed char *sfx;
|
2004-08-23 00:15:46 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ch->vol[0] > 255)
|
|
|
|
ch->vol[0] = 255;
|
|
|
|
if (ch->vol[1] > 255)
|
|
|
|
ch->vol[1] = 255;
|
|
|
|
if (ch->vol[2] > 255)
|
|
|
|
ch->vol[2] = 255;
|
|
|
|
if (ch->vol[3] > 255)
|
|
|
|
ch->vol[3] = 255;
|
|
|
|
if (ch->vol[4] > 255)
|
|
|
|
ch->vol[4] = 255;
|
|
|
|
if (ch->vol[5] > 255)
|
|
|
|
ch->vol[5] = 255;
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if (ch->rate != (1<<PITCHSHIFT))
|
|
|
|
{
|
|
|
|
signed char data;
|
|
|
|
sfx = (signed char *)sc->data;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
data = sfx[ch->pos>>PITCHSHIFT];
|
|
|
|
ch->pos += ch->rate;
|
|
|
|
paintbuffer[i].s[0] += ch->vol[0] * data;
|
|
|
|
paintbuffer[i].s[1] += ch->vol[1] * data;
|
|
|
|
paintbuffer[i].s[2] += ch->vol[2] * data;
|
|
|
|
paintbuffer[i].s[3] += ch->vol[3] * data;
|
|
|
|
paintbuffer[i].s[4] += ch->vol[4] * data;
|
|
|
|
paintbuffer[i].s[5] += ch->vol[5] * data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sfx = (signed char *)sc->data + (ch->pos>>PITCHSHIFT);
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
paintbuffer[i].s[0] += ch->vol[0] * sfx[i];
|
|
|
|
paintbuffer[i].s[1] += ch->vol[1] * sfx[i];
|
|
|
|
paintbuffer[i].s[2] += ch->vol[2] * sfx[i];
|
|
|
|
paintbuffer[i].s[3] += ch->vol[3] * sfx[i];
|
|
|
|
paintbuffer[i].s[4] += ch->vol[4] * sfx[i];
|
|
|
|
paintbuffer[i].s[5] += ch->vol[5] * sfx[i];
|
|
|
|
}
|
|
|
|
ch->pos += count<<PITCHSHIFT;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
|
|
|
|
{
|
|
|
|
int data;
|
|
|
|
int left, right;
|
|
|
|
int leftvol, rightvol;
|
|
|
|
signed short *sfx;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
leftvol = ch->vol[0];
|
|
|
|
rightvol = ch->vol[1];
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if (ch->rate != (1<<PITCHSHIFT))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-11-06 23:05:29 +00:00
|
|
|
signed short data;
|
|
|
|
sfx = (signed short *)sc->data;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
data = sfx[ch->pos>>PITCHSHIFT];
|
|
|
|
ch->pos += ch->rate;
|
|
|
|
paintbuffer[i].s[0] += (leftvol * data)>>8;
|
|
|
|
paintbuffer[i].s[1] += (rightvol * data)>>8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sfx = (signed short *)sc->data + (ch->pos>>PITCHSHIFT);
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
data = sfx[i];
|
|
|
|
left = (data * leftvol) >> 8;
|
|
|
|
right = (data * rightvol) >> 8;
|
|
|
|
paintbuffer[i].s[0] += left;
|
|
|
|
paintbuffer[i].s[1] += right;
|
|
|
|
}
|
|
|
|
ch->pos += count<<PITCHSHIFT;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom16Stereo (channel_t *ch, sfxcache_t *sc, int count)
|
|
|
|
{
|
|
|
|
int leftvol, rightvol;
|
|
|
|
signed short *sfx;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
leftvol = ch->vol[0];
|
|
|
|
rightvol = ch->vol[1];
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if (ch->rate != (1<<PITCHSHIFT))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-11-06 23:05:29 +00:00
|
|
|
signed short l, r;
|
|
|
|
sfx = (signed short *)sc->data;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
l = sfx[(ch->pos>>(PITCHSHIFT-1))&~1];
|
|
|
|
r = sfx[(ch->pos>>(PITCHSHIFT-1))|1];
|
|
|
|
ch->pos += ch->rate;
|
|
|
|
paintbuffer[i].s[0] += (ch->vol[0] * l)>>8;
|
|
|
|
paintbuffer[i].s[1] += (ch->vol[1] * r)>>8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sfx = (signed short *)sc->data + (ch->pos>>PITCHSHIFT)*2;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
paintbuffer[i].s[0] += (*sfx++ * leftvol) >> 8;
|
|
|
|
paintbuffer[i].s[1] += (*sfx++ * rightvol) >> 8;
|
|
|
|
}
|
|
|
|
ch->pos += count<<PITCHSHIFT;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom16_6Speaker (channel_t *ch, sfxcache_t *sc, int count)
|
|
|
|
{
|
|
|
|
int vol[6];
|
|
|
|
signed short *sfx;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
vol[0] = ch->vol[0];
|
|
|
|
vol[1] = ch->vol[1];
|
|
|
|
vol[2] = ch->vol[2];
|
|
|
|
vol[3] = ch->vol[3];
|
|
|
|
vol[4] = ch->vol[4];
|
|
|
|
vol[5] = ch->vol[5];
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if (ch->rate != (1<<PITCHSHIFT))
|
|
|
|
{
|
|
|
|
signed short data;
|
|
|
|
sfx = (signed short *)sc->data;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
data = sfx[ch->pos>>PITCHSHIFT];
|
|
|
|
ch->pos += ch->rate;
|
|
|
|
paintbuffer[i].s[0] += (vol[0] * data)>>8;
|
|
|
|
paintbuffer[i].s[1] += (vol[1] * data)>>8;
|
|
|
|
paintbuffer[i].s[2] += (vol[2] * data)>>8;
|
|
|
|
paintbuffer[i].s[3] += (vol[3] * data)>>8;
|
|
|
|
paintbuffer[i].s[4] += (vol[4] * data)>>8;
|
|
|
|
paintbuffer[i].s[5] += (vol[5] * data)>>8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-11-06 23:05:29 +00:00
|
|
|
sfx = (signed short *)sc->data + (ch->pos>>PITCHSHIFT);
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
paintbuffer[i].s[0] += (sfx[i] * vol[0]) >> 8;
|
|
|
|
paintbuffer[i].s[1] += (sfx[i] * vol[1]) >> 8;
|
|
|
|
paintbuffer[i].s[2] += (sfx[i] * vol[2]) >> 8;
|
|
|
|
paintbuffer[i].s[3] += (sfx[i] * vol[3]) >> 8;
|
|
|
|
paintbuffer[i].s[4] += (sfx[i] * vol[4]) >> 8;
|
|
|
|
paintbuffer[i].s[5] += (sfx[i] * vol[5]) >> 8;
|
|
|
|
}
|
|
|
|
ch->pos += count<<PITCHSHIFT;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SND_PaintChannelFrom16_4Speaker (channel_t *ch, sfxcache_t *sc, int count)
|
|
|
|
{
|
|
|
|
int vol[4];
|
|
|
|
signed short *sfx;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
vol[0] = ch->vol[0];
|
|
|
|
vol[1] = ch->vol[1];
|
|
|
|
vol[2] = ch->vol[2];
|
|
|
|
vol[3] = ch->vol[3];
|
|
|
|
|
2010-11-06 23:05:29 +00:00
|
|
|
if (ch->rate != (1<<PITCHSHIFT))
|
|
|
|
{
|
|
|
|
signed short data;
|
|
|
|
sfx = (signed short *)sc->data;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
data = sfx[ch->pos>>PITCHSHIFT];
|
|
|
|
ch->pos += ch->rate;
|
|
|
|
paintbuffer[i].s[0] += (vol[0] * data)>>8;
|
|
|
|
paintbuffer[i].s[1] += (vol[1] * data)>>8;
|
|
|
|
paintbuffer[i].s[2] += (vol[2] * data)>>8;
|
|
|
|
paintbuffer[i].s[3] += (vol[3] * data)>>8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-11-06 23:05:29 +00:00
|
|
|
sfx = (signed short *)sc->data + ch->pos;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
|
|
{
|
|
|
|
paintbuffer[i].s[0] += (sfx[i] * vol[0]) >> 8;
|
|
|
|
paintbuffer[i].s[1] += (sfx[i] * vol[1]) >> 8;
|
|
|
|
paintbuffer[i].s[2] += (sfx[i] * vol[2]) >> 8;
|
|
|
|
paintbuffer[i].s[3] += (sfx[i] * vol[3]) >> 8;
|
|
|
|
}
|
|
|
|
ch->pos += count<<PITCHSHIFT;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|