Jump to content

  • Log In with Google      Sign In   
  • Create Account


XAudio2 3D Sound


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   -  Reputation: 665

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();
}

 



Sponsor:

#2 Dawoodoz   Members   -  Reputation: 290

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.


My open source DirectX 10/11 graphics engine. https://sites.google.com/site/dawoodoz

"My design pattern is the simplest to understand. Everyone else is just too stupid to understand it."


#3 Medo3337   Members   -  Reputation: 665

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   -  Reputation: 290

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.


My open source DirectX 10/11 graphics engine. https://sites.google.com/site/dawoodoz

"My design pattern is the simplest to understand. Everyone else is just too stupid to understand it."


#5 Medo3337   Members   -  Reputation: 665

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   -  Reputation: 665

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.



PARTNERS