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
你們能夠編譯完整代碼來體驗一下。對象