Esempio n. 1
0
void AUD_OpenALDevice::setSpeedOfSound(float speed)
{
	alSpeedOfSound(speed);
}
Esempio n. 2
0
bool COpenALGameSystem::Init()
{
	ALint ALhints[4];
	float gain = 0.0f;

	ALhints[0] = ALC_MAX_AUXILIARY_SENDS;
	ALhints[1] = requestedNumberOfAuxiliarySends;

	m_alDevice = alcOpenDevice(NULL);

	if (m_alDevice == NULL)
	{
		Warning("OpenAL: Device couldn't be properly opened. Initialization failed.\n");
		return false;
	}

	/**
	 * Check for effects extensions that we can use to provide digital signal processing
	 */
	if (alcIsExtensionPresent(m_alDevice, "ALC_EXT_EFX") == AL_FALSE)
	{
		m_bEffectsAvailable = false;
	}
	else
	{
		m_bEffectsAvailable = true;
		m_effectsType = OPENAL_EFFECTS_EFX;
	}

	m_alContext = alcCreateContext(m_alDevice, NULL);

	if (alGetError() != AL_NO_ERROR)
	{
		Warning("OpenAL: Couldn't create an OpenAL context. Initialization failed.\n");
		return false;
	}

	alcMakeContextCurrent(m_alContext);
	if (alGetError() != AL_NO_ERROR)
	{
		Warning("OpenAL: Couldn't make the OpenAL context current.\n");
		return false;
	}

	// Figure out how many auxiliary sends we've got access to
	if (m_bEffectsAvailable)
		alcGetIntegerv(m_alDevice, ALC_MAX_AUXILIARY_SENDS, 1, &m_iAuxiliarySendCount);

	// Initialize this to zero in order to prevent loud audio before we get the volume ConVar(s).
	alListenerfv(AL_GAIN, &gain);
	if (alGetError() != AL_NO_ERROR)
	{
		Warning("OpenAL: Couldn't change gain? This could get loud... Continuing without regard.\n");
	}

	// Set up the speed of sound. If this doesn't work right, you have old drivers.
	alSpeedOfSound(valveSpeedOfSound);
	if (alGetError() != AL_NO_ERROR)
	{
		Warning("OpenAL: You need to update your audio drivers or OpenAL for sound to work properly.\n");
		return false;
	}

	m_bInitialized = true;

	Update(-1);

	if (!g_OpenALUpdateThread.IsAlive())
		g_OpenALUpdateThread.Start();

	DevMsg("OpenAL: Init finished");

	if (m_bEffectsAvailable)
	{
		DevMsg(" with %d auxiliary sends per source.", m_iAuxiliarySendCount);
		alListenerf(AL_METERS_PER_UNIT, VALVEUNITS_TO_METERS(1));
	}

	DevMsg(".\nAL Renderer: %s\nAL Vendor: %s\nAL Version: %s\n", alGetString(AL_RENDERER), alGetString(AL_VENDOR), alGetString(AL_VERSION));

	return true;
}
Esempio n. 3
0
	void	COALDevice::SetSpeedOfSound(const float32 fUnitsPerSecond) {
		alSpeedOfSound(fUnitsPerSecond);
	}
Esempio n. 4
0
void WSoundComponent::SetSoundSpeed(float fSpeed) {
	alSpeedOfSound(fSpeed);
}
Esempio n. 5
0
 void cAudioManager::setSpeedOfSound(float speed)
 {
     alSpeedOfSound(speed);
     checkALError();
 }
