void TestMovingObject::moveParentAndListenerHasPosition()
      {
        std::cerr << "TestMovingObject::moveParentAndListenerHasPosition" << std::endl ;
        std::cerr.flush() ;

        // we construct a complete system
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMovingObject::moveParentAndListenerHasPosition")) ;
        model->init() ;
        
        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positionned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener_ship = system->createObject() ;
        Model::Positionned* listener_ship_positionned = new Model::Positionned();
        listener_ship->addTrait(listener_ship_positionned) ;
        
        Kernel::Object* listener = listener_ship->createObject() ;
        listener->addTrait(new Model::Positionned()) ;
        listener->addTrait(new Model::Listener()) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());
        
        Kernel::Object* ship = system->createObject() ;
        Model::Positionned* ship_positionned = new Model::Positionned(Model::Position::Meter(0,0,-50));
        ship->addTrait(ship_positionned);
        ship->addTrait(new Model::Oriented()) ;
        ship->addTrait(new Model::Mobile());
        
        Kernel::Object* engine = ship->createObject() ;
        engine->addTrait(new Model::Engine(Model::Force::Newton(10,10,10))) ;
        engine->addTrait(new Model::Positionned()) ;
        
        Kernel::Timer global_timer ;
        Kernel::Timer timer ;
        
        float listener_position_x ;
        float listener_position_y ;
        float listener_position_z ;

        float expected_listener_position_x = 0 ;
        float expected_listener_position_y = 0 ;
        float expected_listener_position_z = 0 ;

        alGetListener3f(AL_POSITION,&listener_position_x,&listener_position_y,&listener_position_z) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_x,listener_position_x,delta) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_y,listener_position_y,delta) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_z,listener_position_z,delta) ;

        listener_ship_positionned->setPosition(listener_ship_positionned->getPosition()+Model::Position::Meter(0,0,-1));
        
        expected_listener_position_z -= 1 ;

        alGetListener3f(AL_POSITION,&listener_position_x,&listener_position_y,&listener_position_z) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_x,listener_position_x,delta) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_y,listener_position_y,delta) ;
        CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_z,listener_position_z,delta) ;
      }
