Beispiel #1
0
		bool Audio::initialize()
		{
			if(m_initialized)
			{
				return false;
			}

			m_device = alcOpenDevice(NULL);
			if(!m_device)
			{
				Utilities::printDebugString("[Gamma::Audio::Audio] Couldn't open an OpenAL device.\n");
				return false;
			}

			m_context = alcCreateContext(m_device, NULL);
			if(!m_context)
			{
				Utilities::printDebugString("[Gamma::Audio::Audio] Couldn't create an OpenAL context.\n");
				alcCloseDevice(m_device);
				return false;
			}

			if(!alcMakeContextCurrent(m_context))
			{
				Utilities::printDebugString("[Gamma::Audio::Audio] Couldn't activate the OpenAL context.\n");
				alcDestroyContext(m_context);
				alcCloseDevice(m_device);
				return false;
			}
			else
			{
				m_initialized = true;
			}

			// Set up the listener.
			setListenerPosition(Math::Vector3(0.0f, 0.0f, 0.0f));
			setListenerVelocity(Math::Vector3(0.0f, 0.0f, 0.0f));
			setListenerOrientation(Math::Vector3(0.0f, 0.0f, 1.0f), Math::Vector3(0.0f, 1.0f, 0.0f));

			return true;
		}
Beispiel #2
0
CarSoundData::CarSoundData(int id, SoundInterface* sound_interface)
{
    eng_pri.id = id;
    eng_pri.a = 1.0f;
    engine.a = 0.0f;
    engine.f = 1.0f;
    engine.lp = 1.0f;
    smooth_accel = 0.0f;
    drag_collision.a = 0.0f;
    drag_collision.f = 0.0f;
    pre_axle = 0.0f;
    axle.a = 0.0f;
    axle.f = 0.0f;
    turbo.a = 0.0f;
    turbo.f = 0.0f;
    engine_backfire.a=0.0f;
    prev_gear = 0;
    gear_changing = false;
    bottom_crash = false;
    bang = false;
    crash = false;
    turbo_on = false;
    turbo_ilag = 0.05f;
    turbo_rpm = 0.0f;
    this->sound_interface = sound_interface;
    for (int i=0; i<4; i++) {
        for (int j=0; j<3; j++) {
            wheel[i].p[j] = 0.0f;
            wheel[i].u[j] = 0.0f;
        }
        wheel[i].skid.a = 0.0f;
        wheel[i].skid.f = 1.0f;
    }
    sgVec3 zeroes = {0.0f, 0.0f, 0.0f};
    setCarPosition(zeroes);
    setCarSpeed(zeroes);
    setListenerPosition(zeroes);
    
    attenuation = 0.0f;
}
//------------------------------------------------------------------------------
void AudioSystem::update(sf::Time delta)
{
    if(r_listenerEntity != nullptr)
    {
        if(r_listenerEntity->transform())
        {
            setListenerPosition(r_listenerEntity->transform()->position());
        }
    }

    // Iterate over a copy to avoid concurrent modification
    auto updateList = m_emitters;

    for(auto it = updateList.begin(); it != updateList.end(); ++it)
    {
        AudioEmitter & cmp = **it;
        if(cmp.entity().active())
        {
            cmp.update();
        }
    }

//	music.update(delta);
}
AudioSystem::AudioSystem()
{
    setListenerPosition(sf::Vector2f(0,0));
    setListenerDepth(1);
    m_sources.resize(DEFAULT_SOURCES_COUNT);
}