Ejemplo n.º 1
0
// Thread: Any. Must be locked: AudioMutex.
bool CreatePlaybackDevice() {
	if (AudioDevice) return true;

	AudioDevice = alcOpenDevice(nullptr);
	if (!AudioDevice) {
		LOG(("Audio Error: Could not create default playback device, enumerating.."));
		EnumeratePlaybackDevices();
		return false;
	}

	ALCint attributes[] = {
		ALC_STEREO_SOURCES, 128,
		ALC_FREQUENCY, Media::Player::kDefaultFrequency,
		0
	};
	AudioContext = alcCreateContext(AudioDevice, attributes);
	alcMakeContextCurrent(AudioContext);
	if (ContextErrorHappened()) {
		DestroyPlaybackDevice();
		return false;
	}

	ALfloat v[] = { 0.f, 0.f, -1.f, 0.f, 1.f, 0.f };
	alListener3f(AL_POSITION, 0.f, 0.f, 0.f);
	alListener3f(AL_VELOCITY, 0.f, 0.f, 0.f);
	alListenerfv(AL_ORIENTATION, v);

#ifndef TDESKTOP_DISABLE_OPENAL_EFFECTS
	// playback speed related init
	// generate an effect slot and an effect
	alGenAuxiliaryEffectSlots(1, &_playbackSpeedData.uiEffectSlot);
	alGenEffects(1, &_playbackSpeedData.uiEffect);
	// initialize the pitch shifter effect
	alEffecti(_playbackSpeedData.uiEffect, AL_EFFECT_TYPE, AL_EFFECT_PITCH_SHIFTER);
	// 12 semitones = 1 octave
	alEffecti(_playbackSpeedData.uiEffect, AL_PITCH_SHIFTER_COARSE_TUNE, kPlaybackSpeedTune);
	// connect the effect with the effect slot
	alAuxiliaryEffectSloti(_playbackSpeedData.uiEffectSlot, AL_EFFECTSLOT_EFFECT, _playbackSpeedData.uiEffect);
	// initialize a filter to disable the direct (dry) path
	alGenFilters(1, &_playbackSpeedData.uiFilter);
	alFilteri(_playbackSpeedData.uiFilter, AL_FILTER_TYPE, AL_FILTER_LOWPASS);
	// disable all frequencies
	alFilterf(_playbackSpeedData.uiFilter, AL_LOWPASS_GAIN, 0.f);
	// to use the modified playback speed:
	// connect both the effect slot and filter with the stream source and set AL_PITCH
#endif // TDESKTOP_DISABLE_OPENAL_EFFECTS

	alDistanceModel(AL_NONE);

	return true;
}
Ejemplo n.º 2
0
//////////////////////////////////////////////////////////////////////////
// Ctor
SsChannelAL::SsChannelAL( SsCoreImplAL* Parent ):
	ALSource_( NULL ),
	ALFilter_( NULL ),
	State_( ssCS_IDLE ),
	Sample_( NULL ),
	Parent_( Parent )
{
	// Generate source.
	alGenSources( 1, &ALSource_ );
	alBreakOnError();

#if SS_AL_EFX_SUPPORTED
	if( SsCore::pImpl< SsCoreImplAL >()->isEFXEnabled() )
	{
		// Generate filter (if supported)
		alGenFilters( 1, &ALFilter_ );
		alBreakOnError();
	}
#endif
}
Ejemplo n.º 3
0
bool openal_init() {
	dev=alcOpenDevice(NULL);

	if(!dev)
		return true;

	ctx=alcCreateContext(dev,NULL);

	if(!ctx)
		return true;

	if(!alcMakeContextCurrent(ctx))
		return true;

	sound_init_extensions();
/*
	if(cvars["s_volume"]>100)
		cvars["s_volume"]=100;

	if(cvars["s_on"])
		alListenerf(AL_GAIN,float(cvars["s_volume"])/100);
	else
		alListenerf(AL_GAIN,0.0f);
*/
	alGenAuxiliaryEffectSlots(1,&uiEffectSlot);
	alGenEffects(1,&uiEffect);
	alEffecti(uiEffect,AL_EFFECT_TYPE,AL_EFFECT_REVERB);
	alAuxiliaryEffectSloti(uiEffectSlot,AL_EFFECTSLOT_EFFECT,uiEffect);

	alGenFilters(1,&uiFilter);
	alFilteri(uiFilter,AL_FILTER_TYPE,AL_FILTER_LOWPASS);
	alFilterf(uiFilter,AL_LOWPASS_GAIN,1.0f);
	alFilterf(uiFilter,AL_LOWPASS_GAINHF,0.1f);

	soundbuffers.push_back(new SoundBuffer("data/sfx/01.ogg"));
	soundbuffers.push_back(new SoundBuffer("data/sfx/02.ogg"));

	return false;
}
Ejemplo n.º 4
0
CEFX::CEFX(ALCdevice* device)
	:enabled(false)
	,supported(false)
	,sfxProperties(NULL)
	,sfxSlot(0)
	,sfxReverb(0)
	,sfxFilter(0)
	,updates(0)
	,maxSlots(0)
	,maxSlotsPerSource(0)
{
	SetAirAbsorptionFactor(configHandler->GetFloat("snd_airAbsorption"));

	bool hasExtension = alcIsExtensionPresent(device, "ALC_EXT_EFX");

	if(hasExtension && alGenEffects && alDeleteEffects)
		supported = true;

	//! set default preset
	eaxPresets["default"] = eaxPresets[default_preset];

	//! always allocate this
	sfxProperties = new EAXSfxProps();
	*sfxProperties = eaxPresets[default_preset];

	if (!supported) {
		if(!hasExtension)
			LOG("  EFX Supported: no");
		else
			LOG("  EFX is supported but software does not seem to work properly");
		return;
	}

	//! clear log
	alGetError() ;

	//! Check Available Effects
	{
		static const ALuint effects[] = {
			AL_EFFECT_REVERB,
			AL_EFFECT_EAXREVERB,
			AL_EFFECT_CHORUS,
			AL_EFFECT_DISTORTION,
			AL_EFFECT_ECHO,
			AL_EFFECT_FLANGER,
			AL_EFFECT_FREQUENCY_SHIFTER,
			AL_EFFECT_VOCAL_MORPHER,
			AL_EFFECT_PITCH_SHIFTER,
			AL_EFFECT_RING_MODULATOR,
			AL_EFFECT_AUTOWAH,
			AL_EFFECT_COMPRESSOR,
			AL_EFFECT_EQUALIZER
		};

		ALuint alFx;
		alGenEffects(1, &alFx);
		if (alGetError() == AL_NO_ERROR) {
			for(size_t i = 0; i < sizeof(effects); i++) {
				const ALuint fx = effects[i];
				alEffecti(alFx, AL_EFFECT_TYPE, fx);
				effectsSupported[fx] = (alGetError() == AL_NO_ERROR);
			}
		}
		alDeleteEffects(1, &alFx);
	}

	//! Check Available Filters
	{
		static const ALuint filters[] = {
			AL_FILTER_LOWPASS,
			AL_FILTER_HIGHPASS,
			AL_FILTER_BANDPASS
		};

		ALuint alFilter;
		alGenFilters(1, &alFilter);
		if (alGetError() == AL_NO_ERROR) {
			for(size_t i = 0; i < sizeof(filters); i++) {
				const ALuint filter = filters[i];
				alFilteri(alFilter, AL_FILTER_TYPE, filter);
				filtersSupported[filter] = (alGetError() == AL_NO_ERROR);
			}
		}
		alDeleteFilters(1, &alFilter);
	}

	//! Check Max Available EffectSlots
	{
		int n;
		ALuint alFXSlots[128];
		for (n = 0; n < 128; n++) {
			alGenAuxiliaryEffectSlots(1, &alFXSlots[n]);
			if (alGetError() != AL_NO_ERROR)
				break;
		}
		maxSlots = n;

		alDeleteAuxiliaryEffectSlots(n, alFXSlots);
	}

	//! Check Max AUX FX SLOTS Per Sound Source
	alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, (ALCint*)&maxSlotsPerSource);


	//! Check requirements
	if (!effectsSupported[AL_EFFECT_EAXREVERB]
		|| !filtersSupported[AL_FILTER_LOWPASS]
		|| (maxSlots<1)
		|| (maxSlotsPerSource<1)
	) {
		LOG_L(L_WARNING, "  EFX Supported: no");
		supported = false;
		return;
	}


	//! Create our global sfx enviroment
	alGenAuxiliaryEffectSlots(1, &sfxSlot);
	alGenEffects(1, &sfxReverb);
		alEffecti(sfxReverb, AL_EFFECT_TYPE, AL_EFFECT_EAXREVERB);
	alGenFilters(1, &sfxFilter);
		alFilteri(sfxFilter, AL_FILTER_TYPE, AL_FILTER_LOWPASS);
	if (!alIsAuxiliaryEffectSlot(sfxSlot) || !alIsEffect(sfxReverb) || !alIsFilter(sfxFilter)) {
		LOG_L(L_ERROR, "  Initializing EFX failed!");
		alDeleteFilters(1, &sfxFilter);
		alDeleteEffects(1, &sfxReverb);
		alDeleteAuxiliaryEffectSlots(1, &sfxSlot);
		supported = false;
		return;
	}


	//! Load defaults
	CommitEffects();
	if (!CheckError("  EFX")) {
		LOG_L(L_ERROR, "  Initializing EFX failed!");
		alAuxiliaryEffectSloti(sfxSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECT_NULL);
		alDeleteFilters(1, &sfxFilter);
		alDeleteEffects(1, &sfxReverb);
		alDeleteAuxiliaryEffectSlots(1, &sfxSlot);
		supported = false;
		return;
	}

	//! User may disable it (performance reasons?)
	enabled = configHandler->GetBool("UseEFX");
	LOG("  EFX Enabled: %s", (enabled ? "yes" : "no"));
	if (enabled) {
		LOG_L(L_DEBUG, "  EFX MaxSlots: %i", maxSlots);
		LOG_L(L_DEBUG, "  EFX MaxSlotsPerSource: %i", maxSlotsPerSource);
	}

	configHandler->NotifyOnChange(this);
}
Ejemplo n.º 5
0
/* OpenAL EFX extension functions */
static ALvoid CDECL wine_alGenFilters(ALsizei n, ALuint* filters)
{
    alGenFilters(n, filters);
}
Ejemplo n.º 6
0
AudioFilter::AudioFilter()
{
#if !defined(FEA_NO_EFX)
    alGenFilters(1, &mFilterId);
#endif
}