コード例 #1
0
ファイル: snd_ds6.cpp プロジェクト: cbxbiker61/nogravity
static void RLXAPI UserSetParms(V3XMATRIX *lpMAT, V3XVECTOR *lpVEL,
								float*lpDistanceF, float*lpDopplerF, float*lpRolloffF)
{
	HRESULT  hr;
    if (!g_lpDS3DListener)
		return;
    if (lpMAT)
    {
        V3XVECTOR *ps = &lpMAT->v.Pos;
        hr = g_lpDS3DListener->SetPosition(ps->x, ps->y, ps->z, DS3D_DEFMODE);

		g_lpDS3DListener->SetOrientation(
        lpMAT->v.K.x, lpMAT->v.K.y, lpMAT->v.K.z, // 3D engine use a other orientation (right hand)
         lpMAT->v.J.x, lpMAT->v.J.y, lpMAT->v.J.z,
        DS3D_DEFMODE);

    }
    if (lpVEL)
		g_lpDS3DListener->SetVelocity(lpVEL->x, lpVEL->y, lpVEL->z, DS3D_DEFMODE);
    if (lpDistanceF)
		g_lpDS3DListener->SetDistanceFactor(*lpDistanceF, DS3D_DEFMODE);
    if (lpDopplerF)
		g_lpDS3DListener->SetDopplerFactor( *lpDopplerF, DS3D_DEFMODE);
    if (lpRolloffF)
		g_lpDS3DListener->SetRolloffFactor( *lpRolloffF, DS3D_DEFMODE);
}
コード例 #2
0
ファイル: DirectSound.cpp プロジェクト: doveiya/isilme
//-----------------------------------------------------------------------------
//	Установка всех параметров слушателя
// на входе    :  listener - указатель на интерфейс слушателя
//  			  data     - указатель на структуру в которой содержатся
//  						 параметры слушателя
// на выходе   :	успешность установки параметров слушателя
//-----------------------------------------------------------------------------
int ds_SetAllListenerParameters(LPDIRECTSOUND3DLISTENER listener,
	LPDS3DLISTENER data, DWORD def)
{
	int ret = false;

	// проверка наличия слушателя
	if (!listener)
		return ret;

	// установка позиции
	ret = (listener->SetPosition(data->vPosition.x,
					 	data->vPosition.y,
					 	data->vPosition.z,
					 	def) == DS_OK) ?
		true :
		false;

	// установка скорости слушателя
	if (ret)
		ret = (listener->SetVelocity(data->vVelocity.x,
						 	data->vVelocity.y,
						 	data->vVelocity.z,
						 	def) == DS_OK) ?
			true :
			false;

	// установка ориентации
	if (ret)
		ret = (listener->SetOrientation(data->vOrientFront.x,
						 	data->vOrientFront.y,
						 	data->vOrientFront.z,
						 	data->vOrientTop.x,
						 	data->vOrientTop.y,
						 	data->vOrientTop.z,
						 	def) == DS_OK) ?
			true :
			false;

	// установка дистанции
	if (ret)
		ret = (listener->SetDistanceFactor(data->flDistanceFactor, def) ==
			DS_OK) ?
			true :
			false;

	// установка фактора удаления
	if (ret)
		ret = (listener->SetRolloffFactor(data->flRolloffFactor, def) == DS_OK) ?
			true :
			false;

	// установка эффекта допплера
	if (ret)
		ret = (listener->SetDopplerFactor(data->flDopplerFactor, def) == DS_OK) ?
			true :
			false;

	return ret;
}
コード例 #3
0
ファイル: ds3d.cpp プロジェクト: lubomyr/freespace2
// ---------------------------------------------------------------------------------------
// ds3d_update_listener()
//
//	returns:		0		=>		success
//					-1		=>		failure
//
int ds3d_update_listener(vector *pos, vector *vel, matrix *orient)
{
	HRESULT			hr;

	if (DS3D_inited == FALSE)
		return 0;

	if ( pDS3D_listener == NULL )
		return -1;
	
	// set the listener position
	if ( pos != NULL ) {
		hr = pDS3D_listener->SetPosition(pos->x, pos->y, pos->z, DS3D_DEFERRED); 
	}

	// set the listener veclocity
	if ( vel != NULL ) {
		hr = pDS3D_listener->SetVelocity(vel->x, vel->y, vel->z, DS3D_DEFERRED); 
	}

	if ( orient != NULL ) {
		hr = pDS3D_listener->SetOrientation(	orient->fvec.x, orient->fvec.y, orient->fvec.z,
															orient->uvec.x, orient->uvec.y, orient->uvec.z,
															DS3D_DEFERRED );
	}

	float rolloff_factor = 1.0f;
	if (ds_using_a3d() == true) {
		rolloff_factor = 3.0f;		// A3D rolloff
	} else {
		rolloff_factor = 3.0f;		// EAX rolloff
	}

	hr = pDS3D_listener->SetRolloffFactor( rolloff_factor, DS3D_DEFERRED );
	hr = pDS3D_listener->SetDopplerFactor( 1.0f, DS3D_DEFERRED );
	
	hr = pDS3D_listener->CommitDeferredSettings();
	if ( hr != DS_OK ) {
		nprintf(("SOUND","Error in pDS3D_listener->CommitDeferredSettings(): %s\n", get_DSERR_text(hr) ));
		return -1;
	}

	return 0;
}
コード例 #4
0
//===========================================================================
// DS_Listener
//	SFXLP_UNITS_PER_METER
//	SFXLP_DOPPLER
//	SFXLP_UPDATE
//===========================================================================
void DS_Listener(int property, float value)
{
	if(!dsListener) return;

	switch(property)
	{
	case SFXLP_UPDATE:
		// Commit any deferred settings.
		dsListener->CommitDeferredSettings();
		EAXCommitDeferred();
		break;

	case SFXLP_UNITS_PER_METER:
		dsListener->SetDistanceFactor(1/value, DS3D_IMMEDIATE);
		break;

	case SFXLP_DOPPLER:
		dsListener->SetDopplerFactor(value, DS3D_IMMEDIATE);
		break;
	}
}
コード例 #5
0
//===========================================================================
// DS_Init
//===========================================================================
int DS_Init(void)
{
	HWND				hWnd;
	DSBUFFERDESC		desc;
	LPDIRECTSOUNDBUFFER	bufTemp;

	if(initOk) return true;

	// Are we in verbose mode?	
	if((verbose = ArgExists("-verbose")))
		Con_Message("DS_Init(Compat): Initializing sound driver...\n");

	// Get Doomsday's window handle.
	hWnd = (HWND) DD_GetInteger(DD_WINDOW_HANDLE);

	hr = DS_OK;
	if(ArgExists("-noeax") 
		|| FAILED(hr = EAXDirectSoundCreate(NULL, &dsound, NULL)))
	{
		// EAX can't be initialized. Use normal DS, then.
		if(FAILED(hr)) Error("DS_Init", "EAX 2 couldn't be initialized.");
		if(FAILED(hr = DirectSoundCreate(NULL, &dsound, NULL)))
		{
			Error("DS_Init", "Failed to create dsound interface.");
			return false;
		}
	}
	// Set the cooperative level.
	if(FAILED(hr = dsound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY)))
	{
		Error("DS_Init", "Couldn't set dSound coop level.");
		return false;
	}
	// Get the primary buffer and the listener.
	primary = NULL;
	memset(&desc, 0, sizeof(desc));
	desc.dwSize = sizeof(desc);
	desc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER;
	dsListener = NULL;
	if(SUCCEEDED(dsound->CreateSoundBuffer(&desc, &primary, NULL)))
	{
		// Query the listener interface.
		primary->QueryInterface(IID_IDirectSound3DListener, 
			(void**) &dsListener);
	}
	else
	{
		// Failure; get a 2D primary buffer, then.
		desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
		dsound->CreateSoundBuffer(&desc, &primary, NULL);
	}
	// Start playing the primary buffer.
	if(primary) 
	{
		if(FAILED(hr = primary->Play(0, 0, DSBPLAY_LOOPING)))
			Error("DS_Init", "Can't play primary buffer.");
	}
	
	// Try to get the EAX listener property set. 
	// Create a temporary secondary buffer for it.
	eaxListener = NULL;
	if(SUCCEEDED(CreateDSBuffer(DSBCAPS_STATIC | DSBCAPS_CTRL3D, 
		DSBSIZE_MIN, 22050, 8, 1, &bufTemp)))
	{
		// Now try to get the property set.
		if(SUCCEEDED(hr = bufTemp->QueryInterface(IID_IKsPropertySet, 
			(void**) &eaxListener)))
		{
			DWORD support = 0, revsize = 0;
			// Check for support.
			if(FAILED(hr = eaxListener->QuerySupport(
				DSPROPSETID_EAX_ListenerProperties,
				DSPROPERTY_EAXLISTENER_ENVIRONMENT,
				&support)) 
				|| ((support & NEEDED_SUPPORT) != NEEDED_SUPPORT))
			{
				Error("DS_Init", "Sufficient EAX2 support not present.");
				eaxListener->Release();
				eaxListener = NULL;
			}
			else
			{
				// EAX is supported!
				if(verbose) Con_Message("DS_Init(Compat): EAX2 is available.\n");
			}
		}
		// Release the temporary buffer interface.
		bufTemp->Release();
	}
		
	// Get the caps.
	dsCaps.dwSize = sizeof(dsCaps);
	dsound->GetCaps(&dsCaps);
	if(verbose) Con_Message("DS_Init(Compat): Number of hardware 3D "
		"buffers: %i\n", dsCaps.dwMaxHw3DAllBuffers);

	// Configure the DS3D listener.
	if(dsListener)
	{
		dsListener->SetDistanceFactor(1/36.0f, DS3D_DEFERRED);
		dsListener->SetDopplerFactor(2, DS3D_DEFERRED);
	}

	// Success!
	initOk = true;
	return true;
}
コード例 #6
0
// ---------------------------------------------------------------------------------------
// ds3d_update_listener()
//
//	returns:		0		=>		success
//					-1		=>		failure
//
int ds3d_update_listener(vec3d* pos, vec3d* vel, matrix* orient)
{
	if (DS3D_inited == FALSE)
		return 0;

#ifdef USE_OPENAL
	// set the listener position
	if ( pos != NULL ) {
		OpenAL_ErrorPrint( alListener3f(AL_POSITION, pos->xyz.x, pos->xyz.y, pos->xyz.z) );
	}

	// set the listener velocity
	if ( vel != NULL ) {
		OpenAL_ErrorPrint( alListener3f(AL_VELOCITY, vel->xyz.x, vel->xyz.y, vel->xyz.z) );
	}

	// set the listener orientation
	if ( orient != NULL ) {
		// uvec is up/top vector, fvec is at/front vector
		ALfloat list_orien[] = { orient->vec.fvec.xyz.x, orient->vec.fvec.xyz.y, orient->vec.fvec.xyz.z,
									orient->vec.uvec.xyz.x, orient->vec.uvec.xyz.y, orient->vec.uvec.xyz.z };
		OpenAL_ErrorPrint( alListenerfv(AL_ORIENTATION, list_orien) );
	}

#else

	HRESULT hr;

	if (pDS3D_listener == NULL)
		return -1;

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

	// set the listener veclocity
	if (vel != NULL)
	{
		hr = pDS3D_listener->SetVelocity(vel->xyz.x, vel->xyz.y, vel->xyz.z, DS3D_DEFERRED);
	}

	if (orient != NULL)
	{
		hr = pDS3D_listener->SetOrientation(orient->vec.fvec.xyz.x, orient->vec.fvec.xyz.y, orient->vec.fvec.xyz.z,
			orient->vec.uvec.xyz.x, orient->vec.uvec.xyz.y, orient->vec.uvec.xyz.z,
			DS3D_DEFERRED);
	}

	float rolloff_factor = 1.0f;
	if (ds_using_a3d() == true)
	{
		rolloff_factor = 3.0f;		// A3D rolloff
	}
	else
	{
		rolloff_factor = 3.0f;		// EAX rolloff
	}

	hr = pDS3D_listener->SetRolloffFactor(rolloff_factor, DS3D_DEFERRED);
	hr = pDS3D_listener->SetDopplerFactor(1.0f, DS3D_DEFERRED);

	hr = pDS3D_listener->CommitDeferredSettings();
	if (hr != DS_OK)
	{
		nprintf(("SOUND", "Error in pDS3D_listener->CommitDeferredSettings(): %s\n", get_DSERR_text(hr)));
		return -1;
	}
#endif

	return 0;
}