Beispiel #1
0
bool CSound::Mute()
{
	mute = !mute;
	if (mute)
		alListenerf(AL_GAIN, 0.0);
	else
		alListenerf(AL_GAIN, masterVolume);
	return mute;
}
Beispiel #2
0
bool CSound::Mute()
{
	boost::recursive_mutex::scoped_lock lck(soundMutex);
	mute = !mute;
	if (mute)
		alListenerf(AL_GAIN, 0.0);
	else
		alListenerf(AL_GAIN, masterVolume);
	return mute;
}
Beispiel #3
0
void CSound::Iconified(bool state)
{
	if (appIsIconified != state && !mute)
	{
		if (state == false)
			alListenerf(AL_GAIN, masterVolume);
		else if (state == true)
			alListenerf(AL_GAIN, 0.0);
	}
	appIsIconified = state;
}
Beispiel #4
0
void CSound::Iconified(bool state)
{
	boost::recursive_mutex::scoped_lock lck(soundMutex);
	if (appIsIconified != state && !mute)
	{
		if (state == false)
			alListenerf(AL_GAIN, masterVolume);
		else if (state == true)
			alListenerf(AL_GAIN, 0.0);
	}
	appIsIconified = state;
}
Beispiel #5
0
bool ALSound::Create()
{
    CleanUp();

    if (m_enabled)
        return true;

    GetLogger()->Info("Opening audio device...\n");
    m_device = alcOpenDevice(nullptr);
    if (!m_device)
    {
        GetLogger()->Error("Could not open audio device!\n");
        return false;
    }

    m_context = alcCreateContext(m_device, nullptr);
    if (!m_context)
    {
        GetLogger()->Error("Could not create audio context!\n");
        return false;
    }
    alcMakeContextCurrent(m_context);
    alListenerf(AL_GAIN, m_audioVolume);
    alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);

    GetLogger()->Info("Done.\n");
    m_enabled = true;
    return true;
}
Beispiel #6
0
void AudioSystem::setListenerGain(float gain) {
   SHINY_CHECK_AUDIO_SYSTEM_VALID_CURRENT("setting listener gain");
   ASSERT(gain >= 0.0f, "Invalid gain value: %f, sould be non-negative", gain);

   alListenerf(AL_GAIN, gain);
   SHINY_CHECK_AL_ERROR("setting listener gain");
}
Beispiel #7
0
HG_ERROR SoundManager::initialize()
{
    HG_ERROR err = HG_OK;
    
    BREAK_START;
    
    mDevice = alcOpenDevice(NULL);
    if (mDevice == NULL)
    {
        err = HG_ERROR_AL_DEVICE_NOT_SUPPORT;
        break;
    }
    
    mContext = alcCreateContext(mDevice, NULL);
    if (mContext == NULL)
    {
        err = HG_ERROR_AL_CONTEXT_FAILED;
        break;
    }
    
    alcMakeContextCurrent(mContext);
    
    alListenerf(AL_GAIN, 1.0f);
    
    // Doppler
    alDopplerFactor(1.0f);
    alDopplerVelocity(343.0f);
    
    BREAK_END;
    
    return err;
}
Beispiel #8
0
void al_listenerf( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) {

	if (NULL == alListenerf) mogl_glunsupported("alListenerf");
	alListenerf((ALenum)mxGetScalar(prhs[0]),
		(ALfloat)mxGetScalar(prhs[1]));

}
	void SoundManager::init() {
		m_device = alcOpenDevice(NULL);

		if (!m_device || alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Could not open audio device - deactivating audio module");
			m_device = NULL;
			return;
		}

		m_context = alcCreateContext(m_device, NULL);
		if (!m_context || alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Couldn't create audio context - deactivating audio module");
			m_device = NULL;
			return;
		}

		alcMakeContextCurrent(m_context);
		if (alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Couldn't change current audio context - deactivating audio module");
			m_device = NULL;
			return;
		}

		// set listener position
		alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
		ALfloat vec1[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
		alListenerfv(AL_ORIENTATION, vec1);

		// set volume
		alListenerf(AL_GAIN, m_volume);
	}
Beispiel #10
0
void Audio::perFrame(){

	if(!active){	//update the fake audio objects
		for(int i=0; i<sources.size(); i++){
			sources[i]->perFrame();
		}
	}

	if(active){

		for(int i=0; i<sources.size(); i++){
			sources[i]->perFrame();
		}

		alListener3f(AL_POSITION,    level->camera->pos.x,level->camera->pos.y,level->camera->pos.z);
		alListener3f(AL_VELOCITY,    level->camera->velocity.x,level->camera->velocity.y,level->camera->velocity.z);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		level->camera->transform();

		double mMatrix[16];
		glGetDoublev(GL_MODELVIEW_MATRIX,mMatrix);

		SetListenerOrientation(-mMatrix[2],-mMatrix[6],-mMatrix[10],mMatrix[1],mMatrix[5],mMatrix[9]);
			//set listener orientation, first 3 numbers are for the forward vector, last three are for the up vecto

		if(volume<0){volume=0;}
		if(volume>1){volume=1;}

		
		alListenerf(AL_GAIN, volume);
	}
}
void SoundSystem::SetVolume(float32 _volume)
{
	volume = Clamp(_volume, 0.f, 1.f);
#ifdef __DAVASOUND_AL__
	AL_VERIFY(alListenerf(AL_GAIN, volume));
#endif
}
Beispiel #12
0
void CSound::ConfigNotify(const std::string& key, const std::string& value)
{
	if (key == "snd_volmaster")
	{
		masterVolume = std::atoi(value.c_str()) * 0.01f;
		if (!mute && !appIsIconified)
			alListenerf(AL_GAIN, masterVolume);
	}
	else if (key == "snd_volgeneral")
	{
		Channels::General.SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "snd_volunitreply")
	{
		Channels::UnitReply.SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "snd_volbattle")
	{
		Channels::Battle.SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "snd_volui")
	{
		Channels::UserInterface.SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "PitchAdjust")
	{
		bool tempPitchAdjust = (std::atoi(value.c_str()) != 0);
		if (!tempPitchAdjust)
			PitchAdjust(1.0);
		pitchAdjust = tempPitchAdjust;
	}
}
int DS_Init(void)
{
    // Already initialized?
    if(initOk) return true;

    // Open the default playback device.
    device = alcOpenDevice(NULL);
    if(!device)
    {
        Con_Message("OpenAL init failed (default playback device).");
        return false;
    }

    // Create and make current a new context.
    alcMakeContextCurrent(context = alcCreateContext(device, NULL));
    DSOPENAL_ERRCHECK(alGetError());

    // Attempt to load and configure the EAX extensions.
    loadExtensions();

    // Configure the listener and global OpenAL properties/state.
    alListenerf(AL_GAIN, 1);
    alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
    headYaw = headPitch = 0;
    unitsPerMeter = 36;

    // Everything is OK.
    DSOPENAL_TRACE("DS_Init: OpenAL initialized%s." << (hasEAX? " (EAX 2.0 available)" : ""));
    initOk = true;
    return true;
}
	void Listener::setGain(Ogre::Real gain)
	{
		mGain = gain;

		alListenerf(AL_GAIN, mGain);
		CheckError(alGetError(), "Failed to set Gain");
	}
		//! Sets new volume of listener.
		void CSoundListenerOpenAL::setVolume(const f32 value)
		{
			//TODO: check max value
			IRR_ASSERT(value >=0.0);

			alListenerf(AL_GAIN, value);
		}
Beispiel #16
0
void AudioDevice::setGlobalVolume(float volume)
{
    if (audioContext)
        alCheck(alListenerf(AL_GAIN, volume * 0.01f));

    listenerVolume = volume;
}
Beispiel #17
0
void HGE_Impl::_SetFXVolume(int vol)
{
	if(hOpenAL)
	{
		alListenerf(AL_GAIN, ((ALfloat) vol) / 100.0f);
	}
}
Beispiel #18
0
bool CListener::Set_Listener_Volume(ALfloat fVolume)
{
	std::unique_lock<std::mutex> lock(_mutex);
	alListenerf(AL_GAIN,fVolume);

	return !OpenAL_Check_Error();
}
void ListenerNode::activate()
{
	alListenerf( AL_GAIN, _gain );
	alDopplerFactor( _dopplerFactor );
	alSpeedOfSound( _speedOfSound );

	updatePositionAndOrientation();
}
Beispiel #20
0
void SoundManager::setListenerGain(float gain) {
	checkReady();

	Common::StackLock lock(_mutex);

	if (_hasSound)
		alListenerf(AL_GAIN, gain);
}
Beispiel #21
0
static
seal_err_t
setf(int key, float val)
{
    alListenerf(key, val);

    return _seal_get_openal_err();
}
Beispiel #22
0
/**
 * @brief Open an audio output device
 */
bool OpenAL2::initOutput(const QString& deviceName)
{
    peerSources.clear();

    outputInitialized = false;
    if (!Settings::getInstance().getAudioOutDevEnabled()) {
        return false;
    }

    qDebug() << "Opening audio output" << deviceName;
    assert(!alOutDev);

    const QByteArray qDevName = deviceName.toUtf8();
    const ALchar* tmpDevName = qDevName.isEmpty() ? nullptr : qDevName.constData();
    alOutDev = alcOpenDevice(tmpDevName);

    if (!alOutDev) {
        qWarning() << "Cannot open output audio device" << deviceName;
        return false;
    }

    qDebug() << "Opened audio output" << deviceName;
    alOutContext = alcCreateContext(alOutDev, nullptr);
    checkAlcError(alOutDev);

    if (!alcMakeContextCurrent(alOutContext)) {
        qWarning() << "Cannot create output audio context";
        return false;
    }

    // try to init echo cancellation
    echoCancelSupported = initOutputEchoCancel();

    if (!echoCancelSupported) {
        // fallback to normal, no proxy device needed
        qDebug() << "Echo cancellation disabled";
        alProxyDev = alOutDev;
        alProxyContext = alOutContext;
    }

    alGenSources(1, &alMainSource);
    checkAlError();

    // init master volume
    alListenerf(AL_GAIN, Settings::getInstance().getOutVolume() * 0.01f);
    checkAlError();

    Core* core = Core::getInstance();
    if (core) {
        // reset each call's audio source
        core->getAv()->invalidateCallSources();
    }

    // ensure alProxyContext is active
    alcMakeContextCurrent(alProxyContext);
    outputInitialized = true;
    return true;
}
Beispiel #23
0
void CSound::ConfigNotify(const std::string& key, const std::string& value)
{
	boost::recursive_mutex::scoped_lock lck(soundMutex);
	if (key == "snd_volmaster")
	{
		masterVolume = std::atoi(value.c_str()) * 0.01f;
		if (!mute && !appIsIconified)
			alListenerf(AL_GAIN, masterVolume);
	}
	else if (key == "snd_eaxpreset")
	{
		efx->SetPreset(value);
	}
	else if (key == "snd_filter")
	{
		float gainlf = 1.f;
		float gainhf = 1.f;
		sscanf(value.c_str(), "%f %f", &gainlf, &gainhf);
		efx->sfxProperties->filter_properties_f[AL_LOWPASS_GAIN]   = gainlf;
		efx->sfxProperties->filter_properties_f[AL_LOWPASS_GAINHF] = gainhf;
		efx->CommitEffects();
	}
	else if (key == "UseEFX")
	{
		bool enable = (std::atoi(value.c_str()) != 0);
		if (enable)
			efx->Enable();
		else
			efx->Disable();
	}
	else if (key == "snd_volgeneral")
	{
		Channels::General->SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "snd_volunitreply")
	{
		Channels::UnitReply->SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "snd_volbattle")
	{
		Channels::Battle->SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "snd_volui")
	{
		Channels::UserInterface->SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "snd_volmusic")
	{
		Channels::BGMusic->SetVolume(std::atoi(value.c_str()) * 0.01f);
	}
	else if (key == "PitchAdjust")
	{
		bool tempPitchAdjust = (std::atoi(value.c_str()) != 0);
		if (!tempPitchAdjust)
			PitchAdjust(1.0);
		pitchAdjust = tempPitchAdjust;
	}
}
//Sets global gain for sound
void SoundManager::SetGain(float gain)
{
	alListenerf(AL_GAIN,gain);
	ALenum error(alGetError());
	if(error != AL_NO_ERROR)
	{
		SingletonLogMgr::Instance()->AddNewLine("SoundManager::SetGain","Failure while changing main volume (" + GetALErrorString(error,false) + ")",LOGEXCEPTION);
	}
}
Beispiel #25
0
/**
 * @brief Set the master output volume.
 *
 * @param[in] volume   the master volume (between 0 and 1)
 */
void OpenAL::setOutputVolume(qreal volume)
{
    QMutexLocker locker(&audioLock);

    volume = std::max(0.0, std::min(volume, 1.0));

    alListenerf(AL_GAIN, static_cast<ALfloat>(volume));
    checkAlError();
}
Beispiel #26
0
void OpenALDevice::setVolume(float volume)
{
	if(volume < 0.0f)
		return;

	std::lock_guard<std::recursive_mutex> lock(m_mutex);

	alListenerf(AL_GAIN, volume);
}
Beispiel #27
0
AL_API ALvoid AL_APIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
{
    ALCcontext *Context;

    if(pflValues)
    {
        switch(eParam)
        {
            case AL_GAIN:
            case AL_METERS_PER_UNIT:
                alListenerf(eParam, pflValues[0]);
                return;

            case AL_POSITION:
            case AL_VELOCITY:
                alListener3f(eParam, pflValues[0], pflValues[1], pflValues[2]);
                return;
        }
    }

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

    if(pflValues)
    {
        switch(eParam)
        {
            case AL_ORIENTATION:
                if(isfinite(pflValues[0]) && isfinite(pflValues[1]) &&
                   isfinite(pflValues[2]) && isfinite(pflValues[3]) &&
                   isfinite(pflValues[4]) && isfinite(pflValues[5]))
                {
                    LockContext(Context);
                    // AT then UP
                    Context->Listener.Forward[0] = pflValues[0];
                    Context->Listener.Forward[1] = pflValues[1];
                    Context->Listener.Forward[2] = pflValues[2];
                    Context->Listener.Up[0] = pflValues[3];
                    Context->Listener.Up[1] = pflValues[4];
                    Context->Listener.Up[2] = pflValues[5];
                    Context->UpdateSources = AL_TRUE;
                    UnlockContext(Context);
                }
                else
                    alSetError(Context, AL_INVALID_VALUE);
                break;

            default:
                alSetError(Context, AL_INVALID_ENUM);
                break;
        }
    }
    else
        alSetError(Context, AL_INVALID_VALUE);

    ALCcontext_DecRef(Context);
}
Beispiel #28
0
void CSoundManager::SetMasterGain(float gain)
{
	if (m_Enabled)
	{
		m_Gain = gain;
		alListenerf(AL_GAIN, m_Gain);
		AL_CHECK;
	}
}
Beispiel #29
0
static int lua_alListener(lua_State* lua_state)
{
	ALenum enum_parameter;
	int openal_primitive_type;

	enum_parameter = lua_tointeger(lua_state, 1);


	openal_primitive_type = lua_getTypeForEnum(enum_parameter);

	switch(openal_primitive_type)
	{
		case LUAOPENAL_BOOL_TYPE:
		case LUAOPENAL_INT_TYPE:
		{
			alListeneri(enum_parameter, lua_tointeger(lua_state, 2));
			break;
		}
		case LUAOPENAL_FLOAT_TYPE:
		{
			alListenerf(enum_parameter, lua_tonumber(lua_state, 2));
			break;
		}
		case LUAOPENAL_INT_3_TYPE:
		{
			alListener3i(enum_parameter, lua_tointeger(lua_state, 2), lua_tointeger(lua_state, 3),  lua_tointeger(lua_state, 4));
			break;			
		}
		case LUAOPENAL_FLOAT_3_TYPE:
		{
			alListener3f(enum_parameter, lua_tonumber(lua_state, 2),  lua_tonumber(lua_state, 3),  lua_tonumber(lua_state, 4));
			break;			
		}
		case LUAOPENAL_FLOAT_6_TYPE:
		{
			ALfloat val_array[6] = 
			{
				lua_tonumber(lua_state, 2),
				lua_tonumber(lua_state, 3),
				lua_tonumber(lua_state, 4),
				lua_tonumber(lua_state, 5),
				lua_tonumber(lua_state, 6),
				lua_tonumber(lua_state, 7)
			};

			alListenerfv(enum_parameter, val_array);
			break;			
		}
		default:
		{
			/* TODO: Figure out how to handle OpenAL extensions. */
			luaL_error(lua_state, "Unhandled parameter type for alSource*");
		}
	}
	return 0;
}
Beispiel #30
0
void AudioDevice::setVolume(float volume)
{
	alListenerf(AL_GAIN, volume);

	if(AudioCheckError()) 
	{
		LogWarn("Error changing listener volume: %s", AudioGetError());
		return;
	}
}