static PaUtilHostApiRepresentation **hostApis_ = 0;
static int hostApisCount_ = 0;
+static int defaultHostApiIndex_ = 0;
static int initializationCount_ = 0;
static int deviceCount_ = 0;
}
hostApisCount_ = 0;
+ defaultHostApiIndex_ = -1; /* indicates that we haven't determined the default host API yet */
deviceCount_ = 0;
baseDeviceIndex = 0;
assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount );
assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount );
+ /* the first successfully initialized host API with at least one input *or*
+ output device is used as the default host API.
+ */
+ if( (defaultHostApiIndex_ == -1) &&
+ ( hostApi->info.defaultInputDevice != paNoDevice
+ || hostApi->info.defaultOutputDevice != paNoDevice ) )
+ {
+ defaultHostApiIndex_ = hostApisCount_;
+ }
+
hostApi->privatePaFrontInfo.baseDeviceIndex = baseDeviceIndex;
if( hostApi->info.defaultInputDevice != paNoDevice )
}
}
+ /* if no host APIs have devices, the default host API is the first initialized host API */
+ if( defaultHostApiIndex_ == -1 )
+ defaultHostApiIndex_ = 0;
+
return result;
error:
}
else
{
- result = paDefaultHostApiIndex;
+ result = defaultHostApiIndex_;
/* internal consistency check: make sure that the default host api
index is within range */
/** paHostApiInitializers is a NULL-terminated array of host API initialization
functions. These functions are called by pa_front.c to initialize the host APIs
- when the client calls Pa_Initialize().
+ when the client calls Pa_Initialize().
+
+ The initialization functions are invoked in order.
+
+ The first successfully initialized host API that has a default input *or* output
+ device is used as the default PortAudio host API. This is based on the logic that
+ there is only one default host API, and it must contain the default input and output
+ devices (if defined).
- There is a platform specific file which defines paHostApiInitializers for that
+ There is a platform specific file that defines paHostApiInitializers for that
platform, pa_win/pa_win_hostapis.c contains the Win32 definitions for example.
*/
extern PaUtilHostApiInitializer *paHostApiInitializers[];
-/** The index of the default host API in the paHostApiInitializers array.
-
- There is a platform specific file which defines paDefaultHostApiIndex for that
- platform, see pa_win/pa_win_hostapis.c for example.
-*/
-extern int paDefaultHostApiIndex;
-
-
#ifdef __cplusplus
}
#endif /* __cplusplus */