Skip to main content
GameDev.net gamedev.net
🔒 Locked

XACT3 - how to get attenuation with distance [RESOLVED]

Started by Buckeye Dec 19, 2010 at 10:04 AM 0 replies 1.7k views
Original Post
Buckeye
Buckeye
Problem: Using DX9, XAudio2, XACT - I can't detect an attenuation with increasing distance between listener and emitter. What am I missing?

The stereo direction from emitter to listener works well. Moving my eye direction "swings" the emitter sound appropriately, so I assume my DoWork routine which revises the listener position and emitter positions and invokes XACT3DCalculate and XACT3DApply to the cues is working as intended.

I pretty much lifted the code from the June 2010 SDK. Here's the major portion of my XACT initialization. This code is preceded by a successful load of the xgs file into pGlobalSettingsData, etc.

   // Initialize & create the XACT runtime     XACT_RUNTIME_PARAMETERS xrParams = {0};    xrParams.lookAheadTime = XACT_ENGINE_LOOKAHEAD_DEFAULT;	xrParams.fnNotificationCallback = XACTNotificationCallback;	xrParams.pGlobalSettingsBuffer = pGlobalSettingsData; 	xrParams.globalSettingsBufferSize = dwGlobalSettingsFileSize;	xrParams.globalSettingsFlags = XACT_FLAG_GLOBAL_SETTINGS_MANAGEDATA; // this will tell XACT to delete[] the buffer when its unneeded    hr = g_audioState.pEngine->Initialize( &xrParams );    if( FAILED( hr ) )        return hr;    ZeroMemory( &g_audioState.listener, sizeof( X3DAUDIO_LISTENER ) );    g_audioState.listener.OrientFront = D3DXVECTOR3(1, 0, 0 );    g_audioState.listener.OrientTop = D3DXVECTOR3( 0, 1, 0 );    g_audioState.listener.Position = D3DXVECTOR3( 0, 0, 0 );    g_audioState.listener.Velocity = D3DXVECTOR3( 0, 0, 0 );    ZeroMemory( &g_audioState.emitter, sizeof( X3DAUDIO_EMITTER ) );    g_audioState.emitter.pCone = NULL;    g_audioState.emitter.OrientFront = D3DXVECTOR3( 1, 0, 0 );    g_audioState.emitter.OrientTop = D3DXVECTOR3( 0, 1, 0 );    g_audioState.emitter.Position = D3DXVECTOR3( 0, 0, 0 );    g_audioState.emitter.Velocity = D3DXVECTOR3( 0, 0, 0 );    g_audioState.emitter.ChannelCount = 2;    g_audioState.emitter.ChannelRadius = 1.0f;    g_audioState.emitter.pChannelAzimuths = NULL;    g_audioState.emitter.pVolumeCurve = NULL;    g_audioState.emitter.pLFECurve = NULL;    g_audioState.emitter.pLPFDirectCurve = NULL;    g_audioState.emitter.pLPFReverbCurve = NULL;    g_audioState.emitter.pReverbCurve = NULL;    g_audioState.emitter.CurveDistanceScaler = 1.0f;    g_audioState.emitter.DopplerScaler = NULL;    g_audioState.DelayTimes[0] = 0.0f;    g_audioState.DelayTimes[1] = 0.0f;    // Init MatrixCoefficients. XACT will fill in the values    ZeroMemory( &g_audioState.MatrixCoefficients, sizeof( FLOAT32 ) * 8 * 2 );    // query number of channels on the final mix    WAVEFORMATEXTENSIBLE wfxFinalMixFormat;    hr = g_audioState.pEngine->GetFinalMixFormat( &wfxFinalMixFormat );    if( FAILED( hr ) ) return hr;    WORD nDstChannelCount = wfxFinalMixFormat.Format.nChannels;    ZeroMemory( &g_audioState.dspSettings, sizeof( X3DAUDIO_DSP_SETTINGS ) );    g_audioState.dspSettings.pMatrixCoefficients = g_audioState.MatrixCoefficients;    g_audioState.dspSettings.pDelayTimes = g_audioState.DelayTimes;    g_audioState.dspSettings.SrcChannelCount = 2;    g_audioState.dspSettings.DstChannelCount = nDstChannelCount;    // Initialize 3D settings    hr = XACT3DInitialize( g_audioState.pEngine, g_audioState.x3DInstance );    if( FAILED( hr ) )        return E_FAIL;

Following that initialization, the wave and sound banks are successfully loaded.

I start the sound as follows:
	g_audioState.pSoundBank->Prepare( snum, 0, 0, &pCue3D->pCue );	pCue3D->vEmitterPosition = emitterPos;	g_audioState.emitter.Position = pCue3D->vEmitterPosition;	XACT3DCalculate( g_audioState.x3DInstance, &g_audioState.listener, &g_audioState.emitter,						&g_audioState.dspSettings );	XACT3DApply( &g_audioState.dspSettings, pCue3D->pCue );	pCue3D->pCue->Play();

Other than attentuation with distance, the sounds play and I get the callback notification for the cue stop.

EDIT: I also tried adding a preset (and attached a sound) with a fast attenuation to -50db at 100 units. With the emitter distance at 100 units, there's no attenuation - i.e., same volume as emitter distance = 0.

[Edited by - Buckeye on December 19, 2010 7:49:56 PM]
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
Buckeye
Buckeye
Resolution: I'd forgotten I had to rebuild the XACT project after every change. Seems to be working as advertised now.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.