Ejemplo n.º 2
0
////////////////////////////////////////////////////////////
/// Get the current position of the listener
////////////////////////////////////////////////////////////
ofxVec3f Listener::GetPosition()
{
    ofxVec3f Position;
    ALCheck(alGetListener3f(AL_POSITION, &Position.x, &Position.y, &Position.z));

    return Position;
}
Ejemplo n.º 3
0
Vector3f Listener::getPosition()
{
    Vector3f position;
    alCheck(alGetListener3f(AL_POSITION, &position.x, &position.y, &position.z));

    return position;
}
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL10_nalGetListener3f(JNIEnv *__env, jclass clazz, jint paramName, jlong value1Address, jlong value2Address, jlong value3Address, jlong __functionAddress) {
	ALfloat *value1 = (ALfloat *)(intptr_t)value1Address;
	ALfloat *value2 = (ALfloat *)(intptr_t)value2Address;
	ALfloat *value3 = (ALfloat *)(intptr_t)value3Address;
	alGetListener3fPROC alGetListener3f = (alGetListener3fPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	alGetListener3f(paramName, value1, value2, value3);
}
Ejemplo n.º 5
0
static
seal_err_t
get3f(int key, float* px, float* py, float* pz)
{
    alGetListener3f(key, px, py, pz);

    return _seal_get_openal_err();
}
Ejemplo n.º 6
0
Vector3f Listener::getPosition()
{
    priv::ensureALInit();

    Vector3f position;
    alCheck(alGetListener3f(AL_POSITION, &position.x, &position.y, &position.z));

    return position;
}
Ejemplo n.º 7
0
void al_getlistener3f( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) {

	if (NULL == alGetListener3f) mogl_glunsupported("alGetListener3f");
	alGetListener3f((ALenum)mxGetScalar(prhs[0]),
		(ALfloat*)mxGetData(prhs[1]),
		(ALfloat*)mxGetData(prhs[2]),
		(ALfloat*)mxGetData(prhs[3]));

}
Ejemplo n.º 8
0
value lime_al_get_listener3f (value param) {

    ALfloat val1, val2, val3;

    alGetListener3f (val_int (param), &val1, &val2, &val3);

    value result = alloc_array (3);
    val_array_set_i (result, 0, alloc_float (val1));
    val_array_set_i (result, 1, alloc_float (val2));
    val_array_set_i (result, 2, alloc_float (val3));
    return result;

}
Ejemplo n.º 9
0
AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)
{
    ALCcontext *Context;

    switch(eParam)
    {
        case AL_GAIN:
        case AL_METERS_PER_UNIT:
            alGetListenerf(eParam, pflValues);
            return;

        case AL_POSITION:
        case AL_VELOCITY:
            alGetListener3f(eParam, pflValues+0, pflValues+1, pflValues+2);
            return;
    }

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

    if(pflValues)
    {
        switch(eParam)
        {
            case AL_ORIENTATION:
                LockContext(Context);
                // AT then UP
                pflValues[0] = Context->Listener.Forward[0];
                pflValues[1] = Context->Listener.Forward[1];
                pflValues[2] = Context->Listener.Forward[2];
                pflValues[3] = Context->Listener.Up[0];
                pflValues[4] = Context->Listener.Up[1];
                pflValues[5] = Context->Listener.Up[2];
                UnlockContext(Context);
                break;

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

    ALCcontext_DecRef(Context);
}
Ejemplo n.º 10
0
//*
// =======================================================================================================================
// Compute the sample's volume relative to AL_POSITION.
// =======================================================================================================================
//
void sound_SetObjectPosition(AUDIO_SAMPLE *psSample)
{
#ifndef WZ_NOSOUND
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// coordinates
	float	listenerX, listenerY, listenerZ, dX, dY, dZ;

	// calculation results
	float	distance, gain;
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	// only set it when we have a valid sample
	if (!psSample)
	{
		return;
	}

	// compute distance
	alGetListener3f( AL_POSITION, &listenerX, &listenerY, &listenerZ );
	sound_GetError();
	dX = psSample->x  - listenerX; // distances on all axis
	dY = psSample->y - listenerY;
	dZ = psSample->z - listenerZ;
	distance = sqrtf(dX * dX + dY * dY + dZ * dZ); // Pythagorean theorem

	// compute gain
	gain = (1.0f - (distance * ATTENUATION_FACTOR)) * psSample->fVol * sfx3d_volume;
	// max volume
	if (gain > 1.0f)
	{
		gain = 1.0f;
	}
	if (gain < 0.0f)
	{
		// this sample can't be heard right now
		gain = 0.0f;
	}
	alSourcef( psSample->iSample, AL_GAIN, gain );

	// the alSource3i variant would be better, if it wouldn't provide linker errors however
	alSource3f( psSample->iSample, AL_POSITION, (float)psSample->x,(float)psSample->y,(float)psSample->z );
	sound_GetError();
#endif
	return;
}
Ejemplo n.º 11
0
AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values)
{
    ALCcontext *Context;

    switch(param)
    {
        case AL_GAIN:
        case AL_METERS_PER_UNIT:
            alGetListenerf(param, values);
            return;

        case AL_POSITION:
        case AL_VELOCITY:
            alGetListener3f(param, values+0, values+1, values+2);
            return;
    }

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

    al_try
    {
        CHECK_VALUE(Context, values);
        switch(param)
        {
            case AL_ORIENTATION:
                LockContext(Context);
                // AT then UP
                values[0] = Context->Listener->Forward[0];
                values[1] = Context->Listener->Forward[1];
                values[2] = Context->Listener->Forward[2];
                values[3] = Context->Listener->Up[0];
                values[4] = Context->Listener->Up[1];
                values[5] = Context->Listener->Up[2];
                UnlockContext(Context);
                break;

            default:
                al_throwerr(Context, AL_INVALID_ENUM);
        }
    }
    al_endtry;

    ALCcontext_DecRef(Context);
}
Ejemplo n.º 12
0
AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values)
{
    ALCcontext *context;

    switch(param)
    {
    case AL_GAIN:
    case AL_METERS_PER_UNIT:
        alGetListenerf(param, values);
        return;

    case AL_POSITION:
    case AL_VELOCITY:
        alGetListener3f(param, values+0, values+1, values+2);
        return;
    }

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

    ReadLock(&context->PropLock);
    if(!(values))
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    switch(param)
    {
    case AL_ORIENTATION:
        // AT then UP
        values[0] = context->Listener->Forward[0];
        values[1] = context->Listener->Forward[1];
        values[2] = context->Listener->Forward[2];
        values[3] = context->Listener->Up[0];
        values[4] = context->Listener->Up[1];
        values[5] = context->Listener->Up[2];
        break;

    default:
        SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
    }

done:
    ReadUnlock(&context->PropLock);
    ALCcontext_DecRef(context);
}
Ejemplo n.º 13
0
ALvoid CDECL wine_alGetListener3f(ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3)
{
    alGetListener3f(param, value1, value2, value3);
}
      void TestMovingObject::basicTest()
      {
        std::cerr << "TestMovingObject::basicTest" << std::endl ;
        std::cerr.flush() ;
        /*!
          - build a engine
          - build a listener
          - move the engine position
          - update the module for streaming during 10secondes
          -destroy all and clean sound module
        */

        // we construct a complete system
        std::auto_ptr<Kernel::Model> model(new Kernel::Model("TestMovingObject::basicTest")) ;
        model->init() ;
        
        Kernel::Object* system = model->createObject() ;
        system->addTrait(new Model::Positionned()) ;
        system->addTrait(new Model::Oriented()) ;

        Kernel::Object* listener = system->createObject() ;
        listener->addTrait(new Model::Listener()) ;
        Model::Positionned* listenerPos = new Model::Positionned();
        listener->addTrait(listenerPos) ;
        listener->addTrait(new Model::Oriented()) ;
        listener->addTrait(new Model::Mobile());

        Kernel::Object* engine = system->createObject() ;
        engine->addTrait(new Model::Engine(Model::Force::Newton(10,10,10))) ;
        Model::Positionned* enginePos = new Model::Positionned(Model::Position::Meter(0,0,-50));
        engine->addTrait(enginePos);
        engine->addTrait(new Model::Oriented()) ;
        engine->addTrait(new Model::Mobile());
        
        Kernel::ViewPoint* viewpoint = model->getViewPoint<Implementation::OpenAL::RealWorldViewPoint>() ;
        
        ALuint engine_source = 
          engine->getTrait<Implementation::Engine>()
                ->getView<Implementation::OpenAL::Engine>(viewpoint)->m_source ;
        
        Kernel::Timer global_timer ;
        Kernel::Timer timer ;

        float expected_position_x = 0 ;
        float expected_position_y = 0 ;
        float expected_position_z = -50 ;

        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
        
        /// moving on Z axis
        while (global_timer.getSecond() <= 1)
        {
          enginePos->setPosition(enginePos->getPosition()+ Model::Position::Meter(0,0,0.005));
          expected_position_z += 0.005 ;
          checkSourcePosition(engine_source,
                              expected_position_x,
                              expected_position_y,
                              expected_position_z) ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        
        /// moving on X axis
        global_timer.reset();
        enginePos->setPosition(Model::Position::Meter(-50,0,0));
        
        expected_position_x = -50 ;
        expected_position_y = 0 ;
        expected_position_z = 0 ;
        
        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
        
        while (global_timer.getSecond() <= 1)
        {
          enginePos->setPosition(enginePos->getPosition()+Model::Position::Meter(0.005,0,0));
          expected_position_x += 0.005 ;
          checkSourcePosition(engine_source,
                              expected_position_x,
                              expected_position_y,
                              expected_position_z) ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        
        /// moving on Y axis
        global_timer.reset();
        enginePos->setPosition(Model::Position::Meter(0,-50,0));
        
        expected_position_x = 0 ;
        expected_position_y = -50 ;
        expected_position_z = 0 ;
        
        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
        
        while (global_timer.getSecond() <= 1)
        {
          enginePos->setPosition(enginePos->getPosition()+Model::Position::Meter(0,0.005,0));
          expected_position_y += 0.005 ;
          checkSourcePosition(engine_source,
                              expected_position_x,
                              expected_position_y,
                              expected_position_z) ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        
        /// moving on X axis listener and source
        global_timer.reset();
        enginePos->setPosition(Model::Position::Meter(0,0,-100));
        
        expected_position_x = 0 ;
        expected_position_y = 0 ;
        expected_position_z = -100 ;
        
        checkSourcePosition(engine_source,
                            expected_position_x,
                            expected_position_y,
                            expected_position_z) ;
        
        float listener_position_x ;
        float listener_position_y ;
        float listener_position_z ;

        float expected_listener_position_x = 0 ;
        float expected_listener_position_y = 0 ;
        float expected_listener_position_z = 0 ;
        
        while (global_timer.getSecond() <= 1)
        {
          listenerPos->setPosition(listenerPos->getPosition()+ Model::Position::Meter(0,0,-0.005));
          expected_listener_position_z -= 0.005 ;
          
          alGetListener3f(AL_POSITION,&listener_position_x,&listener_position_y,&listener_position_z) ;
          CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_x,listener_position_x,delta) ;
          CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_y,listener_position_y,delta) ;
          CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_listener_position_z,listener_position_z,delta) ;
          
          enginePos->setPosition(enginePos->getPosition()+ Model::Position::Meter(0,0,0.005));
          expected_position_z += 0.005 ;
          checkSourcePosition(engine_source,
                              expected_position_x,
                              expected_position_y,
                              expected_position_z) ;
          float seconds = timer.getSecond() ;
          timer.reset() ;
          model->update(seconds) ;
        }
        
        InternalMessage("Sound","after sound close") ;
      }
