예제 #1
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;
}
예제 #2
0
void CAListener::SetVel( const TVec &roVel ) const
{
#ifdef A_USE_OAL_DUMMY
#else
	ALint iError;
	alGetError();
	alListenerfv( AL_VELOCITY, roVel );
	if( ( iError = alGetError() ) != AL_NO_ERROR )
	{
		A_ERR( "alListenerfv VELOCITY (%s)\n", GetALErrorString_( iError ) );
		return;
	}
#endif // A_USE_OAL_DUMMY
}
예제 #3
0
void Camera::init(float x, float y){
    position->x = x;
    position->y = y;
    
    listenerPos[0] = 0.0;
    listenerPos[1] = 0.0;
    listenerPos[2] = 0.0;

    listenerVel[0] = 0.0;
    listenerVel[1] = 0.0;
    listenerVel[2] = 0.0;

    listenerOri[0] = 0.0;
    listenerOri[1] = 0.0;
    listenerOri[2] = -1.0;
    listenerOri[3] = 0.0;
    listenerOri[4] = 1.0;
    listenerOri[5] = 0.0;
    
    alListenerfv(AL_POSITION,    listenerPos);
    alListenerfv(AL_VELOCITY,    listenerVel);
    alListenerfv(AL_ORIENTATION, listenerOri);
}
예제 #4
0
		void setDirection(const Vector3f &direction)
		{
			listenerDirection = direction;
			float orientation[] = 
			{
				listenerDirection.x, // Direction
				listenerDirection.y,
				listenerDirection.z,
				listenerUpVector.x, // Up vector
				listenerUpVector.y,
				listenerUpVector.z,
			};
			alListenerfv(AL_ORIENTATION, orientation);
		}
