diff options
author | Chris Robinson <[email protected]> | 2007-12-05 00:37:38 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2007-12-05 00:37:38 -0800 |
commit | e9eaacd0bdfaed7e7c4b827f1ebadae2e799de15 (patch) | |
tree | 2c1e22e4f895eaf22b55e81316e9b2343956ccd0 /Alc/dsound.c | |
parent | 15019b3871efa27782703ee216aa910927427801 (diff) |
Remove static variable from DSound callback
Diffstat (limited to 'Alc/dsound.c')
-rw-r--r-- | Alc/dsound.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Alc/dsound.c b/Alc/dsound.c index 5913f52f..c65637c8 100644 --- a/Alc/dsound.c +++ b/Alc/dsound.c @@ -37,6 +37,7 @@ typedef struct { LPDIRECTSOUNDBUFFER DSpbuffer; LPDIRECTSOUNDBUFFER DSsbuffer; MMRESULT ulDSTimerID; + DWORD OldWriteCursor; } DSoundData; @@ -44,8 +45,6 @@ static ALCchar *DeviceList[16]; static void CALLBACK DirectSoundProc(UINT uID,UINT uReserved,DWORD_PTR dwUser,DWORD_PTR dwReserved1,DWORD_PTR dwReserved2) { - static DWORD OldWriteCursor=0; - ALCdevice *pDevice = (ALCdevice *)dwUser; DSoundData *pData = pDevice->ExtraData; DWORD PlayCursor,WriteCursor; @@ -65,21 +64,21 @@ static void CALLBACK DirectSoundProc(UINT uID,UINT uReserved,DWORD_PTR dwUser,DW // Get current play and write cursors IDirectSoundBuffer_GetCurrentPosition(pData->DSsbuffer,&PlayCursor,&WriteCursor); - if (!OldWriteCursor) OldWriteCursor=WriteCursor-PlayCursor; + if (!pData->OldWriteCursor) pData->OldWriteCursor=WriteCursor-PlayCursor; // Get the output format and figure the number of bytes played (block aligned) IDirectSoundBuffer_GetFormat(pData->DSsbuffer,&OutputType,sizeof(WAVEFORMATEX),NULL); - BytesPlayed=((((WriteCursor<OldWriteCursor)?(BufSize+WriteCursor-OldWriteCursor):(WriteCursor-OldWriteCursor))/OutputType.nBlockAlign)*OutputType.nBlockAlign); + BytesPlayed=((((WriteCursor<pData->OldWriteCursor)?(BufSize+WriteCursor-pData->OldWriteCursor):(WriteCursor-pData->OldWriteCursor))/OutputType.nBlockAlign)*OutputType.nBlockAlign); // Lock output buffer started at 40msec in front of the old write cursor (15msec in front of the actual write cursor) - DSRes=IDirectSoundBuffer_Lock(pData->DSsbuffer,(OldWriteCursor+(OutputType.nSamplesPerSec/25)*OutputType.nBlockAlign)%BufSize,BytesPlayed,(LPVOID*)&WritePtr1,&WriteCnt1,(LPVOID*)&WritePtr2,&WriteCnt2,0); + DSRes=IDirectSoundBuffer_Lock(pData->DSsbuffer,(pData->OldWriteCursor+(OutputType.nSamplesPerSec/25)*OutputType.nBlockAlign)%BufSize,BytesPlayed,(LPVOID*)&WritePtr1,&WriteCnt1,(LPVOID*)&WritePtr2,&WriteCnt2,0); // If the buffer is lost, restore it, play and lock if (DSRes==DSERR_BUFFERLOST) { IDirectSoundBuffer_Restore(pData->DSsbuffer); IDirectSoundBuffer_Play(pData->DSsbuffer,0,0,DSBPLAY_LOOPING); - DSRes=IDirectSoundBuffer_Lock(pData->DSsbuffer,(OldWriteCursor+(OutputType.nSamplesPerSec/25)*OutputType.nBlockAlign)%BufSize,BytesPlayed,(LPVOID*)&WritePtr1,&WriteCnt1,(LPVOID*)&WritePtr2,&WriteCnt2,0); + DSRes=IDirectSoundBuffer_Lock(pData->DSsbuffer,(pData->OldWriteCursor+(OutputType.nSamplesPerSec/25)*OutputType.nBlockAlign)%BufSize,BytesPlayed,(LPVOID*)&WritePtr1,&WriteCnt1,(LPVOID*)&WritePtr2,&WriteCnt2,0); } // Successfully locked the output buffer @@ -98,7 +97,7 @@ static void CALLBACK DirectSoundProc(UINT uID,UINT uReserved,DWORD_PTR dwUser,DW } // Update old write cursor location - OldWriteCursor=((OldWriteCursor+BytesPlayed)%BufSize); + pData->OldWriteCursor=((pData->OldWriteCursor+BytesPlayed)%BufSize); } |