Esempio n. 6
0
UBOOL UOpenALAudioSubsystem::Init()
{
	guard(UOpenALAudioSubsystem::Init);

	INT Rate = GetActualOutputRate();


	// OpenAL / ALURE initialization
	ALCint ContextAttrs[] = { ALC_FREQUENCY, Rate, 0 };
	if( alureInitDevice( NULL, ContextAttrs ) == AL_FALSE )
		appErrorf( TEXT("Couldn't initialize OpenAL: %s"), alureGetErrorString() );

	alDistanceModel( AL_LINEAR_DISTANCE_CLAMPED );
	CheckALErrorFlag( TEXT("alDistanceModel") );

	alDopplerFactor( DopplerFactor );
	CheckALErrorFlag( TEXT("alDopplerFactor") );

	// Metre per second to units per second, where units per meter is 52.5.
	// Taken from: http://wiki.beyondunreal.com/Legacy:General_Scale_And_Dimensions
	alSpeedOfSound( 343.3f * 52.5f );
	CheckALErrorFlag( TEXT("alSpeedOfSound") );

	ALuint* NewSources = new ALuint[NumSources + 1];
	Sources = new FAudioSource[NumSources];
	alGenSources( NumSources + 1, NewSources );
	CheckALErrorFlag( TEXT("alGenSources") );
	MusicSource = NewSources[0];
	for( INT i=0; i<NumSources; i++ )
		Sources[i].Id = NewSources[i+1];
	delete[] NewSources;

	// Fix the music source to 0 values
	alSource3f(	MusicSource, AL_POSITION,			0.f, 0.f, 0.f );
	alSource3f(	MusicSource, AL_VELOCITY,			0.f, 0.f, 0.f );
	alSource3f(	MusicSource, AL_DIRECTION,			0.f, 0.f, 0.f );
	alSourcef(	MusicSource, AL_ROLLOFF_FACTOR,		0.f );
	alSourcei(	MusicSource, AL_SOURCE_RELATIVE,	AL_TRUE );

	SetVolumes();
	CheckALErrorFlag( TEXT("SetVolumes") );


	// MikMod initialization
	//kipz - remove this because it breaks on new mikmod
	//MikMod_RegisterDriver( &MusicDriver );
	MikMod_RegisterAllDrivers();
	// Register only formats that are known to be supported by UT.
	// Taken from: http://wiki.beyondunreal.com/Music
	MikMod_RegisterLoader( &load_mod );
	MikMod_RegisterLoader( &load_s3m );
	MikMod_RegisterLoader( &load_stm );
	MikMod_RegisterLoader( &load_it  );
	MikMod_RegisterLoader( &load_xm  );
	MikMod_RegisterLoader( &load_far );
	MikMod_RegisterLoader( &load_669 );

	md_mixfreq = Rate;
	if ( HighQualityMusic )
		md_mode |= DMODE_HQMIXER;
	if( MikMod_Init( "" ) )
		appErrorf( TEXT("Couldn't initialize MikMod: %s"), MikMod_strerror( MikMod_errno ) );


	// Initialized!
	USound::Audio = this;
	UMusic::Audio = this;
	Initialized = 1;

	return 1;
	unguard;
}
Esempio n. 7
0
void Engine_InitAL()
{
#if !NO_AUDIO

    ALCint paramList[] = {
        ALC_STEREO_SOURCES,  TR_AUDIO_STREAM_NUMSOURCES,
        ALC_MONO_SOURCES,   (TR_AUDIO_MAX_CHANNELS - TR_AUDIO_STREAM_NUMSOURCES),
        ALC_FREQUENCY,       44100, 0
    };


    Sys_DebugLog(LOG_FILENAME, "Probing OpenAL devices...");

    const char *devlist = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);

    if (!devlist)
    {
        Sys_DebugLog(LOG_FILENAME, "InitAL: No AL audio devices!");
        return;
    }

    while(*devlist)
    {
        Sys_DebugLog(LOG_FILENAME, " Device: %s", devlist);
        ALCdevice* dev = alcOpenDevice(devlist);

        if(audio_settings.use_effects)
        {
            if( alcIsExtensionPresent(dev, ALC_EXT_EFX_NAME) == ALC_TRUE )
            {
                Sys_DebugLog(LOG_FILENAME, " EFX supported!");
                al_device = dev;
                break;
            }
            else
            {
                alcCloseDevice(dev);
                devlist += std::strlen(devlist)+1;
            }
        }
        else
        {
            al_device = dev;
            break;
        }
    }

    al_context = alcCreateContext(al_device, paramList);

    if(!al_context)
    {
        Sys_DebugLog(LOG_FILENAME, " Failed to create OpenAL context.");
        alcCloseDevice(al_device);
        al_device = nullptr;
        return;
    }

    alcMakeContextCurrent(al_context);

    Audio_LoadALExtFunctions(al_device);

    std::string driver = "OpenAL library: ";
    driver += alcGetString(al_device, ALC_DEVICE_SPECIFIER);
    ConsoleInfo::instance().addLine(driver, FONTSTYLE_CONSOLE_INFO);

    alSpeedOfSound(330.0 * 512.0);
    alDopplerVelocity(330.0 * 510.0);
    alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
