Reduce the use of the dsound global variable by passing address to

functions.
oldstable
Robert Reif 2004-01-12 21:02:22 +00:00 committed by Alexandre Julliard
parent e8283089cb
commit 370a18f786
2 changed files with 26 additions and 25 deletions

View File

@ -382,7 +382,7 @@ void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb); void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos); void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq); void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
void DSOUND_PerformMix(void); void DSOUND_PerformMix(IDirectSoundImpl *dsound);
void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2); void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2); void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

View File

@ -147,8 +147,8 @@ static inline void cp_fields(const IDirectSoundBufferImpl *dsb, BYTE *ibuf, BYTE
INT fl,fr; INT fl,fr;
if (dsb->wfx.wBitsPerSample == 8) { if (dsb->wfx.wBitsPerSample == 8) {
if (dsound->wfx.wBitsPerSample == 8 && if (dsb->dsound->wfx.wBitsPerSample == 8 &&
dsound->wfx.nChannels == dsb->wfx.nChannels) { dsb->dsound->wfx.nChannels == dsb->wfx.nChannels) {
/* avoid needless 8->16->8 conversion */ /* avoid needless 8->16->8 conversion */
*obuf=*ibuf; *obuf=*ibuf;
if (dsb->wfx.nChannels==2) if (dsb->wfx.nChannels==2)
@ -162,25 +162,25 @@ static inline void cp_fields(const IDirectSoundBufferImpl *dsb, BYTE *ibuf, BYTE
fr = (dsb->wfx.nChannels==2 ? *(((INT16 *)ibuf) + 1) : fl); fr = (dsb->wfx.nChannels==2 ? *(((INT16 *)ibuf) + 1) : fl);
} }
if (dsound->wfx.nChannels == 2) { if (dsb->dsound->wfx.nChannels == 2) {
if (dsound->wfx.wBitsPerSample == 8) { if (dsb->dsound->wfx.wBitsPerSample == 8) {
*obuf = cvtS16toU8(fl); *obuf = cvtS16toU8(fl);
*(obuf + 1) = cvtS16toU8(fr); *(obuf + 1) = cvtS16toU8(fr);
return; return;
} }
if (dsound->wfx.wBitsPerSample == 16) { if (dsb->dsound->wfx.wBitsPerSample == 16) {
*((INT16 *)obuf) = fl; *((INT16 *)obuf) = fl;
*(((INT16 *)obuf) + 1) = fr; *(((INT16 *)obuf) + 1) = fr;
return; return;
} }
} }
if (dsound->wfx.nChannels == 1) { if (dsb->dsound->wfx.nChannels == 1) {
fl = (fl + fr) >> 1; fl = (fl + fr) >> 1;
if (dsound->wfx.wBitsPerSample == 8) { if (dsb->dsound->wfx.wBitsPerSample == 8) {
*obuf = cvtS16toU8(fl); *obuf = cvtS16toU8(fl);
return; return;
} }
if (dsound->wfx.wBitsPerSample == 16) { if (dsb->dsound->wfx.wBitsPerSample == 16) {
*((INT16 *)obuf) = fl; *((INT16 *)obuf) = fl;
return; return;
} }
@ -726,7 +726,7 @@ post_mix:
return slen; return slen;
} }
static DWORD DSOUND_MixToPrimary(DWORD playpos, DWORD writepos, DWORD mixlen, BOOL recover) static DWORD DSOUND_MixToPrimary(IDirectSoundImpl *dsound, DWORD playpos, DWORD writepos, DWORD mixlen, BOOL recover)
{ {
INT i, len, maxlen = 0; INT i, len, maxlen = 0;
IDirectSoundBufferImpl *dsb; IDirectSoundBufferImpl *dsb;
@ -767,7 +767,7 @@ static DWORD DSOUND_MixToPrimary(DWORD playpos, DWORD writepos, DWORD mixlen, BO
return maxlen; return maxlen;
} }
static void DSOUND_MixReset(DWORD writepos) static void DSOUND_MixReset(IDirectSoundImpl *dsound, DWORD writepos)
{ {
INT i; INT i;
IDirectSoundBufferImpl *dsb; IDirectSoundBufferImpl *dsb;
@ -817,7 +817,7 @@ static void DSOUND_CheckReset(IDirectSoundImpl *dsound, DWORD writepos)
{ {
TRACE("(%p,%ld)\n",dsound,writepos); TRACE("(%p,%ld)\n",dsound,writepos);
if (dsound->need_remix) { if (dsound->need_remix) {
DSOUND_MixReset(writepos); DSOUND_MixReset(dsound, writepos);
dsound->need_remix = FALSE; dsound->need_remix = FALSE;
/* maximize Half-Life performance */ /* maximize Half-Life performance */
dsound->prebuf = ds_snd_queue_min; dsound->prebuf = ds_snd_queue_min;
@ -848,7 +848,7 @@ void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq)
/* #define SYNC_CALLBACK */ /* #define SYNC_CALLBACK */
void DSOUND_PerformMix(void) void DSOUND_PerformMix(IDirectSoundImpl *dsound)
{ {
int nfiller; int nfiller;
BOOL forced; BOOL forced;
@ -974,7 +974,7 @@ void DSOUND_PerformMix(void)
} }
/* do the mixing */ /* do the mixing */
frag = DSOUND_MixToPrimary(playpos, writepos, maxq, paused); frag = DSOUND_MixToPrimary(dsound, playpos, writepos, maxq, paused);
if (forced) frag = maxq - inq; if (forced) frag = maxq - inq;
dsound->mixpos += frag; dsound->mixpos += frag;
while (dsound->mixpos >= dsound->buflen) while (dsound->mixpos >= dsound->buflen)
@ -1019,23 +1019,24 @@ void DSOUND_PerformMix(void)
void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2) void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{ {
IDirectSoundImpl* This = (IDirectSoundImpl*)dwUser;
TRACE("(%d,%d,0x%lx,0x%lx,0x%lx)\n",timerID,msg,dwUser,dw1,dw2); TRACE("(%d,%d,0x%lx,0x%lx,0x%lx)\n",timerID,msg,dwUser,dw1,dw2);
TRACE("entering at %ld\n", GetTickCount()); TRACE("entering at %ld\n", GetTickCount());
if (!dsound) { if (dsound != This) {
ERR("dsound died without killing us?\n"); ERR("dsound died without killing us?\n");
timeKillEvent(timerID); timeKillEvent(timerID);
timeEndPeriod(DS_TIME_RES); timeEndPeriod(DS_TIME_RES);
return; return;
} }
RtlAcquireResourceShared(&(dsound->lock), TRUE); RtlAcquireResourceShared(&(This->lock), TRUE);
if (dsound->ref) { if (This->ref) {
DSOUND_PerformMix(); DSOUND_PerformMix(This);
} }
RtlReleaseResource(&(dsound->lock)); RtlReleaseResource(&(This->lock));
TRACE("completed processing at %ld\n", GetTickCount()); TRACE("completed processing at %ld\n", GetTickCount());
} }
@ -1059,11 +1060,11 @@ void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, D
EnterCriticalSection(&(This->mixlock)); EnterCriticalSection(&(This->mixlock));
#endif #endif
/* retrieve current values */ /* retrieve current values */
fraglen = dsound->fraglen; fraglen = This->fraglen;
buflen = dsound->buflen; buflen = This->buflen;
pwplay = dsound->pwplay; pwplay = This->pwplay;
playpos = pwplay * fraglen; playpos = pwplay * fraglen;
mixpos = dsound->mixpos; mixpos = This->mixpos;
/* check remaining mixed data */ /* check remaining mixed data */
inq = ((mixpos < playpos) ? buflen : 0) + mixpos - playpos; inq = ((mixpos < playpos) ? buflen : 0) + mixpos - playpos;
mixq = inq / fraglen; mixq = inq / fraglen;
@ -1073,8 +1074,8 @@ void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, D
pwplay++; pwplay++;
if (pwplay >= DS_HEL_FRAGS) pwplay = 0; if (pwplay >= DS_HEL_FRAGS) pwplay = 0;
/* write new values */ /* write new values */
dsound->pwplay = pwplay; This->pwplay = pwplay;
dsound->pwqueue--; This->pwqueue--;
/* queue new buffer if we have data for it */ /* queue new buffer if we have data for it */
if (inq>1) DSOUND_WaveQueue(This, inq-1); if (inq>1) DSOUND_WaveQueue(This, inq-1);
#ifdef SYNC_CALLBACK #ifdef SYNC_CALLBACK