Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

XAudio2 3D Sound

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 Medo3337   Members   

891
Like
0Likes
Like

Posted 02 April 2013 - 07:51 PM

I initialized XAudio2 and I'm able to play audio files normally, now I'm looking to play the sound in 3D space.

 

I'm using the following code to set the position of the emitter (model position) and the position of the listener (camera position), not sure what changes should I make to get it to work:

 

void updateAudioPosition()
{
     X3DAUDIO_VECTOR p;

     // Set the position of the listener in 3D space
     p.x = 0.0f;
     p.y = 0.0f;
     p.z = 0.0f;
     xAudioListener.Position = p;

     // Set the position of the emitter in 3D space
     p.x = 500.0f;
     p.y = 100.0f;
     p.z = 400.0f;
     xAudioEmitter.Position = p;


     DWORD dwCalcFlags = X3DAUDIO_CALCULATE_MATRIX | X3DAUDIO_CALCULATE_DOPPLER
     | X3DAUDIO_CALCULATE_LPF_DIRECT | X3DAUDIO_CALCULATE_LPF_REVERB
     | X3DAUDIO_CALCULATE_REVERB;

     X3DAudioCalculate(X3DInstance, &xAudioListener, &xAudioEmitter, dwCalcFlags, &DSPSettings);
     pSourceVoice->SetFrequencyRatio(DSPSettings.DopplerFactor);
     pSourceVoice->SetOutputMatrix(NULL, 1, 1, &DSPSettings.ReverbLevel);
}

void render_frame()
{
      // Code to render the scene here...
      updateAudioPosition();
}

 



#2 Dawoodoz   Members   

459
Like
0Likes
Like

Posted 03 April 2013 - 02:23 AM

Your emitter is very far away from the listener.

 

I abandoned XAudio2 because it had too many bugs.


"App". is an acronym and must always be followed by a dot.

https://en.oxforddictionaries.com/punctuation/punctuation-in-abbreviations


#3 Medo3337   Members   

891
Like
0Likes
Like

Posted 03 April 2013 - 03:14 PM

@Dawoodoz: That's not the problem, I'm getting the following exception:

 

Unhandled exception at 0x773715de in XAudio Test.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1.

 

on line:

 

X3DAudioCalculate(X3DInstance, &xAudioListener, &xAudioEmitter, dwCalcFlags, &DSPSettings);


#4 Dawoodoz   Members   

459
Like
0Likes
Like

Posted 04 April 2013 - 06:25 AM

0xcdcdcdd1 = 0xcdcdcdcd + 4 byte

It looks like one of the pointers are uninitialized memory from the debug environment.

Make sure that all pointers are initialized to Null before allocating.


"App". is an acronym and must always be followed by a dot.

https://en.oxforddictionaries.com/punctuation/punctuation-in-abbreviations


#5 Medo3337   Members   

891
Like
0Likes
Like

Posted 04 April 2013 - 03:31 PM

Got rid of the exception, now I'm trying to setup the basic XAudio2 3D Sound.
 
Tried the following code:
pXAudio2->GetDeviceDetails(0, &details);
X3DAudioInitialize(details.OutputFormat.dwChannelMask, X3DAUDIO_SPEED_OF_SOUND, X3DInstance);

emitter.Position = D3DXVECTOR3(5.0f, 2.0f, 0.0f);
X3DAUDIO_CONE emitterCone;
emitter.pCone = &(emitterCone);
emitter.pCone->InnerAngle = 0.0f;
// Setting the inner cone angles to X3DAUDIO_2PI and
// outer cone other than 0 causes
// the emitter to act like a point emitter using the
// INNER cone settings only.
emitter.pCone->OuterAngle = 0.0f;
// Setting the outer cone angles to zero causes
// the emitter to act like a point emitter using the
// OUTER cone settings only.
emitter.InnerRadius = 0.0f;
emitter.InnerRadiusAngle = 0.0f;
emitter.pCone->InnerVolume = 0.0f;
emitter.pCone->OuterVolume = 1.0f;
emitter.pCone->InnerLPF = 0.0f;
emitter.pCone->OuterLPF = 1.0f;
emitter.pCone->InnerReverb = 0.0f;
emitter.pCone->OuterReverb = 1.0f;


emitter.OrientFront = D3DXVECTOR3( 0, 0, 1 );
emitter.OrientTop = D3DXVECTOR3( 0, 1, 0 );
emitter.ChannelCount = 8;
emitter.ChannelRadius = 1.0f;
FLOAT32 emitterAzimuths[8];
emitter.pChannelAzimuths = emitterAzimuths;

// Use of Inner radius allows for smoother transitions as
// a sound travels directly through, above, or below the listener.
// It also may be used to give elevation cues.
emitter.InnerRadius = 2.0f;
emitter.InnerRadiusAngle = X3DAUDIO_PI/4.0f;

emitter.pVolumeCurve = NULL; //(X3DAUDIO_DISTANCE_CURVE*)&X3DAudioDefault_LinearCurve;
emitter.pLFECurve    = NULL; //(X3DAUDIO_DISTANCE_CURVE*)&Emitter_LFE_Curve;
emitter.pLPFDirectCurve = NULL; // use default curve
emitter.pLPFReverbCurve = NULL; // use default curve
emitter.pReverbCurve    = (X3DAUDIO_DISTANCE_CURVE*)&Emitter_Reverb_Curve;


listener.OrientFront = D3DXVECTOR3( 0, 0, 1 );
listener.OrientTop = D3DXVECTOR3( 0, 1, 0 );
listener.Position = D3DXVECTOR3(0, 0, 0);
listener.OrientFront = D3DXVECTOR3( 0, 0, 1 );
listener.OrientTop = D3DXVECTOR3( 0, 1, 0 );
listener.pCone = NULL; //(X3DAUDIO_CONE*)&Listener_DirectionalCone;
        listener.Position = D3DXVECTOR3(0.0f, 0.0f, 0.0f);


ZeroMemory(&dspSettings, sizeof(dspSettings));
    dspSettings.SrcChannelCount = 1;
dspSettings.DstChannelCount = details.OutputFormat.Format.nChannels;    
dspSettings.pMatrixCoefficients = matrixCoefficients;


DWORD dwCalcFlags = X3DAUDIO_CALCULATE_MATRIX | X3DAUDIO_CALCULATE_DOPPLER
| X3DAUDIO_CALCULATE_LPF_DIRECT | X3DAUDIO_CALCULATE_LPF_REVERB
| X3DAUDIO_CALCULATE_REVERB;
X3DAudioCalculate(X3DInstance, &listener, &emitter, dwCalcFlags, &dspSettings);
pSourceVoice->SetFrequencyRatio(dspSettings.DopplerFactor);
pSourceVoice->SetOutputMatrix(NULL, 1, details.OutputFormat.Format.nChannels, dspSettings.pMatrixCoefficients);

 

I'm trying to play the sound in (x = 5.0f, y = 2.0f, z = 0.0f) which is the emitter position

and the listener position is located in (x = 0.0f, y = 0.0f, z = 0.0f)

 

I can hear the sound but it's not like in 3D space, whats wrong?



#6 Medo3337   Members   

891
Like
0Likes
Like

Posted 05 April 2013 - 09:32 AM

I got it to work correctly after changing the parameters that I pass to "pSourceVoice->SetOutputMatrix".

 

Now, I notice when a model go a little far, I don't hear the sound well, what settings should I put to make the player hear the sound even if the model is far away?

I want the player to stop hearing the sound when the model is far ENOUGH.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.