예제 #5
0
void CAListener::SetPos( const TVec &roPos ) const
{
#ifdef A_USE_OAL_DUMMY
#else
	ALint iError;
	alGetError();
	alListenerfv( AL_POSITION, roPos );
	if( ( iError = alGetError() ) != AL_NO_ERROR )
	{
		A_ERR( "alListenerfv POSITION (%s)\n", GetALErrorString_( iError ) );
		return;
	}
#endif // A_USE_OAL_DUMMY
}
예제 #6
0
파일: testorient.c 프로젝트: Aye1/RVProject
static void setposition(ALfloat x, ALfloat y, ALfloat z) {
	ALfloat pos[3];

	pos[0] = x; pos[1] = y; pos[2] = z;

	fprintf(stderr, "POSITION: [%f, %f, %f]\n",
		x, y, z);

	alListenerfv( AL_POSITION, pos );

	fprintf(stderr, "--------------------------------\n");

	return;
}
예제 #7
0
static void init( const ALbyte *fname )
{
	ALfloat zeroes[] = { 0.0f, 0.0f, 0.0f };
	ALfloat back[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
	ALfloat front[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f };
	ALuint boom;

	start = time( NULL );

	alListenerfv( AL_POSITION, zeroes );
	alListenerfv( AL_VELOCITY, zeroes );
	alListenerfv( AL_ORIENTATION, front );

	boom = CreateBufferFromFile( fname );
	
	alGenSources( 1, &movingSource );

	alSourcefv( movingSource, AL_POSITION, srcposition );
	alSourcefv( movingSource, AL_VELOCITY, zeroes );
	alSourcefv( movingSource, AL_DIRECTION, back );
	alSourcei( movingSource, AL_BUFFER, boom );
	alSourcei( movingSource, AL_LOOPING, AL_TRUE );
}
예제 #8
0
	void Listener::clear(void)
	{
		union
		{
			ALfloat ort[6];
			struct
			{
				ALfloat at[3];
				ALfloat up[3];
			};
		}  orient;
		orient.ort[0] = 0.0f;
		orient.ort[1] = 1.0f;
		orient.ort[2] = 0.0f;
		orient.ort[3] = 0.0f;
		orient.ort[4] = 0.0f;
		orient.ort[5] = 1.0f;
		ALfloat  pos[3L] = { 0.0f, 0.0f, 0.0f };
		alListenerfv(AL_POSITION, pos);
		alListenerfv(AL_ORIENTATION, orient.ort);
		setVelocity(osg::Vec3f(0.0f, 0.0f, 0.0f));
		setGain(1.0);
	}
예제 #9
0
static void init( const char *fname) {
	ALfloat zeroes[] = { 0.0f, 0.0f,  0.0f };
	ALfloat back[]   = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
	ALfloat front[]  = { 0.0f, 0.0f,  1.0f, 0.0f, 1.0f, 0.0f };
	ALuint boom;
	ALsizei size;
	ALsizei bits;
	ALsizei freq;
	ALsizei format;
	ALboolean err;

	start = time(NULL);

	alListenerfv(AL_POSITION, zeroes );
	alListenerfv(AL_VELOCITY, zeroes );
	alListenerfv(AL_ORIENTATION, front );

	alGenBuffers( 1, &boom );

	err = alutLoadWAV(fname, &wave, &format, &size, &bits, &freq);
	if(err == AL_FALSE) {
		fprintf(stderr, "Could not include %s\n", fname);
		exit(1);
	}

	alBufferData( boom, format, wave, size, freq );
	free(wave); /* openal makes a local copy of wave data */

	alGenSources( 1, &moving_source);

	alSourcef(  moving_source, AL_GAIN_LINEAR_LOKI, 0.25 );
	alSourcei(  moving_source, AL_BUFFER, boom );
	alSourcei(  moving_source, AL_LOOPING, AL_TRUE);
	alSourcef(  moving_source, AL_PITCH, 1.00);

	return;
}
예제 #10
0
internal bool32
initialize_sound(sound_array *sounds)
{
    ALCdevice *device = g_audioDevice = alcOpenDevice(NULL);
    if (device)
    {
        g_audioContext = alcCreateContext(device, NULL);
        if (alcMakeContextCurrent(g_audioContext))
        {
            if (!start_new_log(AL_LOG_FILE))
            {
                fprintf(stderr, "Failed to create new log file: %s\n", AL_LOG_FILE);
            }

            alListenerfv(AL_POSITION, g_listenerPos);
            alListenerfv(AL_VELOCITY, g_listenerVel);
            alListenerfv(AL_ORIENTATION, g_listenerOri);
            if (al_print_if_error("Failed to initialize listener\n")) return false;

            alGenSources(sounds->size, sounds->sources);
            if (al_print_if_error("Failed to generate audio sources\n")) return false;
        }
        else
        {
            al_log(true, "OpenAL: failed to make audio context current\n");
            return false;
        }
    }
    else
    {
        al_log(true, "Failed to open device\n");
        // TODO: fix bug where alcOpenDevice occasionally fails
        return false;
    }
    return true;
}
예제 #11
0
void SoundListener::initListener()
{
	mOrientation[0]= mDirection.x; // Forward.x
	mOrientation[1]= mDirection.y; // Forward.y
	mOrientation[2]= mDirection.z; // Forward.z

	mOrientation[3]= mUp.x; // Up.x
	mOrientation[4]= mUp.y; // Up.y
	mOrientation[5]= mUp.z; // Up.z

	alListener3f(AL_POSITION, mPosition.x, mPosition.y, mPosition.z);
	alListenerfv(AL_ORIENTATION, mOrientation);
	alListenerf (AL_GAIN, 1.0f);
	alListener3f(AL_VELOCITY, 0.0f, 0.0f, 0.0f);
}
예제 #12
0
파일: Audio.cpp 프로젝트: bruni68510/Joyau
/*
  call-seq: setOrientation(atX, atY, at2, upX, upY, upZ) 

  Sets the audio listener's orientation.
*/
VALUE Listener_setOrientation(VALUE self, VALUE atX, VALUE atY, VALUE atZ,
                              VALUE upX, VALUE upY, VALUE upZ)
{
   float args[6];

   args[0] = NUM2DBL(atX);
   args[1] = NUM2DBL(atY);
   args[2] = NUM2DBL(atZ);
   args[3] = NUM2DBL(upX);
   args[4] = NUM2DBL(upY);
   args[5] = NUM2DBL(upZ);

   alListenerfv(AL_ORIENTATION, args);
   return Qnil;
}
예제 #13
0
void CAListener::SetAmp( float fAmp ) const
{
#ifdef A_USE_OAL_DUMMY
#else
	// Position.
	ALint iError;
	alGetError();
	alListenerfv( AL_GAIN, &fAmp );
	if( ( iError = alGetError() ) != AL_NO_ERROR )
	{
		A_ERR( "alListenerfv GAIN (%s)\n", GetALErrorString_( iError ) );
		return;
	}
#endif // A_USE_OAL_DUMMY
}
예제 #14
0
void Player::updateAudioListener()
{
	alListener3f( AL_POSITION, pos_.x, pos_.y, pos_.z );
	alListener3f( AL_VELOCITY, vel_.x, vel_.y, vel_.z );

	ALfloat orientation[] = {
		camera_.position().x + camera_.direction().x,
		camera_.position().y + camera_.direction().y,
		camera_.position().z + camera_.direction().z,
		camera_.up().x,
		camera_.up().y,
		camera_.up().z
	};

	alListenerfv( AL_ORIENTATION, orientation );
}
예제 #15
0
SoundPlayer::SoundPlayer() :
_device(0),
_context(0),
_nextMatchlock(SoundSourceMatchlockFirst),
_nextArrows(SoundSourceArrowsFirst),
_nextCookie(1)
{
	ALenum error;

	_device = alcOpenDevice(0); // select the "preferred device"
	if (_device)
	{
		_context = alcCreateContext(_device, 0);
	}

	alcMakeContextCurrent(_context);

	// Generate Buffers
	alGetError(); // clear error code
	alGenBuffers(NUMBER_OF_SOUND_BUFFERS, _buffers);
	if ((error = alGetError()) != AL_NO_ERROR)
	{
		//DisplayALError("alGenBuffers :", error);
		return;
	}

	alGenSources(NUMBER_OF_SOUND_SOURCES, _sources);
	if ((error = alGetError()) != AL_NO_ERROR)
	{
		return;
	}

	float orientation[6] =
			{
					0.0f, 0.0f, -1.0f, // direction
					0.0f, 1.0f, 0.0f //up
			};

	orientation[0] = 0; //sin(rads);
	orientation[1] = 0.0f;            // No Change to the Y vector
	orientation[2] = -1; //-cos(rads);

	alListenerfv(AL_ORIENTATION, orientation);

}
예제 #16
0
void AUD_OpenALDevice::setListenerOrientation(const AUD_Quaternion& orientation)
{
	ALfloat direction[6];
	direction[0] = -2 * (orientation.w() * orientation.y() +
						 orientation.x() * orientation.z());
	direction[1] = 2 * (orientation.x() * orientation.w() -
						orientation.z() * orientation.y());
	direction[2] = 2 * (orientation.x() * orientation.x() +
						orientation.y() * orientation.y()) - 1;
	direction[3] = 2 * (orientation.x() * orientation.y() -
						orientation.w() * orientation.z());
	direction[4] = 1 - 2 * (orientation.x() * orientation.x() +
							orientation.z() * orientation.z());
	direction[5] = 2 * (orientation.w() * orientation.x() +
						orientation.y() * orientation.z());
	alListenerfv(AL_ORIENTATION, direction);
	m_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());
     }
 }
