Exemple #1
0
void ListenerNode::updatePositionAndOrientation()
{
	//get absolute transformation of node, by default OpenAL uses absolute transformations
	const float *absMatPtr;
	getTransMatrices( 0x0, &absMatPtr );
	Matrix4f absMat( absMatPtr );

	Vec3f trans, rot, scale;
	absMat.decompose( trans, rot, scale );
	alListener3f( AL_POSITION, trans.x, trans.y, trans.z );

	//remove translation
	absMat.x[12] = 0;
	absMat.x[13] = 0;
	absMat.x[14] = 0;

	Vec3f forward = ( absMat * Vec3f( 0, 0, -1 ) ).normalized();
	Vec3f up = ( absMat * Vec3f( 0, 1, 0 ) ).normalized();

	float orientation[6];
	orientation[0] = forward.x;
	orientation[1] = forward.y;
	orientation[2] = forward.z;
	orientation[3] = up.x;
	orientation[4] = up.y;
	orientation[5] = up.z;

	alListenerfv( AL_ORIENTATION, orientation );
}
Exemple #2
0
/*
  call-seq: direction=(vector)

  Sets the audio listener's direction.
*/
VALUE Listener_directionOp(VALUE self, VALUE val)
{
   Vector3f &ref = getRef<Vector3f>(val);
   alListener3f(AL_DIRECTION, ref.x,ref.y, ref.z);

   return val;
}
Exemple #3
0
	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);
	}
Exemple #4
0
void AudioDevice::setPosition(const Vector3f& position)
{
    if (audioContext)
        alCheck(alListener3f(AL_POSITION, position.x, position.y, position.z));

    listenerPosition = position;
}
Exemple #5
0
/*
  call-seq:
    Joyau::Listener.pos=(vector) -> Vector3f

  Sets the audio listener's position.
*/
VALUE Listener_posOp(VALUE self, VALUE val)
{
   Vector3f &ref = getRef<Vector3f>(val);
   alListener3f(AL_POSITION, ref.x,ref.y, ref.z);

   return val;
}
Exemple #6
0
/*
  call-seq:
    Joyau::Listener.velocity=(vector) -> Vector3f

  Sets the audio listener's velocity.
*/
VALUE Listener_velocityOp(VALUE self, VALUE val)
{
   Vector3f &ref = getRef<Vector3f>(val);
   alListener3f(AL_VELOCITY, ref.x,ref.y, ref.z);

   return val;
}
	/*/////////////////////////////////////////////////////////////////*/
	void OgreOggListener::setVelocity(float velx, float vely, float velz)
	{
		mVelocity.x = velx;
		mVelocity.y = vely;
		mVelocity.z = velz;
		alListener3f(AL_VELOCITY, velx, vely, velz);
	}
OpenALAudio::OpenALAudio( unsigned poly ) :
	mPoly( poly ),
	mNextSource( 0 )
{
	// initialization
	mDevice = alcOpenDevice( NULL ); // select the "preferred device"

	if ( mDevice == NULL )
		throw OpenALAudioExc( "Could not open audio device" );

	mContext = alcCreateContext( mDevice, NULL );
	if ( mContext == NULL )
		throw "Could not open context " + string( alGetString( alcGetError( mDevice ) ) );
	alcMakeContextCurrent( mContext );

	alListener3f( AL_POSITION, 0.f, 0.f, 0.f );

	// generate the sources
	for ( int i = 0; i < mPoly; ++i )
	{
		unsigned id;
		alGenSources( 1, &id );
		mSources.push_back( id );
	}
}
Exemple #9
0
	void Listener::setVelocity(const osg::Vec3f& velocity)
	{
		alListener3f(AL_VELOCITY,
			static_cast<ALfloat>(velocity[0]),
			static_cast<ALfloat>(velocity[1]),
			static_cast<ALfloat>(velocity[2]));
	}
	/*/////////////////////////////////////////////////////////////////*/
	void OgreOggListener::setPosition(ALfloat x, ALfloat y, ALfloat z)
	{
		mPosition.x = x;
		mPosition.y = y;
		mPosition.z = z;
		alListener3f(AL_POSITION,x,y,z);
	}
