本文介绍了X3DAudio:X3DAudioCalculate的结果没有意义?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好, 我正在尝试将XAudio2 / X3DAudio声音引擎添加到3D模拟中。现在我对X3DAudioCalculate()函数有两个问题: 首先我猜,pMatrixCoefficients []交换左右耳,如下所示。 其次,如果我使用X3DAUDIO_CALCULATE_DOPPLER计算DopplerFactor,它总是1.0。 我将项目缩减为这个可运行的小代码.. #include" DirectXSDK / inlcude / xaudio2.h" #include" DirectXSDK / inlcude / X3DAudio.h" #include" DirectXSDK / inlcude / d3dx9math.h" #include< iostream> #define SRC_CHANNEL_COUNT 1 #define DST_CHANNEL_COUNT 2 #define CHANNEL_MASK 0x3 #define X3DAUDIO_CALCULATE_ALL 0x0003007F int main() { //数据 X3DAUDIO_HANDLE X3DInstance; X3DAUDIO_DSP_SETTINGS DSPSettings = {0}; X3DAUDIO_LISTENER听众= {0}; X3DAUDIO_EMITTER发射器= {0}; FLOAT32 * matrixOutput = new FLOAT32 [DST_CHANNEL_COUNT]; FLOAT32 * matrixDelay = new FLOAT32 [DST_CHANNEL_COUNT]; //初始化 X3DAudioInitialize(CHANNEL_MASK,X3DAUDIO_SPEED_OF_SOUND,X3DInstance); // DSPSettings输入 DSPSettings.SrcChannelCount = SRC_CHANNEL_COUNT; DSPSettings.DstChannelCount = DST_CHANNEL_COUNT; DSPSettings.pMatrixCoefficients = matrixOutput; DSPSettings.pDelayTimes = matrixDelay; //设置发射器和监听器 Emitter.ChannelCount = 1; Emitter.CurveDistanceScaler = 1; Emitter.OrientFront = D3DXVECTOR3(0,0,0); Emitter.OrientTop = D3DXVECTOR3(0,0,0); Emitter.Position = D3DXVECTOR3(0,5,0); Emitter.Velocity = D3DXVECTOR3(0,10,0); Listener.OrientFront = D3DXVECTOR3(1,0,0); Listener.OrientTop = D3DXVECTOR3(0,0,1); Listener.Position = D3DXVECTOR3(0,0,0); Listener.Velocity = D3DXVECTOR3(0,0,0); //计算 X3DAudioCalculate(X3DInstance,& Listener,& Emitter,X3DAUDIO_CALCULATE_ALL,& DSPSettings); // DSPSettings的输出 std :: cout<< " ------------------------------ DSPSetting ----------------- -------------" << std :: endl << "输入频道:" << DSPSettings.SrcChannelCount<< std :: endl << "输出通道:" << DSPSettings.DstChannelCount<< std :: endl << "输出矩阵:" << DSPSettings.pMatrixCoefficients [0]<< std :: endl << " " << DSPSettings.pMatrixCoefficients [1]<< std :: endl << "倾听者速度:" << DSPSettings.ListenerVelocityComponent<< std :: endl << "发射器速度:" << DSPSettings.EmitterVelocityComponent<< std :: endl << "DopplerFactor:" << DSPSettings.DopplerFactor<< std :: endl << "LPFDirect:" << DSPSettings.LPFDirectCoefficient<< std :: endl << "LPFReverb:" << DSPSettings.LPFReverbCoefficient<< std :: endl << "角度:" << DSPSettings.EmitterToListenerAngle<< std :: endl << "距离:" << DSPSettings.EmitterToListenerDistance<< std :: endl << "pDelayTimes:" << DSPSettings.pDelayTimes [0]<< std :: endl << " " << DSPSettings.pDelayTimes [1]<< std :: endl << "ReverbLevel:" << DSPSettings.ReverbLevel<< std :: endl << " ------------------------------------------------ ----------------------" <<的std :: ENDL; while(1); 返回0; } ..并在控制台上获得以下输出。 ----------------------- ------- DSPSetting ------------------------------ 输入频道:1 输出通道:2 输出矩阵:0 0.2 听众速度:0 发射器速度:-10 多普勒效应器:1 LPFDirect:0.75 LPFReverb:0.75 角度:1.5708 距离:5 pDelayTimes:1 0 ReverbLevel:0 -------- -------------------------------------------------- ------------ 我期待一个DopplerFactor< 1,所有声音都是左耳而不是右耳。任何人都可以帮助我,我做错了。 谢谢你, sRogge 解决方案 在这个主题上花了几个小时后,我仍然没有发现我的错误。 如果我改变Listener.OrientTop的方向并自行重新计算DopplerFactor,它的工作正常。 // .. 。 //计算 X3DAudioCalculate(X3DInstance,& Listener,& Emitter,X3DAUDIO_CALCULATE_ALL,& DSPSettings); float c = X3DAUDIO_SPEED_OF_SOUND; DSPSettings.DopplerFactor =(c - DSPSettings.ListenerVelocityComponent)/(c - DSPSettings.EmitterVelocityComponent); // ... 但如果有人知道我做错了什么,欢迎他告诉我。 。$ Hello,I'm trying to add an XAudio2/X3DAudio sound engine to a 3D simulation. Now I have two problems with the X3DAudioCalculate() function:First I guess, the pMatrixCoefficients[] swap the left and right ear as you can see below.Second, if I calculate the DopplerFactor with X3DAUDIO_CALCULATE_DOPPLER, it is always 1.0.I reduced my project to this small runningable code..#include "DirectXSDK/inlcude/xaudio2.h"#include "DirectXSDK/inlcude/X3DAudio.h"#include "DirectXSDK/inlcude/d3dx9math.h"#include <iostream>#define SRC_CHANNEL_COUNT 1#define DST_CHANNEL_COUNT 2#define CHANNEL_MASK 0x3#define X3DAUDIO_CALCULATE_ALL 0x0003007Fint main(){//DataX3DAUDIO_HANDLE X3DInstance;X3DAUDIO_DSP_SETTINGS DSPSettings = {0};X3DAUDIO_LISTENER Listener = {0};X3DAUDIO_EMITTER Emitter = {0};FLOAT32 *matrixOutput = new FLOAT32[DST_CHANNEL_COUNT];FLOAT32 *matrixDelay = new FLOAT32[DST_CHANNEL_COUNT];//InitialiationX3DAudioInitialize(CHANNEL_MASK, X3DAUDIO_SPEED_OF_SOUND, X3DInstance );//DSPSettings inputDSPSettings.SrcChannelCount = SRC_CHANNEL_COUNT;DSPSettings.DstChannelCount = DST_CHANNEL_COUNT;DSPSettings.pMatrixCoefficients = matrixOutput;DSPSettings.pDelayTimes = matrixDelay;//Setting up emitter and listenerEmitter.ChannelCount = 1;Emitter.CurveDistanceScaler = 1;Emitter.OrientFront = D3DXVECTOR3(0, 0, 0);Emitter.OrientTop = D3DXVECTOR3(0, 0, 0);Emitter.Position = D3DXVECTOR3(0, 5, 0);Emitter.Velocity = D3DXVECTOR3(0, 10, 0);Listener.OrientFront = D3DXVECTOR3(1, 0, 0);Listener.OrientTop = D3DXVECTOR3(0, 0, 1);Listener.Position = D3DXVECTOR3(0, 0, 0);Listener.Velocity = D3DXVECTOR3(0, 0, 0);//CalculateX3DAudioCalculate(X3DInstance, &Listener, &Emitter,X3DAUDIO_CALCULATE_ALL, &DSPSettings);//Output of DSPSettingsstd::cout << "------------------------------DSPSetting------------------------------" << std::endl << "Input Channels: " << DSPSettings.SrcChannelCount << std::endl << "Output Channels: " << DSPSettings.DstChannelCount << std::endl << "Output Matrix: " << DSPSettings.pMatrixCoefficients[0] << std::endl << " " << DSPSettings.pMatrixCoefficients[1] << std::endl << "Listener Velocity: " << DSPSettings.ListenerVelocityComponent << std::endl << "Emitter Velocity: " << DSPSettings.EmitterVelocityComponent << std::endl << "DopplerFactor: " << DSPSettings.DopplerFactor << std::endl << "LPFDirect: " << DSPSettings.LPFDirectCoefficient << std::endl << "LPFReverb: " << DSPSettings.LPFReverbCoefficient << std::endl << "Angle: " << DSPSettings.EmitterToListenerAngle << std::endl << "Distance: " << DSPSettings.EmitterToListenerDistance << std::endl << "pDelayTimes: " << DSPSettings.pDelayTimes[0] << std::endl << " " << DSPSettings.pDelayTimes[1] << std::endl << "ReverbLevel: " << DSPSettings.ReverbLevel << std::endl << "----------------------------------------------------------------------" << std::endl;while(1);return 0;}..and get the following output on the console.------------------------------DSPSetting------------------------------Input Channels: 1Output Channels: 2Output Matrix: 0 0.2Listener Velocity: 0Emitter Velocity: -10DopplerFactor: 1LPFDirect: 0.75LPFReverb: 0.75Angle: 1.5708Distance: 5pDelayTimes: 1 0ReverbLevel: 0----------------------------------------------------------------------I expected a DopplerFactor < 1 and all sound an the left ear instead of right. Can anyone help me, what I did wrong.Thank you,sRogge 解决方案 After some more hours on this topic I still did not found my bug.It works just fine, if I change the direction of Listener.OrientTop and recalculate DopplerFactor on my own ..//...//CalculateX3DAudioCalculate(X3DInstance, &Listener, &Emitter, X3DAUDIO_CALCULATE_ALL, &DSPSettings);float c = X3DAUDIO_SPEED_OF_SOUND;DSPSettings.DopplerFactor = (c - DSPSettings.ListenerVelocityComponent) / (c - DSPSettings.EmitterVelocityComponent);//...But if anyone knows what I did wrong, he's welcome to tell me.. 这篇关于X3DAudio:X3DAudioCalculate的结果没有意义?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-23 04:32