SPU2ghz: Fixed a couple rare odd-case XAudio2 crashes, and fixed a small glitch in in the over/underrun code when timestretching disabled.

git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@288 a6443dda-0b58-4228-96e9-037be469359c
This commit is contained in:
Jake.Stine 2008-11-04 00:29:19 +00:00 committed by Gregory Hainaut
parent c69df473ad
commit 211829bb18
3 changed files with 11 additions and 7 deletions

View File

@ -213,7 +213,7 @@ public:
else else
{ {
// Toss half the buffer plus whatever's being written anew: // Toss half the buffer plus whatever's being written anew:
s32 comp = GetAlignedBufferSize( (size + nSamples ) / 2 ); comp = GetAlignedBufferSize( (size + nSamples ) / 2 );
if( comp > (size-SndOutPacketSize) ) comp = size-SndOutPacketSize; if( comp > (size-SndOutPacketSize) ) comp = size-SndOutPacketSize;
} }

View File

@ -424,7 +424,7 @@ s32 CALLBACK SPU2open(void *pDsp)
debugDialogOpen=1; debugDialogOpen=1;
}*/ }*/
spu2open=1; spu2open=true;
if (!SndInit()) if (!SndInit())
{ {
srate_pv=(double)SampleRate/48000.0; srate_pv=(double)SampleRate/48000.0;

View File

@ -53,7 +53,9 @@ private:
STDMETHOD_(void, OnBufferStart) ( void* ) {} STDMETHOD_(void, OnBufferStart) ( void* ) {}
STDMETHOD_(void, OnBufferEnd) ( void* context ) STDMETHOD_(void, OnBufferEnd) ( void* context )
{ {
if( context == NULL || sndout == NULL ) return; // All of these checks are necessary because XAudio2 is wonky shizat.
if( pSourceVoice == NULL || context == NULL || sndout == NULL ) return;
s16* qb = (s16*)context; s16* qb = (s16*)context;
for(int p=0; p<PacketsPerBuffer; p++, qb+=SndOutPacketSize ) for(int p=0; p<PacketsPerBuffer; p++, qb+=SndOutPacketSize )
@ -123,9 +125,6 @@ public:
// or after CreateSourceVoice. Some drivers could do evil things to // or after CreateSourceVoice. Some drivers could do evil things to
// our structure whn we create the voice. // our structure whn we create the voice.
voiceContext.sndout = sb;
voiceContext.pSourceVoice = pSourceVoice;
// //
// Create an XAudio2 voice to stream this wave // Create an XAudio2 voice to stream this wave
// //
@ -139,8 +138,8 @@ public:
// See comment above. Leave this redundant code in to protect against // See comment above. Leave this redundant code in to protect against
// potentially stupid drivers. // potentially stupid drivers.
voiceContext.sndout = sb;
voiceContext.pSourceVoice = pSourceVoice; voiceContext.pSourceVoice = pSourceVoice;
pSourceVoice->FlushSourceBuffers();
pSourceVoice->Start( 0, 0 ); pSourceVoice->Start( 0, 0 );
qbuffer = new s16[BufferSize*MAX_BUFFER_COUNT]; qbuffer = new s16[BufferSize*MAX_BUFFER_COUNT];
@ -165,6 +164,8 @@ public:
buf.pAudioData=(BYTE*)buf.pContext; buf.pAudioData=(BYTE*)buf.pContext;
pSourceVoice->SubmitSourceBuffer( &buf ); pSourceVoice->SubmitSourceBuffer( &buf );
} }
voiceContext.sndout = sb;
return 0; return 0;
} }
@ -176,7 +177,10 @@ public:
if( pSourceVoice != NULL ) if( pSourceVoice != NULL )
{ {
pSourceVoice->Stop( 0 ); pSourceVoice->Stop( 0 );
pSourceVoice->FlushSourceBuffers();
Sleep(50); // give the engine some time to stop voices Sleep(50); // give the engine some time to stop voices
voiceContext.pSourceVoice = NULL;
voiceContext.sndout = NULL;
pSourceVoice->DestroyVoice(); pSourceVoice->DestroyVoice();
pSourceVoice = NULL; pSourceVoice = NULL;
} }