DirectSound以DMO(DirectX Nedua Objects)的方式提供了对原始音频数据的处理,开发者可以经过VC6.0里的Audio Effect DMO Wizard
来开发自定义的DMO。实际上这个DMO开发向导已经不在Visual Studio里面提供了,而且已经被MFT(Media Foundation Transforms)替代了,但这个不是咱们今天的重点。git
除此以外,DirectSound提供了如下标准DMO音效(原谅鄙人对音效这块不是很了解,所以没有翻译这些术语):github
全部标准音效都按照一致的方式来使用,首先先调用DirectSoundCreate8()
获取设备对象接口并设置协做级别:函数
if (DirectSoundCreate8(&DSDEVID_DefaultPlayback, &m_directSound8, NULL) != DS_OK) { throw std::exception("Error: maybe no default audio device in your system"); } if (m_directSound8->SetCooperativeLevel(windowHandle, DSSCL_PRIORITY) != DS_OK) { throw std::exception("set cooperative level on default audio device failed!"); }
容纳后经过设备对象接口获取播放声音的次缓冲区接口:oop
if (soundBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)&m_soundBufferInterface) != S_OK) throw std::exception("IDirectSoundBuffer8 interface not supported!");
接着经过次缓冲区接口的GetObjectInPath()
函数获取想要的音效接口:ui
IUnknown* interfacePtr; if (m_soundBufferInterface->GetObjectInPath( guid, guidIndex, interfaceGuidMaps[guid], (LPVOID*)&interfacePtr ) != DS_OK) throw std::exception( "GetObjectInPath error" );
最后,调用SetFX()
函数, 传入类型为DSEFFECTDESC的音效参数一个或多个音效参数:翻译
DSEFFECTDESC effectDescriptions = { 0 }; effectDescriptions.dwSize = sizeof(effectDescriptions); effectDescriptions.dwFlags = DSFX_LOCSOFTWARE; effectDescriptions.guidDSFXClass = effectGuid; ... auto callResult = m_soundBufferInterface->SetFX(m_effects.size(), m_effects.data(), resultCodes.data()); if (callResult != DS_OK) { ... }
Chorus音效即合声,标准音效参数由如下几个参数构成:code
Demo中我只实现了Chorus音效的应用:orm
你们能够编译完整代码来体验一下。对象