Ejemplo n.º 15
0
/// gets velocity of the listener
void cSoundSystemOpenAl::GetListenerVelocity(float &x, float &y, float &z){alGetListener3f(AL_VELOCITY,&x,&y,&z);CheckOpenAl();}
Ejemplo n.º 16
0
Vector2 AudioManager::getVelocity() const
{
	Vector2 velocity(0.0f);
	alGetListener3f(AL_VELOCITY, &velocity.x, &velocity.y, 0);
	return velocity;
}
Ejemplo n.º 17
0
Vector2 AudioManager::getPosition() const
{
	Vector2 position(0.0f);
	alGetListener3f(AL_POSITION, &position.x, &position.y, 0);
	return position;
}
Ejemplo n.º 18
0
/// gets position of the listener
void cSoundSystemOpenAl::GetListenerPosition(float &x, float &y, float &z){alGetListener3f(AL_POSITION,&x,&y,&z);CheckOpenAl();}
Ejemplo n.º 19
0
	float3 OALAudioEngine::GetListenerVel() const
	{
		float3 v;
		alGetListener3f(AL_VELOCITY, &v[0], &v[1], &v[2]);
		return ALVecToVec(v);
	}
Ejemplo n.º 20
0
	float3 OALAudioEngine::GetListenerPos() const
	{
		float3 v;
		alGetListener3f(AL_POSITION, &v[0], &v[1], &v[2]);
		return ALVecToVec(v);
	}
