diff options
Diffstat (limited to 'src/client/snd_openal.c')
-rw-r--r-- | src/client/snd_openal.c | 103 |
1 files changed, 83 insertions, 20 deletions
diff --git a/src/client/snd_openal.c b/src/client/snd_openal.c index 6f48713f..9b60aa71 100644 --- a/src/client/snd_openal.c +++ b/src/client/snd_openal.c @@ -42,7 +42,13 @@ cvar_t *s_alRolloff; cvar_t *s_alGraceDistance; cvar_t *s_alDriver; cvar_t *s_alDevice; +cvar_t *s_alInputDevice; cvar_t *s_alAvailableDevices; +cvar_t *s_alAvailableInputDevices; + +static qboolean enumeration_ext = qfalse; +static qboolean enumeration_all_ext = qfalse; +static qboolean capture_ext = qfalse; /* ================= @@ -630,7 +636,7 @@ static void S_AL_ScaleGain(src_t *chksrc, vec3_t origin) scaleFactor *= chksrc->curGain; - if(chksrc->scaleGain != scaleFactor); + if(chksrc->scaleGain != scaleFactor) { chksrc->scaleGain = scaleFactor; S_AL_Gain(chksrc->alSource, chksrc->scaleGain); @@ -2286,22 +2292,34 @@ void S_AL_MasterGain( float gain ) S_AL_SoundInfo ================= */ -static -void S_AL_SoundInfo( void ) +static void S_AL_SoundInfo(void) { Com_Printf( "OpenAL info:\n" ); - Com_Printf( " Vendor: %s\n", qalGetString( AL_VENDOR ) ); - Com_Printf( " Version: %s\n", qalGetString( AL_VERSION ) ); - Com_Printf( " Renderer: %s\n", qalGetString( AL_RENDERER ) ); - Com_Printf( " AL Extensions: %s\n", qalGetString( AL_EXTENSIONS ) ); + Com_Printf( " Vendor: %s\n", qalGetString( AL_VENDOR ) ); + Com_Printf( " Version: %s\n", qalGetString( AL_VERSION ) ); + Com_Printf( " Renderer: %s\n", qalGetString( AL_RENDERER ) ); + Com_Printf( " AL Extensions: %s\n", qalGetString( AL_EXTENSIONS ) ); Com_Printf( " ALC Extensions: %s\n", qalcGetString( alDevice, ALC_EXTENSIONS ) ); - if(qalcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) + + if(enumeration_all_ext) + Com_Printf(" Device: %s\n", qalcGetString(alDevice, ALC_ALL_DEVICES_SPECIFIER)); + else if(enumeration_ext) + Com_Printf(" Device: %s\n", qalcGetString(alDevice, ALC_DEVICE_SPECIFIER)); + + if(enumeration_all_ext || enumeration_ext) + Com_Printf(" Available Devices:\n%s", s_alAvailableDevices->string); + +#ifdef USE_VOIP + if(capture_ext) { - Com_Printf(" Device: %s\n", qalcGetString(alDevice, ALC_DEVICE_SPECIFIER)); - Com_Printf("Available Devices:\n%s", s_alAvailableDevices->string); + Com_Printf(" Input Device: %s\n", qalcGetString(alCaptureDevice, ALC_CAPTURE_DEVICE_SPECIFIER)); + Com_Printf(" Available Input Devices:\n%s", s_alAvailableInputDevices->string); } +#endif } + + /* ================= S_AL_Shutdown @@ -2350,6 +2368,7 @@ qboolean S_AL_Init( soundInterface_t *si ) { #ifdef USE_OPENAL const char* device = NULL; + const char* inputdevice = NULL; int i; if( !si ) { @@ -2375,6 +2394,7 @@ qboolean S_AL_Init( soundInterface_t *si ) s_alDriver = Cvar_Get( "s_alDriver", ALDRIVER_DEFAULT, CVAR_ARCHIVE | CVAR_LATCH ); + s_alInputDevice = Cvar_Get( "s_alInputDevice", "", CVAR_ARCHIVE | CVAR_LATCH ); s_alDevice = Cvar_Get("s_alDevice", "", CVAR_ARCHIVE | CVAR_LATCH); // Load QAL @@ -2388,17 +2408,35 @@ qboolean S_AL_Init( soundInterface_t *si ) if(device && !*device) device = NULL; - // Device enumeration support (extension is implemented reasonably only on Windows right now). - if(qalcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) + inputdevice = s_alInputDevice->string; + if(inputdevice && !*inputdevice) + inputdevice = NULL; + + + // Device enumeration support + enumeration_all_ext = qalcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"); + enumeration_ext = qalcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"); + + if(enumeration_ext || enumeration_all_ext) { - char devicenames[1024] = ""; + char devicenames[16384] = ""; const char *devicelist; const char *defaultdevice; int curlen; - + // get all available devices + the default device name. - devicelist = qalcGetString(NULL, ALC_DEVICE_SPECIFIER); - defaultdevice = qalcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); + if(enumeration_ext) + { + devicelist = qalcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); + defaultdevice = qalcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER); + } + else + { + // We don't have ALC_ENUMERATE_ALL_EXT but normal enumeration. + devicelist = qalcGetString(NULL, ALC_DEVICE_SPECIFIER); + defaultdevice = qalcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); + enumeration_ext = qtrue; + } #ifdef _WIN32 // check whether the default device is generic hardware. If it is, change to @@ -2487,15 +2525,40 @@ qboolean S_AL_Init( soundInterface_t *si ) } else { + char inputdevicenames[16384] = ""; + const char *inputdevicelist; + const char *defaultinputdevice; + int curlen; + + capture_ext = qtrue; + + // get all available input devices + the default input device name. + inputdevicelist = qalcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); + defaultinputdevice = qalcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); + + // dump a list of available devices to a cvar for the user to see. + while((curlen = strlen(inputdevicelist))) + { + Q_strcat(inputdevicenames, sizeof(inputdevicenames), inputdevicelist); + Q_strcat(inputdevicenames, sizeof(inputdevicenames), "\n"); + inputdevicelist += curlen + 1; + } + + s_alAvailableInputDevices = Cvar_Get("s_alAvailableInputDevices", inputdevicenames, CVAR_ROM | CVAR_NORESTART); + // !!! FIXME: 8000Hz is what Speex narrowband mode needs, but we // !!! FIXME: should probably open the capture device after // !!! FIXME: initializing Speex so we can change to wideband // !!! FIXME: if we like. - Com_Printf("OpenAL default capture device is '%s'\n", - qalcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)); - alCaptureDevice = qalcCaptureOpenDevice(NULL, 8000, AL_FORMAT_MONO16, 4096); + Com_Printf("OpenAL default capture device is '%s'\n", defaultinputdevice); + alCaptureDevice = qalcCaptureOpenDevice(inputdevice, 8000, AL_FORMAT_MONO16, 4096); + if( !alCaptureDevice && inputdevice ) + { + Com_Printf( "Failed to open OpenAL Input device '%s', trying default.\n", inputdevice ); + alCaptureDevice = qalcCaptureOpenDevice(NULL, 8000, AL_FORMAT_MONO16, 4096); + } Com_Printf( "OpenAL capture device %s.\n", - (alCaptureDevice == NULL) ? "failed to open" : "opened"); + (alCaptureDevice == NULL) ? "failed to open" : "opened"); } } #endif |