DirectSound对于单声道的Wav文件(或者说对于单声道的PCM音频数据)提供了内置3D音效的模拟,你能够控制每一个声源和收听者的立体位置,对移动的物体应用多普勒效果等等。在单个应用程序中,可以有多个声源,但是只能有一个收听者。
IDirectSound3DBuffer8::GetMaxDistance(D3DVALUE * pflMaxDistance);
IDirectSound3DBuffer8::GetMinDistance(D3DVALUE * pflMinDistance);
IDirectSound3DBuffer8::SetMaxDistance(D3DVALUE flMaxDistance, DWORD dwApply);
IDirectSound3DBuffer8::SetMinDistance(D3DVALUE flMinDistance, DWORD dwApply);
dwApply参数用来指定是立即生效还是延迟生效(需要调用CommitDeferredSettings函数)。
因为投射角度中外角肯定要比内角大,为了保证这一点我们需要做些额外的判断处理:
void MainWindow::on_coneAnglesInside_valueChanged(int value) { DWORD insideAngle, outsideAngle; if (m_wavPlayer.get3DSource()->GetConeAngles(&insideAngle, &outsideAngle) != DS_OK) throw std::exception("GetConeAngles error"); if (static_cast<unsigned>(value) > outsideAngle) ui->coneAnglesOutside->setValue(value), outsideAngle = value; if (m_wavPlayer.get3DSource()->SetConeAngles(value, outsideAngle, DS3D_IMMEDIATE) != DS_OK) throw std::exception("SetConeAngles error"); ui->coneAnglesInsideLabel->setText(QString("coneAnglesInside(%1)").arg(value)); }
这里也有一个特殊情况要处理:朝向的3个维度不能都为0,否则就是一个无效的方向:
#define SET_ONE_VECTOR_WITH_ZERO_CHECK_OF_SOURCE(getFunc, setFunc, sliderName, valueX, valueY, valueZ) \ D3DVECTOR vector; \ if (m_wavPlayer.get3DSource()->getFunc(&vector) != DS_OK) \ throw std::exception(#getFunc " error"); \ \ if (!(valueX == 0.0 && valueY == 0.0 && valueZ == 0.0)) \ if (m_wavPlayer.get3DSource()->setFunc(valueX, valueY, valueZ, DS3D_IMMEDIATE) != DS_OK) \ throw std::exception(#setFunc " error"); \ \ ui->sliderName##Label->setText(QString(#sliderName "(%1)").arg(value)); void MainWindow::on_coneOrientationX_valueChanged(int value) { SET_ONE_VECTOR_WITH_ZERO_CHECK_OF_SOURCE(GetConeOrientation, SetConeOrientation, coneOrientationX, value, vector.y, vector.z); }
其他相关设置这里就不给出代码了,都比较简单,有需要的可以看官方文档。
界面太大,我就分成3张图展示了:
完整代码见链接。
如对本文有疑问, 点击进行留言回复!!
FPGA/verilog 学习笔记(1)—— FPGA和HDL基础概念
2020年 浙江工业大学计算机科学与技术学硕 初试复试经验帖
网友评论