#endif
}
Esempio n. 8
0
void al_speedofsound( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) {

	if (NULL == alSpeedOfSound) mogl_glunsupported("alSpeedOfSound");
	alSpeedOfSound((ALfloat)mxGetScalar(prhs[0]));

}
	void audio_context::speed_of_sound(const float meters_per_sec) {
		AL_CHECK(alSpeedOfSound(meters_per_sec));
	}
Esempio n. 10
0
/**
 * @brief Creates a sound environment.
 */
int sound_al_env( SoundEnv_t env, double param )
{
   int i;
   ALuint s;
   ALfloat f;

   soundLock();
   switch (env) {
      case SOUND_ENV_NORMAL:
         /* Set global parameters. */
         alSpeedOfSound( 3433. );

         if (al_info.efx == AL_TRUE) {
            /* Disconnect the effect. */
            nalAuxiliaryEffectSloti( efx_directSlot,
                  AL_EFFECTSLOT_EFFECT, AL_EFFECT_NULL );

            /* Set per-source parameters. */
            for (i=0; i<source_ntotal; i++) {
               s = source_total[i];
               alSourcef( s, AL_AIR_ABSORPTION_FACTOR, 0. );
            }
         }
         break;

      case SOUND_ENV_NEBULA:
         f = param / 1000.;

         /* Set global parameters. */
         alSpeedOfSound( 3433./(1. + f*2.) );

         if (al_info.efx == AL_TRUE) {

            if (al_info.efx_reverb == AL_TRUE) {
               /* Tweak the reverb. */
               nalEffectf( efx_reverb, AL_REVERB_DECAY_TIME,    10. );
               nalEffectf( efx_reverb, AL_REVERB_DECAY_HFRATIO, 0.5 );

               /* Connect the effect. */
               nalAuxiliaryEffectSloti( efx_directSlot,
                     AL_EFFECTSLOT_EFFECT, efx_reverb );
            }

            /* Set per-source parameters. */
            for (i=0; i<source_ntotal; i++) {
               s = source_total[i];
               /* Value is from 0. (normal) to 10..
                * It represents the attenuation per meter. In this case it decreases by
                * 0.05*AB_FACTOR dB/meter where AB_FACTOR is the air absoprtion factor.
                * In our case each pixel represents 5 meters.
                */
               alSourcef( s, AL_AIR_ABSORPTION_FACTOR, 3.*f );
            }
         }
         break;
   }

   /* Check for errors. */
   al_checkErr();

   soundUnlock();

   return 0;
}
Esempio n. 11
0
	void lime_al_speed_of_sound (float speed) {
		
		alSpeedOfSound (speed);
		
	}