예제 #18
0
void Context::setListenerRotation(const quat& newRotation)
{
    if (listenerRotation != newRotation)
    {
        listenerRotation = newRotation;

        const vec3 at = newRotation * vec3(0.f, 0.f, -1.f);
        const vec3 up = newRotation * vec3(0.f, 1.f, 0.f);

        const float orientation[] = { at.x, at.y, at.z, up.x, up.y, up.z };

        alListenerfv(AL_ORIENTATION, orientation);

#if WENDY_DEBUG
        checkAL("Failed to set listener rotation");
#endif
    }
}
예제 #19
0
static void init( const ALbyte *fname )
{
	ALfloat weirdpos[] = { 300.0f, 0.0f, 0.0f };
	ALfloat position[] = { 0.0f, 0.0f, 4.0f };
	ALuint boom;

	alListenerfv( AL_POSITION, weirdpos );

	boom = CreateBufferFromFile( fname );
	
	alGenSources( 1, &movingSource );

	alSourcei( movingSource, AL_BUFFER, boom );
	alSourcei( movingSource, AL_LOOPING, AL_TRUE );
	alSourcei( movingSource, AL_SOURCE_RELATIVE, AL_TRUE );
	alSourcefv( movingSource, AL_POSITION, position );
	alSourcef( movingSource, AL_PITCH, 1.00 );
}
예제 #20
0
AL_API void AL_APIENTRY alListeneriv(ALenum param, const ALint *values)
{
    ALCcontext *context;

    if(values)
    {
        ALfloat fvals[6];
        switch(param)
        {
        case AL_POSITION:
        case AL_VELOCITY:
            alListener3f(param, (ALfloat)values[0], (ALfloat)values[1], (ALfloat)values[2]);
            return;

        case AL_ORIENTATION:
            fvals[0] = (ALfloat)values[0];
            fvals[1] = (ALfloat)values[1];
            fvals[2] = (ALfloat)values[2];
            fvals[3] = (ALfloat)values[3];
            fvals[4] = (ALfloat)values[4];
            fvals[5] = (ALfloat)values[5];
            alListenerfv(param, fvals);
            return;
        }
    }

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

    WriteLock(&context->PropLock);
    if(!(values))
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    switch(param)
    {
    default:
        SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
    }
    if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire))
        UpdateListenerProps(context);

