Exemplo n.º 1
0
	ALboolean COALExtProvider::CreateEffect(ALuint *puiEffect, ALenum eEffectType)
	{
		if(!m_initialized) return AL_FALSE;

		ALboolean bReturn = AL_FALSE;
	
		if (puiEffect)
		{
			// Clear AL Error State
			alGetError();
	
			// Generate an Effect
			alGenEffects(1, puiEffect);
			if (alGetError() == AL_NO_ERROR)
			{
				// Set the Effect Type
				alEffecti(*puiEffect, AL_EFFECT_TYPE, eEffectType);
				if (alGetError() == AL_NO_ERROR)
					bReturn = AL_TRUE;
				else
					alDeleteEffects(1, puiEffect);
			}
		}
	
		return bReturn;
	}
Exemplo n.º 2
0
	SoundEffect::SoundEffect() :
		m_effect(0),
		m_slot(0),
		m_effectType(SE_EFFECT_NULL),
		m_enabled(false),
		m_filter(NULL) {

		alGenEffects(1, &m_effect);
	}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
ALboolean QOpenALEngine::CreateEffect(ALuint *puiEffect, ALenum eEffectType)
{
    ALboolean bReturn = AL_FALSE;

    if (puiEffect)
    {
        // Clear AL Error State
        alGetError();

        // Generate an Effect
        alGenEffects(1, puiEffect);
        if (alGetError() == AL_NO_ERROR)
        {
            // Set the Effect Type
            alEffecti(*puiEffect, AL_EFFECT_TYPE, eEffectType);
            if (alGetError() == AL_NO_ERROR)
                bReturn = AL_TRUE;
            else
                alDeleteEffects(1, puiEffect);
        }
    }

    return bReturn;
}
Exemplo n.º 6
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);
}
Exemplo n.º 7
0
static ALvoid CDECL wine_alGenEffects(ALsizei n, ALuint* effects)
{
    alGenEffects(n, effects);
}
Exemplo n.º 8
0
int main (int argc, char **argv) {

    #pragma region // --- my init ---
    float pitchnow = 1.0;
    alListener3f(AL_POSITION, 0.0, 0.0, 0.0);

    #pragma endregion

    #pragma region // --- al init ---
// alut の初期化

    alutInit (&argc, argv);

// Hello World としゃべる音声の作成
    ALuint helloBuffer = alutCreateBufferHelloWorld();
    ALuint MusicBuffer = alutCreateBufferFromFile(FILENAME);
    if(AL_NONE == helloBuffer) {
        std::cerr<<"error:nofile"<<std::endl;
        exit(1);
    }

// ソースの作成
    ALuint helloSource;
    alGenSources (1, &helloSource);
    ALuint MusicSource;
    alGenSources (1, &MusicSource);


// ソースにバッファをバインド
    alSourcei (helloSource, AL_BUFFER, helloBuffer);
    alSourcei (MusicSource, AL_BUFFER, MusicBuffer);
    #pragma endregion

    #pragma region // --- effect init ---

    ALCdevice *pDevice = alcOpenDevice(NULL);
    if(!pDevice) {
        std::cerr<<"error : device not found"<<std::endl;
        exit(1);
    }

    LPALGENEFFECTS alGenEffects=(LPALGENEFFECTS)alGetProcAddress("alGenEffects");


    #pragma region // --- set Reverb ---
    ALuint Effect = 0;
    alGenEffects(1, &Effect);
    alEffecti(Effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB);

    #pragma endregion


    #pragma endregion

    cv::namedWindow("hoge");
    alSourcePlay(MusicSource);

    alSource3f(MusicSource, AL_POSITION, 100.0, 0.0, 0.0);
    alSource3f(MusicSource, AL_VELOCITY, 10.0, 0.0, 0.0);

    while(1) {

        char key = cv::waitKey(1);
        if(key=='s') {
            alSourcePlay(helloSource);
            //alutSleep(1);
        }
        if(key == 'p') {
            int state;
            alGetSourcei(MusicSource, AL_SOURCE_STATE, &state);
            if(state ==AL_PAUSED)alSourcePlay(MusicSource);
            else alSourcePause(MusicSource);
        }
        else if(key == 'q') {
            std::cout<<"good bye"<<std::endl;
            break;
        }
        else if(key == 'u') {
            pitchnow *= 2;
            alSourcef(MusicSource, AL_PITCH, pitchnow);
        }
        else if(key == 'd') {
            pitchnow /= 2;
            alSourcef(MusicSource, AL_PITCH, pitchnow);
        }

        // roop
        int state;
        alGetSourcei(MusicSource, AL_SOURCE_STATE, &state);
        if(state != AL_PLAYING) alSourcePlay(MusicSource);

    }


    #pragma region --- release ---
    // リソースを開放
    alSourceStop(helloSource);
    alDeleteSources( 1, &helloSource );
    alDeleteBuffers( 1, &helloBuffer );
    alSourceStop(MusicSource);
    alDeleteSources( 1, &MusicSource );
    alDeleteBuffers( 1, &MusicBuffer );
    alutExit ();
    #pragma endregion

    return 0;
}