Exemple #11
0
SonicDog::SonicDog( size_t threads ) {
	num_threads_ = threads;

	// alutInit( NULL, NULL );
	// checkError( "clearing messages", AL );
	alutGetError();
	if ( alutInitWithoutContext( NULL, NULL ) == AL_FALSE ) {
		checkError( "alutInitWithoutContext", ALUT );
	}

	device_ = alcOpenDevice( NULL );
	if ( device_ ) {
		context_ = alcCreateContext( device_, NULL );
		if ( context_ ) {
			alcMakeContextCurrent( context_ );
		} else {
			checkError( "alcCreateContext", AL );
		}
	} else {
		checkError( "alcOpenDevice", AL );
	}

	// set the position of the listener at the origin
	alListener3f( AL_POSITION, 0.0f, 0.0f, 0.0f );
	alListener3f( AL_VELOCITY, 0.0f, 0.0f, 0.0f );
	// ALfloat ori[] = { 0.0f, 0.0f, 1.0f };
	// alListenerfv( AL_ORIENTATION, ori );

	// initialize the object id
	object_id_ = 1;

	// initialize the locks
	pthread_mutex_init( &play_lock_, NULL );
	pthread_mutex_init( &sources_lock_, NULL );
	pthread_mutex_init( &remove_lock_, NULL );
	pthread_mutex_init( &pause_lock_, NULL );
	pthread_mutex_init( &q_lock_, NULL );
	pthread_mutex_init( &turns_lock_, NULL );
	pthread_cond_init( &empty_q_lock_, NULL );
	pthread_cond_init( &pause_cond_lock_, NULL );

	// boolean to toggle regions on or off
	regions_ = true;
	cutoff_ = false;
	front_only_ = false;
}
//---------------------------------------
// this should only be called once
void ofOpenALSoundPlayer::initialize(){
    if(alDevice == NULL){
        alDevice = alcOpenDevice(NULL);
        alContext = alcCreateContext(alDevice,NULL);
        alcMakeContextCurrent (alContext);
        alListener3f(AL_POSITION, 0,0,0);
    }
}
Exemple #13
0
static
seal_err_t
set3f(int key, float x, float y, float z)
{
    alListener3f(key, x, y, z);

    return _seal_get_openal_err();
}
Exemple #14
0
void AudioManager::set_listener_transform(Transform::ShPtr transform) {
  Vector3f up = transform->get_rotation() * Vector3f::UNIT_Y;
  Vector3f normal = transform->get_rotation() * Vector3f::NEGATIVE_Z;
  Vector3f pos = transform->get_position();
  alListener3f(AL_POSITION, pos.x(), pos.y(), pos.z());
  ALfloat orientation[6] = {normal.x(), normal.y(), normal.z(), up.x(), up.y(), up.z()};
  alListenerfv(AL_ORIENTATION, orientation);
}
 void OpenALRenderableListener::updateImpl(int flags) 
     throw(Exception)
 {
     if (flags & UPDATE_LOCATION) {
         const Vector3 pos(getListener()->getPosition()); // no option but to cast it down to float :(
         const Vector3 vel(getListener()->getVelocity());
         const Vector3 at (getListener()->getAtDirection());
         const Vector3 up (getListener()->getUpDirection());
         ALfloat ori[] = { at.x, at.y, at.z, up.x, up.y, up.z };
         
         alListener3f(AL_POSITION, pos.x, pos.y, pos.z);
         alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z);
         alListenerfv(AL_ORIENTATION, ori);
     }
     if (flags & UPDATE_ATTRIBUTES) {
         alListenerf (AL_GAIN, getListener()->getGain());
     }
 }