Esempio n. 12
0
void OpenALDevice::setSpeedOfSound(float speed)
{
	std::lock_guard<std::recursive_mutex> lock(m_mutex);

	alSpeedOfSound(speed);
}
void COpenALSoundUtility::Init()
{
	// hook into LUA
	m_LuaState = NULL;

	static DWORD msgHash_GetMasterScriptState = CHashString(_T("GetMasterScriptState")).GetUniqueID();
	if(m_ToolBox->SendMessage(msgHash_GetMasterScriptState, sizeof(lua_State *), &m_LuaState) == MSG_HANDLED)
	{
		// register our additional structures/handlers with LUA master
		tolua_OpenALLua_open(m_LuaState);
	}
	else
	{
		StdString error;
		error = _T("Error missing Master Script State Data\n");

		// log error
		EngineGetToolBox()->SetErrorValue(WARN_INVALID_OPERATION);
		EngineGetToolBox()->Log(LOGWARNING, error);
    }

	// this needs to be a message and stripped out of here....
#ifdef _WIN32
	// create invisible dummy sound window for DirectSound
	m_hWndSound = CreateWindowEx(0, "STATIC", "OpenALSoundWindow", 
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		HWND_MESSAGE,
		(HMENU)NULL,
		NULL,
		NULL);

	if (m_hWndSound == NULL)
	{
		m_ToolBox->Log(LOGWARNING, _T("Unable to create sound window\n"));
	}
	else
	{
		SetForegroundWindow(m_hWndSound);
	}
#endif

	// Tell sound system to Start Up (default sound settings, so null is passed)
	ALboolean initResult = alutInit(NULL, NULL);

	if ( initResult == AL_FALSE )
	{
		// error initalizing OpenAL
		m_ToolBox->SetErrorValue(ERR_NULL_POINTER);
		m_ToolBox->Log(LOGWARNING, _T("Sound manager: error initalizing sound: %s\n"), alutGetErrorString(alutGetError()));
		return;
	}

	ALenum err;

	m_bInitialized = true;

	m_iMaxNumSources = MAX_SOURCES;
	bool bSourcesGenerated = false;

	do
	{
		m_SoundSources = new ALuint[m_iMaxNumSources];		
		
		alGenSources(m_iMaxNumSources, m_SoundSources);
		err = alGetError();
		if (err != AL_NO_ERROR)
		{
			delete [] m_SoundSources;
			m_SoundSources = NULL;

			// try decrementing the max number
			m_iMaxNumSources -= 4;
			if (m_iMaxNumSources <= 0)
			{
				m_ToolBox->SetErrorValue(ERR_NULL_POINTER);
				m_ToolBox->Log( LOGERROR, _T("Sound manager error: can't generate audio sources: %s\n"), GetALErrorString(err));						
				break;
			}
		}
		else
		{
			bSourcesGenerated = true;
		}
	}while (!bSourcesGenerated);

	// load up free sources
	if (m_SoundSources != NULL)
	{
		for (UINT i=0; i<m_iMaxNumSources; i++)
		{
			m_FreeSources.push_back(m_SoundSources[i]);
		}
	}

	// ensure default position for listener
	ALfloat position[3] = { (ALfloat)0.0f,
							(ALfloat)0.0f,
							(ALfloat)0.0f };

	ALfloat ori[] = { -1.0, 0.0, 0.0,  0.0, 0.0, 1.0 };

	alListenerfv(AL_POSITION, position);
	alListenerfv(AL_ORIENTATION, ori);

	// set distance model for 3d sounds
	alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);

	// check if init of listener and distance model threw errors
	err = alGetError();
	if (err != AL_NO_ERROR) 
	{
		m_ToolBox->SetErrorValue(ERR_NULL_POINTER);
		m_ToolBox->Log( LOGWARNING, _T("Sound manager: OpenAL problem setting up OpenAL distance model: %s\n"), GetALErrorString(err));
		return;
	}

	alSpeedOfSound(343.3f * m_fSoundScale);
	err = alGetError();
	if (err != AL_NO_ERROR) 
	{
		m_ToolBox->SetErrorValue(ERR_NULL_POINTER);
		m_ToolBox->Log( LOGWARNING, _T("Sound manager: OpenAL problem setting up OpenAL speed of sound: %s\n"), GetALErrorString(err));
		return;
	}

	alDopplerFactor(m_fGlobalDopplerFactor * m_fSoundScale);
	err = alGetError();
	if (err != AL_NO_ERROR) 
	{
		m_ToolBox->SetErrorValue(ERR_NULL_POINTER);
		m_ToolBox->Log( LOGWARNING, _T("Sound manager: OpenAL problem setting up OpenAL doppler factor: %s\n"), GetALErrorString(err));
		return;
	}	
}
Esempio n. 14
0
ALvoid CDECL wine_alSpeedOfSound(ALfloat value)
{
    alSpeedOfSound(value);
}
Esempio n. 15
0
SoundContext::SoundContext(const Misc::ConfigurationFileSection& configFileSection,VruiState* sVruiState)
	:vruiState(sVruiState),
	 #if ALSUPPORT_CONFIG_HAVE_OPENAL
	 alDevice(0),alContext(0),
	 #endif
	 contextData(0),
	 listener(findListener(configFileSection.retrieveString("./listenerName").c_str())),
	 speedOfSound(float(getMeterFactor())*343.0f),
	 dopplerFactor(1.0f),
	 distanceAttenuationModel(CONSTANT)
	{
	/* Set sound context parameters from configuration file: */
	speedOfSound=configFileSection.retrieveValue<float>("./speedOfSound",speedOfSound);
	dopplerFactor=configFileSection.retrieveValue<float>("./dopplerFactor",dopplerFactor);
	distanceAttenuationModel=configFileSection.retrieveValue<DistanceAttenuationModel>("./distanceAttenuationModel",distanceAttenuationModel);
	
	#if ALSUPPORT_CONFIG_HAVE_OPENAL
	/* Open the OpenAL device: */
	std::string alDeviceName=configFileSection.retrieveValue<std::string>("./deviceName","Default");
	alDevice=alcOpenDevice(alDeviceName!="Default"?alDeviceName.c_str():0);
	if(alDevice==0)
		Misc::throwStdErr("SoundContext::SoundContext: Could not open OpenAL sound device \"%s\"",alDeviceName.c_str());
	
	/* Create a list of context attributes: */
	ALCint alContextAttributes[9];
	ALCint* attPtr=alContextAttributes;
	if(configFileSection.hasTag("./mixerFrequency"))
		{
		*(attPtr++)=ALC_FREQUENCY;
		*(attPtr++)=configFileSection.retrieveValue<ALCint>("./mixerFrequency");
		}
	if(configFileSection.hasTag("./refreshFrequency"))
		{
		*(attPtr++)=ALC_REFRESH;
		*(attPtr++)=configFileSection.retrieveValue<ALCint>("./refreshFrequency");
		}
	if(configFileSection.hasTag("./numMonoSources"))
		{
		*(attPtr++)=ALC_MONO_SOURCES;
		*(attPtr++)=configFileSection.retrieveValue<ALCint>("./numMonoSources");
		}
	if(configFileSection.hasTag("./numStereoSources"))
		{
		*(attPtr++)=ALC_STEREO_SOURCES;
		*(attPtr++)=configFileSection.retrieveValue<ALCint>("./numStereoSources");
		}
	*(attPtr++)=ALC_INVALID;
	
	/* Create an OpenAL context: */
	alContext=alcCreateContext(alDevice,alContextAttributes);
	if(alContext==0)
		{
		alcCloseDevice(alDevice);
		Misc::throwStdErr("SoundContext::SoundContext: Could not create OpenAL context for sound device %s",alDeviceName.c_str());
		}
	#endif
	
	/* Create an AL context data object: */
	contextData=new ALContextData(101);
	
	/* Initialize the sound context's OpenAL context: */
	makeCurrent();
	
	#if ALSUPPORT_CONFIG_HAVE_OPENAL
	/* Set global OpenAL parameters: */
	alSpeedOfSound(speedOfSound);
	alDopplerFactor(dopplerFactor);
	switch(distanceAttenuationModel)
		{
		case CONSTANT:
			alDistanceModel(AL_NONE);
			break;
		
		case INVERSE:
			alDistanceModel(AL_INVERSE_DISTANCE);
			break;
		
		case INVERSE_CLAMPED:
			alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
			break;
		
		case LINEAR:
			alDistanceModel(AL_LINEAR_DISTANCE);
			break;
		
		case LINEAR_CLAMPED:
			alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
			break;
		
		case EXPONENTIAL:
			alDistanceModel(AL_EXPONENT_DISTANCE);
			break;
		
		case EXPONENTIAL_CLAMPED:
			alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
			break;
		}
	#endif
	}
