Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
dquakeplus' snd_mix.c
Browse files Browse the repository at this point in the history
  • Loading branch information
MotoLegacy committed Sep 6, 2024
1 parent 7d66725 commit 142407d
Showing 1 changed file with 20 additions and 121 deletions.
141 changes: 20 additions & 121 deletions source/snd_mix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
}


Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -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;
Expand All @@ -341,27 +244,25 @@ 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++)
{
data = sfx[i];
paintbuffer[i].left += lscale[data];
paintbuffer[i].right += rscale[data];
}

ch->pos += count;
}

Expand All @@ -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;

Expand Down

0 comments on commit 142407d

Please sign in to comment.