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
@@ -78,7 +78,13 @@ bool RageSoundDriver_WaveOut::GetData()
MMRESULT ret = waveOutWrite( m_hWaveOut, &m_aBuffers[b], sizeof(m_aBuffers[b]) ); MMRESULT ret = waveOutWrite( m_hWaveOut, &m_aBuffers[b], sizeof(m_aBuffers[b]) );
if( ret != MMSYSERR_NOERROR ) if( ret != MMSYSERR_NOERROR )
{
Init();
if (b_InitSuccess == false)
{
FAIL_M(wo_ssprintf(ret, "waveOutWrite failed")); FAIL_M(wo_ssprintf(ret, "waveOutWrite failed"));
}
}
/* Increment m_iLastCursorPos. */ /* Increment m_iLastCursorPos. */
m_iLastCursorPos += chunksize_frames; m_iLastCursorPos += chunksize_frames;
@@ -115,6 +121,7 @@ RageSoundDriver_WaveOut::RageSoundDriver_WaveOut()
RString RageSoundDriver_WaveOut::Init() RString RageSoundDriver_WaveOut::Init()
{ {
b_InitSuccess = false;
m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
if( m_iSampleRate == 0 ) if( m_iSampleRate == 0 )
m_iSampleRate = 44100; m_iSampleRate = 44100;
@@ -174,6 +181,7 @@ RString RageSoundDriver_WaveOut::Init()
MixingThread.SetName( "Mixer thread" ); MixingThread.SetName( "Mixer thread" );
MixingThread.Create( MixerThread_start, this ); MixingThread.Create( MixerThread_start, this );
b_InitSuccess = true;
return RString(); return RString();
} }
+1 -1
View File
@@ -15,7 +15,6 @@ public:
RageSoundDriver_WaveOut(); RageSoundDriver_WaveOut();
~RageSoundDriver_WaveOut(); ~RageSoundDriver_WaveOut();
RString Init(); RString Init();
std::int64_t GetPosition() const; std::int64_t GetPosition() const;
float GetPlayLatency() const; float GetPlayLatency() const;
int GetSampleRate() const { return m_iSampleRate; } int GetSampleRate() const { return m_iSampleRate; }
@@ -33,6 +32,7 @@ private:
int m_iSampleRate; int m_iSampleRate;
bool m_bShutdown; bool m_bShutdown;
int m_iLastCursorPos; int m_iLastCursorPos;
bool b_InitSuccess;
}; };
#endif #endif