WaveOut: Reattempt to initialize on failure

If the device suddenly changes, like say an audio cable gets unplugged, this gives the game a chance to recover gracefully instead of just crashing.
This commit is contained in:
sukibaby
2024-08-07 00:17:25 -07:00
committed by teejusb
parent a0d1198cc1
commit b30bf85399
2 changed files with 11 additions and 3 deletions
+10 -2
View File
@@ -77,8 +77,14 @@ bool RageSoundDriver_WaveOut::GetData()
this->Mix( (std::int16_t *) m_aBuffers[b].lpData, chunksize_frames, m_iLastCursorPos, GetPosition() );
MMRESULT ret = waveOutWrite( m_hWaveOut, &m_aBuffers[b], sizeof(m_aBuffers[b]) );
if( ret != MMSYSERR_NOERROR )
FAIL_M( wo_ssprintf(ret, "waveOutWrite failed") );
if( ret != MMSYSERR_NOERROR )
{
Init();
if (b_InitSuccess == false)
{
FAIL_M(wo_ssprintf(ret, "waveOutWrite failed"));
}
}
/* Increment m_iLastCursorPos. */
m_iLastCursorPos += chunksize_frames;
@@ -115,6 +121,7 @@ RageSoundDriver_WaveOut::RageSoundDriver_WaveOut()
RString RageSoundDriver_WaveOut::Init()
{
b_InitSuccess = false;
m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
if( m_iSampleRate == 0 )
m_iSampleRate = 44100;
@@ -174,6 +181,7 @@ RString RageSoundDriver_WaveOut::Init()
MixingThread.SetName( "Mixer thread" );
MixingThread.Create( MixerThread_start, this );
b_InitSuccess = true;
return RString();
}
+1 -1
View File
@@ -15,7 +15,6 @@ public:
RageSoundDriver_WaveOut();
~RageSoundDriver_WaveOut();
RString Init();
std::int64_t GetPosition() const;
float GetPlayLatency() const;
int GetSampleRate() const { return m_iSampleRate; }
@@ -33,6 +32,7 @@ private:
int m_iSampleRate;
bool m_bShutdown;
int m_iLastCursorPos;
bool b_InitSuccess;
};
#endif