moved a check from the sound class in the sound base class

This commit is contained in:
Volker Fischer 2011-12-07 20:18:56 +00:00
parent 914e41fac3
commit 8bbc9adaa3
2 changed files with 36 additions and 33 deletions

View file

@ -132,11 +132,18 @@ void CSoundBase::run()
\******************************************************************************/ \******************************************************************************/
QString CSoundBase::SetDev ( const int iNewDev ) QString CSoundBase::SetDev ( const int iNewDev )
{ {
QString strReturn = ""; // init with no error // init return parameter with "no error"
bool bTryLoadAnyDriver = false; QString strReturn = "";
// first check if valid input parameter
if ( iNewDev >= lNumDevs )
{
// we should actually never get here...
return tr ( "Invalid device selection." );
}
// check if an ASIO driver was already initialized // check if an ASIO driver was already initialized
if ( lCurDev >= 0 ) if ( lCurDev != INVALID_SNC_CARD_DEVICE )
{ {
// a device was already been initialized and is used, first clean up // a device was already been initialized and is used, first clean up
// driver // driver
@ -175,6 +182,9 @@ QString CSoundBase::SetDev ( const int iNewDev )
} }
else else
{ {
// init flag for "load any driver"
bool bTryLoadAnyDriver = false;
if ( iNewDev != INVALID_SNC_CARD_DEVICE ) if ( iNewDev != INVALID_SNC_CARD_DEVICE )
{ {
// This is the first time a driver is to be initialized, we first // This is the first time a driver is to be initialized, we first
@ -195,7 +205,6 @@ QString CSoundBase::SetDev ( const int iNewDev )
// try to find one usable driver (select the first valid driver) // try to find one usable driver (select the first valid driver)
bTryLoadAnyDriver = true; bTryLoadAnyDriver = true;
} }
}
if ( bTryLoadAnyDriver ) if ( bTryLoadAnyDriver )
{ {
@ -222,6 +231,7 @@ QString CSoundBase::SetDev ( const int iNewDev )
throw CGenErr ( sErrorMessage ); throw CGenErr ( sErrorMessage );
} }
} }
}
return strReturn; return strReturn;
} }

View file

@ -42,13 +42,6 @@ CSound* pSound;
\******************************************************************************/ \******************************************************************************/
QString CSound::LoadAndInitializeDriver ( int iDriverIdx ) QString CSound::LoadAndInitializeDriver ( int iDriverIdx )
{ {
// first check and correct input parameter
if ( iDriverIdx >= lNumDevs )
{
// we assume here that at least one driver is in the system
iDriverIdx = 0;
}
// load driver // load driver
loadAsioDriver ( cDriverNames[iDriverIdx] ); loadAsioDriver ( cDriverNames[iDriverIdx] );
if ( ASIOInit ( &driverInfo ) != ASE_OK ) if ( ASIOInit ( &driverInfo ) != ASE_OK )
@ -82,7 +75,7 @@ QString CSound::LoadAndInitializeDriver ( int iDriverIdx )
void CSound::UnloadCurrentDriver() void CSound::UnloadCurrentDriver()
{ {
// cleanup ASIO stuff // clean up ASIO stuff
ASIOStop(); ASIOStop();
ASIODisposeBuffers(); ASIODisposeBuffers();
ASIOExit(); ASIOExit();
@ -439,8 +432,8 @@ CSound::CSound ( void (*fpNewCallback) ( CVector<int16_t>& psData, void* arg ),
strDriverNames[i] = cDriverNames[i]; strDriverNames[i] = cDriverNames[i];
} }
// init device index with illegal value to show that driver is not initialized // init device index as not initialized (invalid)
lCurDev = -1; lCurDev = INVALID_SNC_CARD_DEVICE;
// init channel mapping // init channel mapping
ResetChannelMapping(); ResetChannelMapping();