done:
    WriteUnlock(&context->PropLock);
    ALCcontext_DecRef(context);
}
예제 #21
0
AL_API void AL_APIENTRY alListeneriv( ALenum eParam, const ALint* plValues )
{
    ALCcontext *Context;
    ALfloat flValues[6];

    if(plValues)
    {
        switch(eParam)
        {
            case AL_POSITION:
            case AL_VELOCITY:
                alListener3f(eParam, (ALfloat)plValues[0], (ALfloat)plValues[1], (ALfloat)plValues[2]);
                return;

            case AL_ORIENTATION:
                flValues[0] = (ALfloat)plValues[0];
                flValues[1] = (ALfloat)plValues[1];
                flValues[2] = (ALfloat)plValues[2];
                flValues[3] = (ALfloat)plValues[3];
                flValues[4] = (ALfloat)plValues[4];
                flValues[5] = (ALfloat)plValues[5];
                alListenerfv(eParam, flValues);
                return;
        }
    }

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

    if(plValues)
    {
        switch(eParam)
        {
            default:
                alSetError(Context, AL_INVALID_ENUM);
                break;
        }
    }
    else
        alSetError(Context, AL_INVALID_VALUE);

    ALCcontext_DecRef(Context);
}
예제 #22
0
void SoundListener::updateListener()
{
	update();
	if(mParentNode)
	{
		mPosition = mLastParentPosition;
		mDirection = mLastParentOrientation.zAxis();
		mUp = mLastParentOrientation.yAxis();
	}
	alListener3f(AL_POSITION, mPosition.x, mPosition.y, mPosition.z);
	mOrientation[0]= -mDirection.x; // Forward.x
	mOrientation[1]= -mDirection.y; // Forward.y
	mOrientation[2]= -mDirection.z; // Forward.z

	mOrientation[3]= mUp.x; // Up.x
	mOrientation[4]= mUp.y; // Up.y
	mOrientation[5]= mUp.z; // Up.z
	alListenerfv(AL_ORIENTATION, mOrientation); 
}
예제 #23
0
AL_API void AL_APIENTRY alListeneriv(ALenum param, const ALint *values)
{
    ALCcontext *Context;

    if(values)
    {
        ALfloat fvals[6];
        switch(param)
        {
            case AL_POSITION:
            case AL_VELOCITY:
                alListener3f(param, (ALfloat)values[0], (ALfloat)values[1], (ALfloat)values[2]);
                return;

            case AL_ORIENTATION:
                fvals[0] = (ALfloat)values[0];
                fvals[1] = (ALfloat)values[1];
                fvals[2] = (ALfloat)values[2];
                fvals[3] = (ALfloat)values[3];
                fvals[4] = (ALfloat)values[4];
                fvals[5] = (ALfloat)values[5];
                alListenerfv(param, fvals);
                return;
        }
    }

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

    al_try
    {
        CHECK_VALUE(Context, values);
        switch(param)
        {
            default:
                al_throwerr(Context, AL_INVALID_ENUM);
        }
    }
    al_endtry;

    ALCcontext_DecRef(Context);
}
void System::HandleEvents(const frame_tp& timepoint) {
    auto transformfut = TransformMap::GetAsyncUpdatedTransforms().GetFuture(timepoint);
    if (transformfut.valid()) {
        // wait for the list to be published
        auto transformmap = transformfut.get();
        // assume this is the camera entity id
        if(transformmap->count(0)) {
            auto data = transformmap->at(0);
            const glm::vec3& position = data->GetTranslation();
            alListener3f(AL_POSITION, position.x, position.y, position.z);
            const glm::vec3& up = data->GetOrientation() * UP_VECTOR;
            const glm::vec3& at = data->GetOrientation() * FORWARD_VECTOR;
            ALfloat orientation[] = {at.x, at.y, at.z, up.x, up.y, up.z};
            alListenerfv(AL_ORIENTATION, orientation);
        }
    }
    else {
        std::cerr << "Sound system missed the updated transform map publication" << std::endl;
    }
}
        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()) ;
        }