Esempio n. 16
0
	//The default speed of sound value is 343.3.
	void	cSoundParser::SetSpeed(float e_fSpeed)
	{
		alSpeedOfSound(343.3f*e_fSpeed);  
	}
bool EOSAudioDevice::initialize()
{
	ALCcontext *pContext = 0;
	ALCdevice *pDevice = 0;

	// load config
	_device = "auto";
	_bufferSize = BUFFER_SIZE;
	_sourcesLimit = SOURCES_LIMIT;
	_distanceFactor = 1;
	_dopplerFactor = 1;
	_speedOfSound = 343.3f;
	_rolloffFactor = 0.001f;
	_maxDistance = 4000;
	_referenceDistance = 3000;
	_masterVolume = 1;

	// clean error status
	alGetError();

	// initialize OpenAL
    pDevice = alcOpenDevice(NULL);      // select the "default device"
    if(pDevice)
    {
        pContext = alcCreateContext(pDevice, NULL);
        alcMakeContextCurrent(pContext);
    }

    const ALchar *strVendor = alGetString(AL_VENDOR),
                 *strVersion = alGetString(AL_VERSION),
                 *strRenderer = alGetString(AL_RENDERER),
                 *strAlExtensions = alGetString(AL_EXTENSIONS);

    LOGINFO("OpenAL v%s by %s", strVersion, strVendor);
    LOGINFO("  Renderer: %s", strRenderer);
    LOGINFO("  Extensions: %s", strAlExtensions);

    const ALCchar *strDefSpecifier = alcGetString(pDevice, ALC_DEFAULT_DEVICE_SPECIFIER),
                  *strCaptDefSpecifier = alcGetString(pDevice, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER),
                  *strAlcExtensions = alcGetString(pDevice, ALC_EXTENSIONS);

    LOGINFO("  Default device: %s", strDefSpecifier);
    LOGINFO("  Default capture device: %s", strCaptDefSpecifier);
    LOGINFO("  Device extensions: %s", strAlcExtensions);

    // query extensions
    _extLinearDistanceClamped = alIsExtensionPresent("AL_LINEAR_DISTANCE_CLAMPED");
    LOGINFO("  Extension [AL_LINEAR_DISTANCE_CLAMPED]: is %s", (_extLinearDistanceClamped)?"available.":"not available.");

	// allocate sources
	allocateSources();
	LOGINFO("  OpenAL: %i audio sources available", sourcesHandle.size());
	checkErrors("initialize[sources allocation]");

	// distance factor
	if(_extLinearDistanceClamped)
        alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
    else
        alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);

	setDistanceFactor(_distanceFactor);
	checkErrors("initialize[distance factor]");

	// doppler factor
    alDopplerFactor(_dopplerFactor);		// don't exaggerate doppler shift
    alSpeedOfSound(_speedOfSound);	        // using meters/second

	// init listner
	listenerSetPosition(0, 0, 0);
	listenerSetOrientation(0, 0, 1, 0, 1, 0);
	listenerSetGain(_masterVolume);
	checkErrors("initialize[listener]");

    // init libdumb
    dumb_register_stdfiles();

	// check for errors in this function
	return checkErrors("initialize");
}
Esempio n. 18
0
value lime_al_speed_of_sound (value speed) {

    alSpeedOfSound (val_float (speed));
    return alloc_null ();

}
Esempio n. 19
0
void NzAudio::SetSpeedOfSound(float speed)
{
	alSpeedOfSound(speed);
}