Пример #1
0
HG_ERROR SoundManager::initialize()
{
    HG_ERROR err = HG_OK;
    
    BREAK_START;
    
    mDevice = alcOpenDevice(NULL);
    if (mDevice == NULL)
    {
        err = HG_ERROR_AL_DEVICE_NOT_SUPPORT;
        break;
    }
    
    mContext = alcCreateContext(mDevice, NULL);
    if (mContext == NULL)
    {
        err = HG_ERROR_AL_CONTEXT_FAILED;
        break;
    }
    
    alcMakeContextCurrent(mContext);
    
    alListenerf(AL_GAIN, 1.0f);
    
    // Doppler
    alDopplerFactor(1.0f);
    alDopplerVelocity(343.0f);
    
    BREAK_END;
    
    return err;
}
Пример #2
0
static int lua_alDopplerVelocity(lua_State* lua_state)
{
	ALfloat the_value;
	the_value = lua_tonumber(lua_state, 1);
	alDopplerVelocity(the_value);
	return 0;
}
Пример #3
0
ALuint Systems::SoundSystem::CreateSource()
{
	ALuint source;
	alGenSources((ALuint)1, &source);

	alDopplerFactor(1); // Numbers greater than 1 will increase Doppler effect, numbers lower than 1 will decrease the Doppler effect 
	alDopplerVelocity(350.f); // Defines the velocity of the sound

	return source;
}
Пример #4
0
Handle<Value> ALDopplerVelocityCallback(const Arguments& args) {
	//if less that nbr of formal parameters then do nothing
	if (args.Length() < 1)
		return v8::Undefined();
	
	//get arguments
	double arg0 = args[0]->NumberValue();

	//make call
	alDopplerVelocity((ALfloat)arg0);
	
	return v8::Undefined();
}
Пример #5
0
void ConfigurarEntorno ( ALsizei identificador, ALenum modelo,
                         ALfloat doppler_factor, ALfloat doppler_vel,
                         ALint room, ALint room_high_frequency,
                         ALfloat rolloff_factor, ALfloat decay_time,
                         ALfloat decay_high_frequency_ratio, ALint reflections,
                         ALfloat reflections_delay, ALint reverb,
                         ALfloat reverb_delay, ALfloat diffusion,
                         ALfloat density, ALfloat high_frequency_reference ){



	/* Configuramos la atenuacion y el efecto doppler */
	alEnable ( AL_DISTANCE_MODEL );
	alDistanceModel ( modelo );
	alDopplerFactor ( doppler_factor );
	alDopplerVelocity ( doppler_vel ); /* Recordad que en metros la velocidad del sonido es 343 */

#ifdef _LINUX
	/* Generamos el entorno y comprobamos errores */
	alGenEnvironmentIASIG ( identificador, &entornos[identificador] );
	if ( !alIsEnvironmentIASIG ( entornos[identificador] )){
		fprintf ( logs, "No se puede configurar parte del entorno\n");
	}

	/* Configuramos las propiedades del entorno */
	alEnvironmentiIASIG ( entornos[identificador], AL_ENV_ROOM_IASIG, room );
	alEnvironmentiIASIG ( entornos[identificador], AL_ENV_ROOM_HIGH_FREQUENCY_IASIG,
	                      room_high_frequency);

	alEnvironmentfIASIG ( entornos[identificador], AL_ENV_ROOM_ROLLOFF_FACTOR_IASIG, rolloff_factor );
	alEnvironmentfIASIG ( entornos[identificador], AL_ENV_DECAY_TIME_IASIG, decay_time );
	alEnvironmentfIASIG ( entornos[identificador], AL_ENV_DECAY_HIGH_FREQUENCY_RATIO_IASIG,
	                      decay_high_frequency_ratio );
	alEnvironmentiIASIG ( entornos[identificador], AL_ENV_REFLECTIONS_IASIG, reflections );
	alEnvironmentfIASIG ( entornos[identificador], AL_ENV_REFLECTIONS_DELAY_IASIG, reflections_delay );
	alEnvironmentiIASIG ( entornos[identificador], AL_ENV_REVERB_IASIG, reverb );
	alEnvironmentfIASIG ( entornos[identificador], AL_ENV_REVERB_DELAY_IASIG, reverb_delay );
	alEnvironmentfIASIG ( entornos[identificador], AL_ENV_DIFFUSION_IASIG, diffusion );
	alEnvironmentfIASIG ( entornos[identificador], AL_ENV_DENSITY_IASIG, density );
	alEnvironmentfIASIG ( entornos[identificador], AL_ENV_HIGH_FREQUENCY_REFERENCE_IASIG,
	                      high_frequency_reference );
#endif
#ifdef _WIN32
	/* Para windows se pueden crear y configurar entornos utilizando las extensiones EAX
	que admiten algunas tarjetas Soundblaster. Pero como no sé si es gratuito la utilizacion
	de dichas extensiones, de momento para windows no se generaran entornos
	*/
#endif
}
Пример #6
0
	OALAudioEngine::OALAudioEngine()
	{
		ALCdevice* device = alcOpenDevice(nullptr);
		ALCcontext* context = alcCreateContext(device, 0);

		alcMakeContextCurrent(context);

		this->SetListenerPos(float3(0, 0, 0));
		this->SetListenerVel(float3(0, 0, 0));
		this->SetListenerOri(float3(0, 0, 1), float3(0, 1, 0));

		alDistanceModel(AL_INVERSE_DISTANCE);

		alDopplerFactor(1);
		alDopplerVelocity(343); // m/s
	}
