AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
    ALCcontext *Context;
    ALsizei i=0;

    Context = GetContextSuspended();
    if(!Context) return;

    if (n > 0)
    {
        ALCdevice *device = Context->Device;

        // Check that enough memory has been allocted in the 'filters' array for n Filters
        if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint)))
        {
            ALenum err;

            while(i < n)
            {
                ALfilter *filter = calloc(1, sizeof(ALfilter));
                if(!filter)
                {
                    alSetError(Context, AL_OUT_OF_MEMORY);
                    alDeleteFilters(i, filters);
                    break;
                }

                filter->filter = ALTHUNK_ADDENTRY(filter);
                err = InsertUIntMapEntry(&device->FilterMap, filter->filter,
                                         filter);
                if(err != AL_NO_ERROR)
                {
                    ALTHUNK_REMOVEENTRY(filter->filter);
                    memset(filter, 0, sizeof(ALfilter));
                    free(filter);

                    alSetError(Context, err);
                    alDeleteFilters(i, filters);
                    break;
                }

                filters[i++] = filter->filter;
                InitFilterParams(filter, AL_FILTER_NULL);
            }
        }
    }

    ProcessContext(Context);
}
Beispiel #2
0
AudioFilter::~AudioFilter()
{
#if !defined(FEA_NO_EFX)
    if(mFilterId != 0)
        alDeleteFilters(1, &mFilterId);
#endif
}
Beispiel #3
0
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
    ALCcontext *Context;
    ALsizei i;

    Context = GetContextRef();
    if(!Context) return;

    if(n < 0 || IsBadWritePtr((void*)filters, n * sizeof(ALuint)))
        alSetError(Context, AL_INVALID_VALUE);
    else
    {
        ALCdevice *device = Context->Device;
        ALenum err;

        for(i = 0;i < n;i++)
        {
            ALfilter *filter = calloc(1, sizeof(ALfilter));
            if(!filter)
            {
                alSetError(Context, AL_OUT_OF_MEMORY);
                alDeleteFilters(i, filters);
                break;
            }
            InitFilterParams(filter, AL_FILTER_NULL);

            err = NewThunkEntry(&filter->filter);
            if(err == AL_NO_ERROR)
                err = InsertUIntMapEntry(&device->FilterMap, filter->filter, filter);
            if(err != AL_NO_ERROR)
            {
                FreeThunkEntry(filter->filter);
                memset(filter, 0, sizeof(ALfilter));
                free(filter);

                alSetError(Context, err);
                alDeleteFilters(i, filters);
                break;
            }

            filters[i] = filter->filter;
        }
    }

    ALCcontext_DecRef(Context);
}
Beispiel #4
0
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
    ALCcontext *Context;
    ALsizei i=0;

    Context = GetContextSuspended();
    if(!Context) return;

    if(n < 0 || IsBadWritePtr((void*)filters, n * sizeof(ALuint)))
        alSetError(Context, AL_INVALID_VALUE);
    else
    {
        ALCdevice *device = Context->Device;
        ALenum err;

        while(i < n)
        {
            ALfilter *filter = alCalloc(1, sizeof(ALfilter));
            if(!filter)
            {
                alSetError(Context, AL_OUT_OF_MEMORY);
                alDeleteFilters(i, filters);
                break;
            }

            filter->filter = ALTHUNK_ADDENTRY(filter);
            err = InsertUIntMapEntry(&device->FilterMap, filter->filter, filter);
            if(err != AL_NO_ERROR)
            {
                ALTHUNK_REMOVEENTRY(filter->filter);
                memset(filter, 0, sizeof(ALfilter));
                alFree(filter);

                alSetError(Context, err);
                alDeleteFilters(i, filters);
                break;
            }

            filters[i++] = filter->filter;
            InitFilterParams(filter, AL_FILTER_NULL);
        }
    }

    ProcessContext(Context);
}
Beispiel #5
0
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
    ALCcontext *Context;
    ALsizei    cur = 0;

    Context = GetContextRef();
    if(!Context) return;

    al_try
    {
        ALCdevice *device = Context->Device;
        ALenum err;

        CHECK_VALUE(Context, n >= 0);
        for(cur = 0;cur < n;cur++)
        {
            ALfilter *filter = calloc(1, sizeof(ALfilter));
            if(!filter)
            {
                alDeleteFilters(cur, filters);
                al_throwerr(Context, AL_OUT_OF_MEMORY);
            }
            InitFilterParams(filter, AL_FILTER_NULL);

            err = NewThunkEntry(&filter->id);
            if(err == AL_NO_ERROR)
                err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter);
            if(err != AL_NO_ERROR)
            {
                FreeThunkEntry(filter->id);
                memset(filter, 0, sizeof(ALfilter));
                free(filter);

                alDeleteFilters(cur, filters);
                al_throwerr(Context, err);
            }

            filters[cur] = filter->id;
        }
    }
    al_endtry;

    ALCcontext_DecRef(Context);
}
Beispiel #6
0
CEFX::~CEFX()
{
	if (supported) {
		alAuxiliaryEffectSloti(sfxSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECT_NULL);
		alDeleteFilters(1, &sfxFilter);
		alDeleteEffects(1, &sfxReverb);
		alDeleteAuxiliaryEffectSlots(1, &sfxSlot);
	}
	delete sfxProperties;
}
Beispiel #7
0
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
    ALCdevice *device;
    ALCcontext *context;
    ALsizei cur = 0;
    ALenum err;

    context = GetContextRef();
    if(!context) return;

    if(!(n >= 0))
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);

    device = context->Device;
    for(cur = 0;cur < n;cur++)
    {
        ALfilter *filter = calloc(1, sizeof(ALfilter));
        if(!filter)
        {
            alDeleteFilters(cur, filters);
            SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
        }
        InitFilterParams(filter, AL_FILTER_NULL);

        err = NewThunkEntry(&filter->id);
        if(err == AL_NO_ERROR)
            err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter);
        if(err != AL_NO_ERROR)
        {
            FreeThunkEntry(filter->id);
            memset(filter, 0, sizeof(ALfilter));
            free(filter);

            alDeleteFilters(cur, filters);
            SET_ERROR_AND_GOTO(context, err, done);
        }

        filters[cur] = filter->id;
    }

