/** * @brief Cleans up after the sound subsytem. */ void sound_al_exit (void) { int i; soundLock(); /* Free groups. */ for (i=0; i<al_ngroups; i++) { if (al_groups[i].sources != NULL) { free(al_groups[i].sources); } al_groups[i].sources = NULL; al_groups[i].nsources = 0; } if (al_groups != NULL) free(al_groups); al_groups = NULL; al_ngroups = 0; /* Free stacks. */ if (source_all != NULL) { alSourceStopv( source_nall, source_all ); alDeleteSources( source_nall, source_all ); free(source_all); } source_all = NULL; source_nall = 0; if (source_total) free(source_total); source_total = NULL; source_ntotal = 0; if (source_stack != NULL) free(source_stack); source_stack = NULL; source_nstack = 0; source_mstack = 0; /* Clean up EFX stuff. */ if (al_info.efx == AL_TRUE) { nalDeleteAuxiliaryEffectSlots( 1, &efx_directSlot ); if (al_info.efx_reverb == AL_TRUE) nalDeleteEffects( 1, &efx_reverb ); if (al_info.efx_echo == AL_TRUE) nalDeleteEffects( 1, &efx_echo ); } /* Clean up global stuff. */ if (al_context) { alcMakeContextCurrent(NULL); alcDestroyContext( al_context ); } if (al_device) alcCloseDevice( al_device ); soundUnlock(); SDL_DestroyMutex( sound_lock ); }
/** * @brief Enables the OpenAL EFX extension. * * @return 0 on success. */ static int al_enableEFX (void) { /* Get general information. */ alcGetIntegerv( al_device, ALC_MAX_AUXILIARY_SENDS, 1, &al_info.efx_auxSends ); alcGetIntegerv( al_device, ALC_EFX_MAJOR_VERSION, 1, &al_info.efx_major ); alcGetIntegerv( al_device, ALC_EFX_MINOR_VERSION, 1, &al_info.efx_minor ); /* Get function pointers. */ nalGenAuxiliaryEffectSlots = alGetProcAddress( "alGenAuxiliaryEffectSlots" ); nalDeleteAuxiliaryEffectSlots = alGetProcAddress( "alDeleteAuxiliaryEffectSlots" ); nalIsAuxiliaryEffectSlot = alGetProcAddress( "alIsAuxiliaryEffectSlot" ); nalAuxiliaryEffectSloti = alGetProcAddress( "alAuxiliaryEffectSloti" ); nalAuxiliaryEffectSlotiv = alGetProcAddress( "alAuxiliaryEffectSlotiv" ); nalAuxiliaryEffectSlotf = alGetProcAddress( "alAuxiliaryEffectSlotf" ); nalAuxiliaryEffectSlotfv = alGetProcAddress( "alAuxiliaryEffectSlotfv" ); nalGetAuxiliaryEffectSloti = alGetProcAddress( "alGetAuxiliaryEffectSloti" ); nalGetAuxiliaryEffectSlotiv = alGetProcAddress( "alGetAuxiliaryEffectSlotiv" ); nalGetAuxiliaryEffectSlotf = alGetProcAddress( "alGetAuxiliaryEffectSlotf" ); nalGetAuxiliaryEffectSlotfv = alGetProcAddress( "alGetAuxiliaryEffectSlotfv" ); nalGenFilters = alGetProcAddress( "alGenFilters" ); nalDeleteFilters = alGetProcAddress( "alDeleteFilters" ); nalFilteri = alGetProcAddress( "alFilteri" ); nalFilteriv = alGetProcAddress( "alFilteriv" ); nalFilterf = alGetProcAddress( "alFilterf" ); nalFilterfv = alGetProcAddress( "alFilterfv" ); nalGenEffects = alGetProcAddress( "alGenEffects" ); nalDeleteEffects = alGetProcAddress( "alDeleteEffects" ); nalEffecti = alGetProcAddress( "alEffecti" ); nalEffectiv = alGetProcAddress( "alEffectiv" ); nalEffectf = alGetProcAddress( "alEffectf" ); nalEffectfv = alGetProcAddress( "alEffectfv" ); if (!nalGenAuxiliaryEffectSlots || !nalDeleteAuxiliaryEffectSlots || !nalIsAuxiliaryEffectSlot || !nalAuxiliaryEffectSloti || !nalAuxiliaryEffectSlotiv || !nalAuxiliaryEffectSlotf || !nalAuxiliaryEffectSlotfv || !nalGetAuxiliaryEffectSloti || !nalGetAuxiliaryEffectSlotiv || !nalGetAuxiliaryEffectSlotf || !nalGetAuxiliaryEffectSlotfv || !nalGenFilters || !nalDeleteFilters || !nalFilteri || !nalFilteriv || !nalFilterf || !nalFilterfv || !nalGenEffects || !nalDeleteEffects || !nalEffecti || !nalEffectiv || !nalEffectf || !nalEffectfv) { DEBUG("OpenAL EFX functions not found, disabling EFX."); al_info.efx = AL_FALSE; return -1; } /* Create auxiliary slot. */ nalGenAuxiliaryEffectSlots( 1, &efx_directSlot ); /* Create reverb effect. */ nalGenEffects( 1, &efx_reverb ); nalEffecti( efx_reverb, AL_EFFECT_TYPE, AL_EFFECT_REVERB ); if(alGetError() != AL_NO_ERROR) { DEBUG("OpenAL Reverb not found, disabling."); al_info.efx_reverb = AL_FALSE; nalDeleteEffects( 1, &efx_reverb ); } else { al_info.efx_reverb = AL_TRUE; /* Set Reverb parameters. */ /*nalEffectf( efx_reverb, AL_REVERB_DECAY_TIME, 15. );*/ } /* Create echo effect. */ nalGenEffects( 1, &efx_echo ); nalEffecti( efx_echo, AL_EFFECT_TYPE, AL_EFFECT_ECHO ); if(alGetError() != AL_NO_ERROR) { DEBUG("OpenAL Echo not found, disabling."); al_info.efx_echo = AL_FALSE; nalDeleteEffects( 1, &efx_echo ); } else { al_info.efx_echo = AL_TRUE; /* Set Echo parameters. */ nalEffectf( efx_echo, AL_ECHO_DELAY, 0.207 ); } /* Set up the listener. */ alListenerf( AL_METERS_PER_UNIT, 5. ); /* Check for errors. */ al_checkErr(); return 0; }