Ejemplo n.º 21
0
//*****************************************************************************
// alGetListener3f
//*****************************************************************************
//
ALAPI ALvoid ALAPIENTRY alGetListener3f(ALenum param, ALfloat* v1, ALfloat* v2, ALfloat* v3)
{
    AL_VOID_FXN(alGetListener3f(param, v1, v2, v3));
}
Ejemplo n.º 22
0
//*
// =======================================================================================================================
// =======================================================================================================================
//
static bool audio_Play3DTrack( SDWORD iX, SDWORD iY, SDWORD iZ, int iTrack, SIMPLE_OBJECT *psObj, AUDIO_CALLBACK pUserCallback )
{
	//~~~~~~~~~~~~~~~~~~~~~~
	AUDIO_SAMPLE	*psSample;
	// coordinates
	float	listenerX = .0f, listenerY = .0f, listenerZ = .0f, dX, dY, dZ;
	// calculation results
	float	distance, gain;
#ifndef WZ_NOSOUND
	ALenum err;
#endif
	//~~~~~~~~~~~~~~~~~~~~~~

	// if audio not enabled return true to carry on game without audio
	if ( g_bAudioEnabled == false || g_bAudioPaused == true)
	{
		return false;
	}

	if ( audio_CheckSame3DTracksPlaying(iTrack, iX, iY, iZ) == false )
	{
		return false;
	}

	// compute distance
	// NOTE, if this call fails, expect garbage
#ifndef WZ_NOSOUND
	alGetListener3f(AL_POSITION, &listenerX, &listenerY, &listenerZ);
	err = sound_GetError();
	if (err != AL_NO_ERROR)
	{
		return false;
	}
#endif
	dX = (float)iX - listenerX; // distances on all axis
	dY = (float)iY - listenerY;
	dZ = (float)iZ - listenerZ;
	distance = sqrtf(dX * dX + dY * dY + dZ * dZ); // Pythagorean theorem

	// compute gain
	gain = (1.0 - (distance * ATTENUATION_FACTOR)) ;//* 1.0f * sfx3d_volume
	if (gain > 1.0f)
	{
		gain = 1.0f;
	}
	if (gain < 0.0f)
	{
		gain = 0.0f;
	}
	// don't bother adding samples that we can't hear
	if (gain == 0.0f)
	{
		return false;
	}

	psSample = (AUDIO_SAMPLE *)malloc(sizeof(AUDIO_SAMPLE));
	if ( psSample == NULL )
	{
		debug(LOG_ERROR, "audio_Play3DTrack: Out of memory");
		return false;
	}

	// setup sample
	memset( psSample, 0, sizeof(AUDIO_SAMPLE) );						// [check] -Q
	psSample->iTrack = iTrack;
	psSample->x = iX;
	psSample->y = iY;
	psSample->z = iZ;
	psSample->bFinishedPlaying = false;
	psSample->psObj = psObj;
	psSample->pCallback = pUserCallback;

	// add sample to list if able to play
	if ( !sound_Play3DTrack(psSample) )
	{
		debug( LOG_NEVER, "audio_Play3DTrack: couldn't play sample\n" );
		free(psSample);
		return false;
	}

	audio_AddSampleToHead( &g_psSampleList, psSample );
	return true;
}
Ejemplo n.º 23
0
	void Listener::getVelocity(osg::Vec3f& velocity) const
	{
		alGetListener3f(AL_VELOCITY, static_cast<ALfloat*>(&velocity[0]),
			static_cast<ALfloat*>(&velocity[1]),
			static_cast<ALfloat*>(&velocity[2]));
	}