mirror of
https://github.com/nzp-team/glquake.git
synced 2024-11-10 06:31:35 +00:00
dquakeplus' snd_mix.c
This commit is contained in:
parent
7d66725bab
commit
142407d4af
1 changed files with 20 additions and 121 deletions
141
source/snd_mix.c
141
source/snd_mix.c
|
@ -8,7 +8,7 @@ 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.
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
|
@ -34,8 +34,7 @@ void Snd_WriteLinearBlastStereo16 (void);
|
|||
#if !id386
|
||||
void Snd_WriteLinearBlastStereo16 (void)
|
||||
{
|
||||
int i;
|
||||
int val;
|
||||
int i, val;
|
||||
|
||||
for (i=0 ; i<snd_linear_count ; i+=2)
|
||||
{
|
||||
|
@ -60,48 +59,14 @@ void Snd_WriteLinearBlastStereo16 (void)
|
|||
|
||||
void S_TransferStereo16 (int endtime)
|
||||
{
|
||||
int lpos;
|
||||
int lpaintedtime;
|
||||
int lpos, lpaintedtime;
|
||||
DWORD *pbuf;
|
||||
#ifdef _WIN32
|
||||
int reps;
|
||||
DWORD dwSize,dwSize2;
|
||||
DWORD *pbuf2;
|
||||
HRESULT hresult;
|
||||
#endif
|
||||
|
||||
|
||||
snd_vol = volume.value*256;
|
||||
|
||||
snd_p = (int *) paintbuffer;
|
||||
lpaintedtime = paintedtime;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf)
|
||||
{
|
||||
reps = 0;
|
||||
|
||||
while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pbuf, &dwSize,
|
||||
&pbuf2, &dwSize2, 0)) != DS_OK)
|
||||
{
|
||||
if (hresult != DSERR_BUFFERLOST)
|
||||
{
|
||||
Con_Printf ("S_TransferStereo16: DS::Lock Sound Buffer Failed\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (++reps > 10000)
|
||||
{
|
||||
Con_Printf ("S_TransferStereo16: DS: couldn't restore buffer\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
pbuf = (DWORD *)shm->buffer;
|
||||
}
|
||||
|
@ -125,70 +90,27 @@ void S_TransferStereo16 (int endtime)
|
|||
snd_p += snd_linear_count;
|
||||
lpaintedtime += (snd_linear_count>>1);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf)
|
||||
pDSBuf->lpVtbl->Unlock(pDSBuf, pbuf, dwSize, NULL, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void S_TransferPaintBuffer(int endtime)
|
||||
{
|
||||
int out_idx;
|
||||
int count;
|
||||
int out_mask;
|
||||
int *p;
|
||||
int step;
|
||||
int val;
|
||||
int snd_vol;
|
||||
int out_idx, count, out_mask, *p, step, val, snd_vol;
|
||||
DWORD *pbuf;
|
||||
#ifdef _WIN32
|
||||
int reps;
|
||||
DWORD dwSize,dwSize2;
|
||||
DWORD *pbuf2;
|
||||
HRESULT hresult;
|
||||
#endif
|
||||
|
||||
if (shm->samplebits == 16 && shm->channels == 2)
|
||||
{
|
||||
S_TransferStereo16 (endtime);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
p = (int *) paintbuffer;
|
||||
count = (endtime - paintedtime) * shm->channels;
|
||||
out_mask = shm->samples - 1;
|
||||
out_mask = shm->samples - 1;
|
||||
out_idx = paintedtime * shm->channels & out_mask;
|
||||
step = 3 - shm->channels;
|
||||
snd_vol = volume.value*256;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf)
|
||||
{
|
||||
reps = 0;
|
||||
|
||||
while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pbuf, &dwSize,
|
||||
&pbuf2,&dwSize2, 0)) != DS_OK)
|
||||
{
|
||||
if (hresult != DSERR_BUFFERLOST)
|
||||
{
|
||||
Con_Printf ("S_TransferPaintBuffer: DS::Lock Sound Buffer Failed\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (++reps > 10000)
|
||||
{
|
||||
Con_Printf ("S_TransferPaintBuffer: DS: couldn't restore buffer\n");
|
||||
S_Shutdown ();
|
||||
S_Startup ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
pbuf = (DWORD *)shm->buffer;
|
||||
}
|
||||
|
@ -224,22 +146,6 @@ void S_TransferPaintBuffer(int endtime)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pDSBuf) {
|
||||
DWORD dwNewpos, dwWrite;
|
||||
int il = paintedtime;
|
||||
int ir = endtime - paintedtime;
|
||||
|
||||
ir += il;
|
||||
|
||||
pDSBuf->lpVtbl->Unlock(pDSBuf, pbuf, dwSize, NULL, 0);
|
||||
|
||||
pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &dwNewpos, &dwWrite);
|
||||
|
||||
// if ((dwNewpos >= il) && (dwNewpos <= ir))
|
||||
// Con_Printf("%d-%d p %d c\n", il, ir, dwNewpos);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -256,11 +162,9 @@ void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int endtime);
|
|||
|
||||
void S_PaintChannels(int endtime)
|
||||
{
|
||||
int i;
|
||||
int end;
|
||||
int i, end, ltime, count;
|
||||
channel_t *ch;
|
||||
sfxcache_t *sc;
|
||||
int ltime, count;
|
||||
|
||||
while (paintedtime < endtime)
|
||||
{
|
||||
|
@ -270,7 +174,7 @@ void S_PaintChannels(int endtime)
|
|||
end = paintedtime + PAINTBUFFER_SIZE;
|
||||
|
||||
// clear the paint buffer
|
||||
Q_memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
|
||||
memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
|
||||
|
||||
// paint in the channels.
|
||||
ch = channels;
|
||||
|
@ -280,8 +184,7 @@ void S_PaintChannels(int endtime)
|
|||
continue;
|
||||
if (!ch->leftvol && !ch->rightvol)
|
||||
continue;
|
||||
sc = S_LoadSound (ch->sfx);
|
||||
if (!sc)
|
||||
if (!(sc = S_LoadSound (ch->sfx)))
|
||||
continue;
|
||||
|
||||
ltime = paintedtime;
|
||||
|
@ -294,12 +197,12 @@ void S_PaintChannels(int endtime)
|
|||
count = end - ltime;
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
{
|
||||
if (sc->width == 1)
|
||||
SND_PaintChannelFrom8(ch, sc, count);
|
||||
else
|
||||
SND_PaintChannelFrom16(ch, sc, count);
|
||||
|
||||
|
||||
ltime += count;
|
||||
}
|
||||
|
||||
|
@ -311,14 +214,14 @@ void S_PaintChannels(int endtime)
|
|||
ch->pos = sc->loopstart;
|
||||
ch->end = ltime + sc->length - ch->pos;
|
||||
}
|
||||
else
|
||||
else
|
||||
{ // channel just stopped
|
||||
ch->sfx = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// transfer out according to DMA format
|
||||
|
@ -330,7 +233,7 @@ void S_PaintChannels(int endtime)
|
|||
void SND_InitScaletable (void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
|
||||
for (i=0 ; i<32 ; i++)
|
||||
for (j=0 ; j<256 ; j++)
|
||||
snd_scaletable[i][j] = ((signed char)j) * i * 8;
|
||||
|
@ -341,19 +244,17 @@ void SND_InitScaletable (void)
|
|||
|
||||
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
|
||||
{
|
||||
int data;
|
||||
int *lscale, *rscale;
|
||||
int i, data, *lscale, *rscale;
|
||||
unsigned char *sfx;
|
||||
int i;
|
||||
|
||||
if (ch->leftvol > 255)
|
||||
ch->leftvol = 255;
|
||||
if (ch->rightvol > 255)
|
||||
ch->rightvol = 255;
|
||||
|
||||
|
||||
lscale = snd_scaletable[ch->leftvol >> 3];
|
||||
rscale = snd_scaletable[ch->rightvol >> 3];
|
||||
sfx = (signed char *)sc->data + ch->pos;
|
||||
sfx = (unsigned char *)sc->data + ch->pos;
|
||||
|
||||
for (i=0 ; i<count ; i++)
|
||||
{
|
||||
|
@ -361,7 +262,7 @@ void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
|
|||
paintbuffer[i].left += lscale[data];
|
||||
paintbuffer[i].right += rscale[data];
|
||||
}
|
||||
|
||||
|
||||
ch->pos += count;
|
||||
}
|
||||
|
||||
|
@ -370,9 +271,7 @@ void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
|
|||
|
||||
void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
|
||||
{
|
||||
int data;
|
||||
int left, right;
|
||||
int leftvol, rightvol;
|
||||
int data, left, right, leftvol, rightvol;
|
||||
signed short *sfx;
|
||||
int i;
|
||||
|
||||
|
|
Loading…
Reference in a new issue