done:
    ALCcontext_DecRef(context);
}
Beispiel #8
0
CEFX::~CEFX()
{
	configHandler->RemoveObserver(this);
	if (supported) {
		alAuxiliaryEffectSloti(sfxSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECT_NULL);
		alDeleteFilters(1, &sfxFilter);
		alDeleteEffects(1, &sfxReverb);
		alDeleteAuxiliaryEffectSlots(1, &sfxSlot);
	}
	delete sfxProperties;
}
Beispiel #9
0
//////////////////////////////////////////////////////////////////////////
// Dtor
SsChannelAL::~SsChannelAL()
{
	// Delete source.
	alDeleteSources( 1, &ALSource_ );
	alBreakOnError();

#if SS_AL_EFX_SUPPORTED
	if( SsCore::pImpl< SsCoreImplAL >()->isEFXEnabled() )
	{
		// Delete filters.
		alDeleteFilters( 1, &ALFilter_ );
		alBreakOnError();
	}
#endif
}
ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
    ALCcontext *Context;
    ALsizei i;

    Context = alcGetCurrentContext();
    SuspendContext(Context);

    if (n > 0)
    {
        // Check that enough memory has been allocted in the 'filters' array for n Filters
        if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint)))
        {
            ALfilter **list = &g_FilterList;
            while(*list)
                list = &(*list)->next;

            i = 0;
            while(i < n)
            {
                *list = calloc(1, sizeof(ALfilter));
                if(!(*list))
                {
                    // We must have run out or memory
                    alDeleteFilters(i, filters);
                    alSetError(AL_OUT_OF_MEMORY);
                    break;
                }

                filters[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
                (*list)->filter = filters[i];

                InitFilterParams(*list, AL_FILTER_NULL);
                g_FilterCount++;
                i++;

                list = &(*list)->next;
            }
        }
    }

    ProcessContext(Context);
}
Beispiel #11
0
// Thread: Main. Must be locked: AudioMutex.
void ClosePlaybackDevice(not_null<Instance*> instance) {
	if (!AudioDevice) return;

	LOG(("Audio Info: Closing audio playback device."));

#ifndef TDESKTOP_DISABLE_OPENAL_EFFECTS
	// playback speed related
	alDeleteFilters(1, &_playbackSpeedData.uiFilter);
	alDeleteEffects(1, &_playbackSpeedData.uiEffect);
	alDeleteAuxiliaryEffectSlots(1, &_playbackSpeedData.uiEffectSlot);
	_playbackSpeedData.uiFilter = 0;
	_playbackSpeedData.uiEffect = 0;
	_playbackSpeedData.uiEffectSlot = 0;
#endif // TDESKTOP_DISABLE_OPENAL_EFFECTS

	if (Player::mixer()) {
		Player::mixer()->detachTracks();
	}
	instance->detachTracks();

	DestroyPlaybackDevice();
}
Beispiel #12
0
void openal_kill() {
	if(soundevents.size())
		killarray(soundevents);

	if(soundbuffers.size())
		killarray(soundbuffers);

	if(musiclist.size())
		killarray(musiclist);

	if(uiEffect)
		alDeleteEffects(1,&uiEffect);

	if(uiEffectSlot)
		alDeleteAuxiliaryEffectSlots(1,&uiEffectSlot);

	if(uiFilter)
		alDeleteFilters(1,&uiFilter);

	alcMakeContextCurrent(NULL);
	alcDestroyContext(ctx);
	alcCloseDevice(dev);
}
Beispiel #13
0
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
    ALCcontext *context;
    ALsizei cur = 0;

    context = GetContextRef();
    if(!context) return;

    if(!(n >= 0))
        alSetError(context, AL_INVALID_VALUE, "Generating %d filters", n);
    else for(cur = 0;cur < n;cur++)
    {
        ALfilter *filter = AllocFilter(context);
        if(!filter)
        {
            alDeleteFilters(cur, filters);
            break;
        }

        filters[cur] = filter->id;
    }

    ALCcontext_DecRef(context);
}
Beispiel #14
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);
}
Beispiel #15
0
static ALvoid CDECL wine_alDeleteFilters(ALsizei n, const ALuint* filters)
{
    alDeleteFilters(n, filters);
}