Exemple #16
0
/*
  call-seq: setVelocity(x, y, z)

  Sets the audio listener's velocity.
*/
VALUE Listener_setVelocity(VALUE self, VALUE x, VALUE y, VALUE z)
{
   double _x = NUM2DBL(x);
   double _y = NUM2DBL(y);
   double _z = NUM2DBL(z);

   alListener3f(AL_VELOCITY, _x, _y, _z);
   return Qnil;
}
Exemple #17
0
/*
  call-seq: setPos(x, y, z)

  Sets the audio listener's position.
*/
VALUE Listener_setPos(VALUE self, VALUE x, VALUE y, VALUE z)
{
   double _x = NUM2DBL(x);
   double _y = NUM2DBL(y);
   double _z = NUM2DBL(z);

   alListener3f(AL_POSITION, _x, _y, _z);
   return Qnil;
}
Exemple #18
0
/*
  call-seq: setDirection(x, y, z)

  Sets the audio listener's direction.
*/
VALUE Listener_setDirection(VALUE self, VALUE x, VALUE y, VALUE z)
{
   double _x = NUM2DBL(x);
   double _y = NUM2DBL(y);
   double _z = NUM2DBL(z);

   alListener3f(AL_DIRECTION, _x, _y, _z);
   return Qnil;
}
Exemple #19
0
void al_listener3f( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) {

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

}
void EOSAudioDevice::listenerSetPosition(float px, float py, float pz)
{
    checkErrors("pre-listenerSetPosition()");
	_listenerPos[0] = px * _distanceFactor;
	_listenerPos[1] = py * _distanceFactor;
	_listenerPos[2] = pz * _distanceFactor;
	alListener3f(AL_POSITION, _listenerPos[0], _listenerPos[1], _listenerPos[2]);
	checkErrors("listenerSetPosition()");
}
	void Listener::setVelocity(Ogre::Real x, Ogre::Real y, Ogre::Real z)
	{
		mVelocity.x = x;
		mVelocity.y = y;
		mVelocity.z = z;

		alListener3f(AL_VELOCITY, mVelocity.x, mVelocity.y, mVelocity.z);
		CheckError(alGetError(), "Failed to set Velocity");
	}
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);
}
Exemple #23
0
ga_DeviceImpl_OpenAl* gaX_device_open_openAl(gc_int32 in_numBuffers,
                                             gc_int32 in_numSamples,
                                             ga_Format* in_format)
{
  ga_DeviceImpl_OpenAl* ret = gcX_ops->allocFunc(sizeof(ga_DeviceImpl_OpenAl));
  ALCboolean ctxRet;

  ret->devType = GA_DEVICE_TYPE_OPENAL;
  ret->numBuffers = in_numBuffers;
  ret->numSamples = in_numSamples;
  memcpy(&ret->format, in_format, sizeof(ga_Format));
  ret->nextBuffer = 0;
  ret->emptyBuffers = ret->numBuffers;
//#ifdef _WIN32
#if 0
  ret->dev = alcOpenDevice("DirectSound");
#else
  ret->dev = alcOpenDevice(0);
#endif /* _WIN32 */
  if(!ret->dev)
    goto cleanup;
  ret->context = alcCreateContext(ret->dev, 0);
  if(!ret->context)
    goto cleanup;
  ctxRet = alcMakeContextCurrent(ret->context);
  if(ctxRet == ALC_FALSE)
    goto cleanup;

  alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f);
  CHECK_AL_ERROR;
  if(AUDIO_ERROR != AL_NO_ERROR)
    goto cleanup;
  ret->hwBuffers = gcX_ops->allocFunc(sizeof(gc_uint32) * ret->numBuffers);
  alGenBuffers(ret->numBuffers, ret->hwBuffers);
  CHECK_AL_ERROR;
  if(AUDIO_ERROR != AL_NO_ERROR)
    goto cleanup;
  alGenSources(1, &ret->hwSource);
  CHECK_AL_ERROR;
  if(AUDIO_ERROR != AL_NO_ERROR)
  {
    alDeleteBuffers(ret->numBuffers, ret->hwBuffers);
    goto cleanup;
  }
  return ret;

