示例#1
0
void Audio::init()
{
#ifdef WIN32
	EFXEAXREVERBPROPERTIES efxReverb;
	int attrib[] = {ALC_MAX_AUXILIARY_SENDS, 4};
	int sends;
	ALenum al_err;
#endif

	debugf("Using default audio device: %s\n", alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
	device = alcOpenDevice(NULL);
	if (device == NULL)
	{
		debugf("No sound device/driver has been found.\n");
		return;
	}

#ifdef WIN32
    context = alcCreateContext(device, attrib);
#else
    context = alcCreateContext(device, NULL);
#endif
	if (context == NULL)
	{
		debugf("alcCreateContext failed.\n");
	}

	if ( alcMakeContextCurrent(context) == ALC_FALSE )
	{
		ALCenum error = alcGetError(device);

		switch (error)
		{
		case ALC_NO_ERROR:
			debugf("alcMakeContextCurrent failed: No error.\n");
			break;
		case ALC_INVALID_DEVICE:
			debugf("alcMakeContextCurrent failed: Invalid device.\n");
			break;
		case ALC_INVALID_CONTEXT:
			debugf("alcMakeContextCurrent failed: Invalid context.\n");
			break;
		case ALC_INVALID_ENUM:
			debugf("alcMakeContextCurrent failed: Invalid enum.\n");
			break;
		case ALC_INVALID_VALUE:
			debugf("alcMakeContextCurrent failed: Invalid value.\n");
			break;
		case ALC_OUT_OF_MEMORY:
			debugf("alcMakeContextCurrent failed: Out of memory.\n");
			break;
		}
		return;
	}
#ifdef WIN32
	alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
	debugf("%d sends per audio source\n", sends);
#endif
	alListenerf(AL_REFERENCE_DISTANCE, 100.0f);

	//gain = 	(distance / AL_REFERENCE_DISTANCE) ^ (-AL_ROLLOFF_FACTOR
	alDistanceModel(AL_EXPONENT_DISTANCE);
	alListenerf(AL_ROLLOFF_FACTOR, 0.000001f);
//	alListenerf(AL_MAX_DISTANCE, 10000.0f);

	alDopplerFactor(1.0f);
//	alDopplerVelocity(8.0f);
//	alSpeedOfSound(343.3f * UNITS_TO_METERS);
#ifdef WIN32
	alListenerf(AL_METERS_PER_UNIT, 0.3f);

	ALFWIsEFXSupported();
	alGenAuxiliaryEffectSlots(1, &slot);
	al_err = alGetError();
	if (al_err != AL_NO_ERROR)
	{
		debugf("Unable to generate slot: %s\n", GetALErrorString(al_err));
		return;
	}

	alGenEffects(1, &effect);
	al_err = alGetError();
	if (al_err != AL_NO_ERROR)
	{
		debugf("Unable to generate effect: %s\n", GetALErrorString(al_err));
		return;
	}
	alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_EAXREVERB);
	al_err = alGetError();
	if (al_err != AL_NO_ERROR)
	{
		debugf("Unable to set effect: %s\n", GetALErrorString(al_err));
		return;
	}
	ConvertReverbParameters(&eaxBathroom, &efxReverb);
	SetEFXEAXReverbProperties(&efxReverb, effect);

//	alEffectf(effect, AL_REVERB_GAIN, 1.0f);
//	alEffectf(effect, AL_REVERB_DECAY_TIME, 20.0f);
//	alEffectf(effect, AL_REVERB_DENSITY, 0.25f);

	alGenFilters(1, &filter);
	al_err = alGetError();
	if (al_err != AL_NO_ERROR)
	{
		debugf("Unable to generate filter: %s\n", GetALErrorString(al_err));
		return;
	}

	alFilteri(filter, AL_FILTER_TYPE, AL_FILTER_LOWPASS);
	alFilterf(filter, AL_LOWPASS_GAIN, 0.5f);
	alFilterf(filter, AL_LOWPASS_GAINHF, 0.5f);
#endif
}
示例#2
0
	void COALExtProvider::CopyPreset(sSoundReverbProperties& input, EFXEAXREVERBPROPERTIES& output)
	{
		EAXREVERBPROPERTIES props;
		memcpy(&props, &input, sizeof(EAXREVERBPROPERTIES));
		ConvertReverbParameters(&props, &output);
	}