예제 #26
0
	void lime_al_listenerfv (int param, value values) {
		
		if (val_is_null (values) == false) {
			
			int size = val_array_size (values);
			ALfloat *data = new ALfloat[size];
			
			for (int i = 0; i < size; ++i) {
				
				data[i] = (ALfloat)val_float( val_array_i (values, i) );
				
			}
			
			alListenerfv(param, data);
			
			delete[] data;
			
		}
		
	}
예제 #27
0
static void iterate( void ) {
	ALfloat orientation[]  = { 0.0f, 0.0f, -1.0f,
				   0.0f, 1.0f, 0.0f };
	static ALint angle = 0;

	/*
	 * rotate at vector about up vector by angle degrees.
	 */
	_alRotatePointAboutAxis(TORAD(angle), orientation, &orientation[3]);

	angle += 15; /* increment fifeteen degrees degree */

	fprintf(stderr, "orientation: \n\tAT(%f %f %f)\n\tUP(%f %f %f)\n",
		orientation[0], orientation[1], orientation[2],
		orientation[3], orientation[4], orientation[5]);

	alListenerfv(AL_ORIENTATION, orientation);

	micro_sleep(1500000);
}
예제 #28
0
void CAListener::SetOrient( const TVec &roOrient, const TVec &roUp ) const
{
#ifdef A_USE_OAL_DUMMY
#else
	ALint iError;
	alGetError();
	
	// http://www.gamedev.net/community/forums/topic.asp?topic_id=389321
	const ALfloat afOri[] = {
		roOrient[0], roOrient[1], roOrient[2],
		roUp[0], roUp[1], roUp[2]
	};
	alListenerfv( AL_ORIENTATION, afOri );
	if( ( iError = alGetError() ) != AL_NO_ERROR )
	{
		A_ERR( "alListenerfv ORIENTATION (%s)\n", GetALErrorString_( iError ) );
		return;
	}
#endif // A_USE_OAL_DUMMY
}
예제 #29
0
int is::Audio::init() {
    // Grab available devices and print them.
    int deviceCount;
    const char** deviceNames = alureGetDeviceNames( true, &deviceCount );
    if ( !deviceCount ) {
        os->printf( "ERR OpenAL failed to find any usable devices for audio playback!\n" );
        alureFreeDeviceNames( deviceNames );
        audio->checkErrorSimple();
        return 1;
    }
    os->printf( "INF OpenAL detected the following devices for audio:\n" );
    for ( int i=0; i<deviceCount; i++ ) {
        os->printf( "INF     %.\n", deviceNames[i] );
    }

    // Attempt to use any device starting from the first.
    int i = 0;
    while ( alureInitDevice( deviceNames[i], NULL ) == AL_FALSE && i < deviceCount ) {
        audio->checkErrorSimple();
        i++;
    }
    if ( i == deviceCount ) {
        os->printf( "ERR OpenAL failed to find any usable devices for audio playback!\n" );
        alureFreeDeviceNames( deviceNames );
        return 1;
    }
    os->printf( "INF OpenAL: Using %.\n", deviceNames[i] );
    alureFreeDeviceNames( deviceNames );

    // Initialize the listener
    alListener3f( AL_POSITION, 0.f, 0.f, 0.f );
    alListener3f( AL_VELOCITY, 0.f, 0.f, 0.f );
    float ori[6] = {
        0, 0, -1,
        0, 1, 0 };
    alListenerfv( AL_ORIENTATION, ori );
    audio->checkErrorSimple();

    lua->doFolder( "data/sounds" );
    return 0;
}
예제 #30
0
void CSound::UpdateListenerReal()
{
	// call from sound thread, cause OpenAL calls tend to cause L2 misses and so are slow (no reason to call them from mainthread)
	if (!listenerNeedsUpdate)
		return;

	// not 100% threadsafe, but worst case we would skip a single listener update (and it runs at multiple Hz!)
	listenerNeedsUpdate = false;

	const float3 myPosInMeters = myPos * ELMOS_TO_METERS;
	alListener3f(AL_POSITION, myPosInMeters.x, myPosInMeters.y, myPosInMeters.z);

	// reduce the rolloff when the camera is high above the ground (so we still hear something in tab mode or far zoom)
	// for altitudes up to and including 600 elmos, the rolloff is always clamped to 1
	const float camHeight = std::max(1.0f, myPos.y - CGround::GetHeightAboveWater(myPos.x, myPos.z));
	const float newMod = std::min(600.0f / camHeight, 1.0f);

	CSoundSource::SetHeightRolloffModifer(newMod);
	efx->SetHeightRolloffModifer(newMod);

	// Result were bad with listener related doppler effects.
	// The user experiences the camera/listener not as a world-interacting object.
	// So changing sounds on camera movements were irritating, esp. because zooming with the mouse wheel
	// often is faster than the speed of sound, causing very high frequencies.
	// Note: soundsource related doppler effects are not deactivated by this! Flying cannon shoots still change their frequencies.
	// Note2: by not updating the listener velocity soundsource related velocities are calculated wrong,
	// so even if the camera is moving with a cannon shoot the frequency gets changed.
	/*
	const float3 velocity = (myPos - prevPos) / (lastFrameTime);
	float3 velocityAvg = velocity * 0.6f + prevVelocity * 0.4f;
	prevVelocity = velocityAvg;
	velocityAvg *= ELMOS_TO_METERS;
	velocityAvg.y *= 0.001f; //! scale vertical axis separatly (zoom with mousewheel is faster than speed of sound!)
	velocityAvg *= 0.15f;
	alListener3f(AL_VELOCITY, velocityAvg.x, velocityAvg.y, velocityAvg.z);
	*/

	ALfloat ListenerOri[] = {camDir.x, camDir.y, camDir.z, camUp.x, camUp.y, camUp.z};
	alListenerfv(AL_ORIENTATION, ListenerOri);
	CheckError("CSound::UpdateListener");
}