cleanup:
  if(ret->hwBuffers)
    gcX_ops->freeFunc(ret->hwBuffers);
  if(ret->context)
    alcDestroyContext(ret->context);
  if(ret->dev)
    alcCloseDevice(ret->dev);
  gcX_ops->freeFunc(ret);
  return 0;
}
Exemple #24
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;
}
//Set listener position (3d sound)
void SoundManager::SetListenerPosition( float posx, float posy, float posz )
{
	alListener3f(AL_POSITION, posx,posy,posz);
	//Check errors
	ALenum error(alGetError());
	if(error != AL_NO_ERROR)
	{
		SingletonLogMgr::Instance()->AddNewLine("SoundManager::SetListenerPosition","Failure while setting listener values (" + GetALErrorString(error,false) + ")",LOGEXCEPTION);
	}
}
Exemple #26
0
void CSoundListener::updateSound(){
    const CVector3 &v = getDerivedPosition();
	alListener3f(AL_POSITION, v.x, v.y, v.z);
	alListenerfv(AL_VELOCITY, &getVelocity().x);
	CVector3 ori[2];
	CQuaternion q = getDerivedOrientation();
	ori[0] = q * CVector3(0, 0, -1);
	ori[1] = q * CVector3(0, 1, 0);
	alListenerfv(AL_ORIENTATION, &ori[0].x);	
}
        void SoundListener::updateListener()
        {                           
          Ogre::Vector3 position = this->getPosition().Meter() ;
          alListener3f(AL_POSITION, (float)position.x, (float)position.y, (float)position.z);
          Ogre::Quaternion orientation = this->getOrientation().getQuaternion();

          ALfloat openal_orientation[6] ;
          openal_orientation[0] = orientation.zAxis().x ;
          openal_orientation[1] = orientation.zAxis().y ;
          openal_orientation[2] = orientation.zAxis().z ;
          openal_orientation[3] = orientation.yAxis().x ;
          openal_orientation[4] = orientation.yAxis().y ;
          openal_orientation[5] = orientation.yAxis().z ;
          
          alListenerfv(AL_ORIENTATION, openal_orientation) ; 
                      
          Ogre::Vector3 speed = this->getSpeed().MeterPerSecond();
          alListener3f(AL_VELOCITY, (float)speed.x, (float)speed.y, (float)speed.z) ;
          alListenerf(AL_GAIN,getGain()) ;
        }
Exemple #28
0
void WSoundComponent::SetToOrientationDevice(WOrientation* ori) {
	float fVals[6];
	for (uint i = 0; i < 6; i++) {
		if (i < 3)
			fVals[i] = ori->GetLVector()[i];
		else
			fVals[i] = ori->GetUVector()[i];
	}
	alListenerfv(AL_ORIENTATION, fVals);
	alListener3f(AL_POSITION, ori->GetPositionX(), ori->GetPositionY(), ori->GetPositionZ());
}
Exemple #29
0
AL_API ALvoid AL_APIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
{
    ALCcontext *pContext;
    ALboolean updateWorld = AL_FALSE;

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

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

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

            case AL_ORIENTATION:
                // AT then UP
                pContext->Listener.Forward[0] = pflValues[0];
                pContext->Listener.Forward[1] = pflValues[1];
                pContext->Listener.Forward[2] = pflValues[2];
                pContext->Listener.Up[0] = pflValues[3];
                pContext->Listener.Up[1] = pflValues[4];
                pContext->Listener.Up[2] = pflValues[5];
                updateWorld = AL_TRUE;
                break;

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

    if(updateWorld)
    {
        ALsizei pos;
        for(pos = 0;pos < pContext->SourceMap.size;pos++)
        {
            ALsource *source = pContext->SourceMap.array[pos].value;
            if(!source->bHeadRelative)
                source->NeedsUpdate = AL_TRUE;
        }
    }

    ProcessContext(pContext);
}
Exemple #30
0
void ALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat)
{
    m_eye = eye;
    m_lookat = lookat;
    Math::Vector forward = lookat - eye;
    forward.Normalize();
    float orientation[] = {forward.x, forward.y, forward.z, 0.f, -1.0f, 0.0f};

    alListener3f(AL_POSITION, eye.x, eye.y, eye.z);
    alListenerfv(AL_ORIENTATION, orientation);
}