Пример #7
0
	void init()
	{
		s_al_device = alcOpenDevice(NULL);
		CE_ASSERT(s_al_device, "Cannot open OpenAL audio device");

		s_al_context = alcCreateContext(s_al_device, NULL);
		CE_ASSERT(s_al_context, "Cannot create OpenAL context");

		AL_CHECK(alcMakeContextCurrent(s_al_context));

		CE_LOGD("OpenAL Vendor   : %s", alGetString(AL_VENDOR));
		CE_LOGD("OpenAL Version  : %s", alGetString(AL_VERSION));
		CE_LOGD("OpenAL Renderer : %s", alGetString(AL_RENDERER));

		AL_CHECK(alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED));
		AL_CHECK(alDopplerFactor(1.0f));
		AL_CHECK(alDopplerVelocity(343.0f));
	}
Пример #8
0
static int Initialize(void *hnd)
{
  ALCdevice *dev;
  ALCcontext *ctxt;
  ALCint attrs[3];
  // TODO: Check for failures (generally, not just in this file).
  dev = alcOpenDevice(NULL);
  attrs[0] = ALC_FREQUENCY;
  attrs[1] = RLX.Audio.SR_to_Khz[RLX.Audio.SamplingRate];
  attrs[2] = 0;
  ctxt = alcCreateContext(dev, (ALCint *)&attrs);
  alcMakeContextCurrent(ctxt);
  alDistanceModel(AL_INVERSE_DISTANCE);
  alDopplerFactor(0.f); // No doppler
  alDopplerVelocity(0.f); // No velocity

  RLX.Audio.Config|=RLXAUDIO_Use3D;
  return 0;
}
Пример #9
0
ALvoid CDECL wine_alDopplerVelocity(ALfloat value)
{
    alDopplerVelocity(value);
}
Пример #10
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
}
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL10_nalDopplerVelocity(JNIEnv *__env, jclass clazz, jfloat dopplerVelocity, jlong __functionAddress) {
	alDopplerVelocityPROC alDopplerVelocity = (alDopplerVelocityPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	alDopplerVelocity(dopplerVelocity);
}
Пример #12
0
OpenalSoundInterface::OpenalSoundInterface(float sampling_rate, int n_channels): SoundInterface (sampling_rate, n_channels)
{
	car_src = NULL;

	ALfloat far_away[] = { 0.0f, 0.0f,  1000.0f };
	ALfloat zeroes[] = { 0.0f, 0.0f,  0.0f };
	ALfloat front[]  = { 0.0f, 0.0f,  1.0f, 0.0f, 1.0f, 0.0f };
	dev = alcOpenDevice( NULL );
	if( dev == NULL ) {
		throw ("Could not open device");
	}
	
	// Last zero is termination of the array, I think the current official beat SDK ignores that.
	// ALCint attr[] = { ALC_MONO_SOURCES, 1024, ALC_STEREO_SOURCES, 0, 0};
	cc = alcCreateContext( dev, NULL);
	if(cc == NULL) {
		alcCloseDevice( dev );
		throw ("Could not create context.");
	}

	alcMakeContextCurrent( cc );
	alcGetError(dev);
	alGetError();

	// Figure out the number of possible sources, watch out for an API update, perhaps
	// one can get that easier later with al(c)GetInteger (I'm sure that there is no way to
	// query this now) or even request a number with the context.
	const int MAX_SOURCES = 1024;
	int sources;
	ALuint sourcelist[MAX_SOURCES];
	for (sources = 0; sources < MAX_SOURCES; sources++) {
		alGenSources(1, &sourcelist[sources]);
		if (alGetError() != AL_NO_ERROR) {
			break;
		}
	}

	int clear;
	for (clear = 0; clear < sources; clear++) {
		if (alIsSource(sourcelist[clear])) {
			alDeleteSources(1, &sourcelist[clear]);
			if (alGetError() != AL_NO_ERROR) {
				printf("Error in probing OpenAL sources.\n");
			}
		} else {
			printf("Error in probing OpenAL sources.\n");
		}
	}

	OSI_MAX_SOURCES = sources;
	OSI_MAX_STATIC_SOURCES = MAX(0, OSI_MAX_SOURCES - OSI_MIN_DYNAMIC_SOURCES);

	// Figure out the number of buffers.
	int buffers;
	ALuint bufferlist[MAX_SOURCES];
	for (buffers = 0; buffers < MAX_SOURCES; buffers++) {
		alGenBuffers(1, &bufferlist[buffers]);
		if (alGetError() != AL_NO_ERROR) {
			break;
		}
	}

	for (clear = 0; clear < buffers; clear++) {
		if (alIsBuffer(bufferlist[clear])) {
			alDeleteBuffers(1, &bufferlist[clear]);
			if (alGetError() != AL_NO_ERROR) {
				printf("Error in probing OpenAL buffers.\n");
			}
		} else {
			printf("Error in probing OpenAL buffers.\n");
		}
	}

	OSI_MAX_BUFFERS = buffers;

	printf("OpenAL backend info:\n  Vendor: %s\n  Renderer: %s\n  Version: %s\n", alGetString(AL_VENDOR), alGetString(AL_RENDERER), alGetString(AL_VERSION));
	printf("  Available sources: %d%s\n", OSI_MAX_SOURCES, (sources >= MAX_SOURCES) ? " or more" : "");
	printf("  Available buffers: %d%s\n", OSI_MAX_BUFFERS, (buffers >= MAX_SOURCES) ? " or more" : "");
	
	alDistanceModel ( AL_INVERSE_DISTANCE );
	int error = alGetError();
	if (error != AL_NO_ERROR) {
		printf("OpenAL Error: %d alDistanceModel\n", error);
	}

	alDopplerFactor (1.0f);
	//alSpeedOfSound (SPEED_OF_SOUND); // not defined in linux yet.
	alDopplerVelocity (SPEED_OF_SOUND);
	error = alGetError();
	if (error != AL_NO_ERROR) {
		printf("OpenAL Error: %d alDopplerX\n", error);
	}


	alListenerfv(AL_POSITION, far_away );
	alListenerfv(AL_VELOCITY, zeroes );
	alListenerfv(AL_ORIENTATION, front );
	error = alGetError();
	if (error != AL_NO_ERROR) {
		printf("OpenAL Error: %d alListenerfv\n", error);
	}
	
	engpri = NULL;
	global_gain = 1.0f;
	
	// initialise mappings
	grass.schar = &CarSoundData::grass;
	grass_skid.schar = &CarSoundData::grass_skid;
	road.schar = &CarSoundData::road;
	metal_skid.schar = &CarSoundData::drag_collision;
	backfire_loop.schar = &CarSoundData::engine_backfire;
	turbo.schar = &CarSoundData::turbo;
	axle.schar = &CarSoundData::axle;

	n_static_sources_in_use = 0;
}
Пример #13
0
	void lime_al_doppler_velocity (float velocity) {
		
		alDopplerVelocity (velocity);
		
	}
Пример #14
0
OPAL_SOUND_MGR bool SoundManager::init( void )
{
	// It's an error to initialise twice OpenAl
	if ( isInitialised ) return true;

	// Open an audio device
	mSoundDevice = alcOpenDevice( NULL ); // TODO ((ALubyte*) "DirectSound3D");
	// mSoundDevice = alcOpenDevice( "DirectSound3D" );

	// Check for errors
	if ( !mSoundDevice )
	{
		printf( "SoundManager::init error : No sound device.\n");
		return false;
	}

	mSoundContext = alcCreateContext( mSoundDevice, NULL );
	//   if ( checkAlError() || !mSoundContext ) // TODO seems not to work! why ?
	if ( !mSoundContext )
	{
		printf( "SoundManager::init error : No sound context.\n");
		return false;
	}

	// Make the context current and active
	alcMakeContextCurrent( mSoundContext );
	if ( checkALError( "Init()" ) )
	{
		printf( "SoundManager::init error : could not make sound context current and active.\n");
		return false;
	}

	// Check for EAX 2.0 support and
	// Retrieves function entry addresses to API ARB extensions, in this case,
	// for the EAX extension. See Appendix 1 (Extensions) of
	// http://www.openal.org/openal_webstf/specs/OpenAL1-1Spec_html/al11spec7.html
	//
	// TODO EAX fct not used anywhere in the code ... !!!
	isEAXPresent = alIsExtensionPresent( "EAX2.0" );
	if ( isEAXPresent )
	{
		printf( "EAX 2.0 Extension available\n" );

#ifdef _USEEAX
		eaxSet = (EAXSet) alGetProcAddress( "EAXSet" );
		if ( eaxSet == NULL )
			isEAXPresent = false;

		eaxGet = (EAXGet) alGetProcAddress( "EAXGet" );
		if ( eaxGet == NULL )
			isEAXPresent = false;

		if ( !isEAXPresent )
			checkALError( "Failed to get the EAX extension functions adresses.\n" );
#else
		isEAXPresent = false;
		printf( "... but not used.\n" );
#endif // _USEEAX

	}

	// Test if Ogg Vorbis extension is present
	isOggExtensionPresent();

	// Create the Audio Buffers
	alGenBuffers( MAX_AUDIO_BUFFERS, mAudioBuffers );
	if (checkALError("init::alGenBuffers:") )
		return false;

	// Generate Sources
	alGenSources( MAX_AUDIO_SOURCES, mAudioSources );
	if (checkALError( "init::alGenSources :") )
		return false;


	// Setup the initial listener parameters
	// -> location
	alListenerfv( AL_POSITION, position );

	// -> velocity
	alListenerfv( AL_VELOCITY, velocity );

	// -> orientation
	alListenerfv( AL_ORIENTATION, orientation );

	// Gain
	alListenerf( AL_GAIN, 1.0 );

	// Initialise Doppler
	alDopplerFactor( 1.0 ); // 1.2 = exaggerate the pitch shift by 20%
	alDopplerVelocity( 343.0f ); // m/s this may need to be scaled at some point

	// Ok
	isInitialised = true;
	isSoundOn = true;

	printf( "SoundManager initialised.\n\n");

	return true;
}
Пример #15
0
// ---------------------------------------------------------------------------------------
// ds3d_update_buffer()
//
//	parameters:		channel	=> identifies the 3D sound to update
//						min		=>	the distance at which sound doesn't get any louder
//						max		=>	the distance at which sound doesn't attenuate any further
//						pos		=> world position of sound
//						vel		=> velocity of the objects producing the sound
//
//	returns:		0		=>		success
//					-1		=>		failure
//
//
int ds3d_update_buffer(int channel, float min, float max, vec3d* pos, vec3d* vel)
{
	if (DS3D_inited == FALSE)
		return 0;

	if (channel == -1)
		return 0;

#ifdef USE_OPENAL
	// as used by DS3D
	//	OpenAL_ErrorPrint( alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED) );

	// set the min distance
	OpenAL_ErrorPrint( alSourcef(Channels[channel].source_id, AL_REFERENCE_DISTANCE, min) );

	// set the max distance
	//	OpenAL_ErrorPrint( alSourcef(Channels[channel].source_id, AL_MAX_DISTANCE, max) );
	OpenAL_ErrorPrint( alSourcef(Channels[channel].source_id, AL_MAX_DISTANCE, 40000.0f) );

	// set rolloff factor
	OpenAL_ErrorPrint( alSourcef(Channels[channel].source_id, AL_ROLLOFF_FACTOR, 1.0f) );

	// set doppler
	OpenAL_ErrorPrint( alDopplerVelocity(10000.0f) );
	OpenAL_ErrorPrint( alDopplerFactor(0.0f) );  // TODO: figure out why using a value of 1 sounds bad

	// set the buffer position
	if ( pos != NULL ) {
		ALfloat alpos[] = { pos->xyz.x, pos->xyz.y, pos->xyz.z };
		OpenAL_ErrorPrint( alSourcefv(Channels[channel].source_id, AL_POSITION, alpos) );
	}

	// set the buffer velocity
	if ( vel != NULL ) {
		ALfloat alvel[] = { vel->xyz.x, vel->xyz.y, vel->xyz.z };
		OpenAL_ErrorPrint( alSourcefv(Channels[channel].source_id, AL_VELOCITY, alvel) );
	} else {
		ALfloat alvel[] = { 0.0f, 0.0f, 0.0f };
		OpenAL_ErrorPrint( alSourcefv(Channels[channel].source_id, AL_VELOCITY, alvel) );
	}

#else

	HRESULT hr;
	LPDIRECTSOUND3DBUFFER pds3db;
	float max_dist, min_dist;

	pds3db = Channels[channel].pds3db;
	Assert(pds3db != NULL);

	// set the buffer position
	if (pos != NULL)
	{
		hr = pds3db->SetPosition(pos->xyz.x, pos->xyz.y, pos->xyz.z, DS3D_DEFERRED);
	}

	// set the buffer veclocity
	if (vel != NULL)
	{
		hr = pds3db->SetVelocity(vel->xyz.x, vel->xyz.y, vel->xyz.z, DS3D_DEFERRED);
	}
	else
	{
		hr = pds3db->SetVelocity(0.0f, 0.0f, 0.0f, DS3D_DEFERRED);
	}

	// set the min distance
	hr = pds3db->GetMinDistance(&min_dist);
	hr = pds3db->SetMinDistance(min, DS3D_DEFERRED);
	// set the max distance
	hr = pds3db->GetMaxDistance(&max_dist);
	//	hr = pds3db->SetMaxDistance( max, DS3D_DEFERRED );
	hr = pds3db->SetMaxDistance(100000.0f, DS3D_DEFERRED);
#endif

	return 0;
}
Пример #16
0
void al_dopplervelocity( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) {

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

}
Пример #17
0
value lime_al_doppler_velocity (value velocity) {

    alDopplerVelocity (val_float (velocity));
    return alloc_null ();

}
Пример #18
0
//*****************************************************************************
// alDopplerVelocity
//*****************************************************************************
//
ALAPI ALvoid ALAPIENTRY alDopplerVelocity(ALfloat value)
{
    AL_VOID_FXN(alDopplerVelocity(value));
}