IAudioEffectsManager::SetAudioEffectState 方法 (audioclient.h)
设置指定音频效果的状态。
语法
HRESULT SetAudioEffectState(
GUID effectId,
AUDIO_EFFECT_STATE state
);
参数
effectId
正在更改其状态的效果的 GUID 标识符。 音频效果 GUID 在 ksmedia.h 中定义。
state
AUDIO_EFFECT_STATE 枚举中 指定要设置的状态的值。
返回值
返回 HRESULT,包括但不限于以下内容。
值 | 说明 |
---|---|
S_OK | 成功 |
AUDCLNT_E_EFFECT_NOT_AVAILABLE | 指定的效果不可用 |
AUDCLNT_E_EFFECT_STATE_READ_ONLY | 指定的效果具有只读状态 |
AUDCLNT_E_DEVICE_INVALIDATED | 关联的音频流已被销毁。 |
注解
通过调用 GetAudioEffects 获取关联音频流的音频效果的当前列表。
示例
以下示例演示如何使用 IAudioEffectsManager.SetAudioEffectState 禁用 AUDIO_EFFECT_TYPE_DEEP_NOISE_SUPPRESSION 效果。
HRESULT TryDisablePlatformDeepNoiseSuppression(_In_ IAudioClient *client)
{
wil::com_ptr_nothrow<IAudioEffectsManager> audioEffectsManager;
RETURN_IF_FAILED(client->GetService(IID_PPV_ARGS(&audioEffectsManager)));
wil::unique_cotaskmem_array_ptr<AudioEffect> effects;
UINT32 numEffects;
RETURN_IF_FAILED(audioEffectsManager->GetAudioEffects(&effects, &numEffects));
for (UINT32 i = 0; i < numEffects; i++)
{
if (effects[i].id == AUDIO_EFFECT_TYPE_DEEP_NOISE_SUPPRESSION)
{
// Check if deep noise suppression can be set and if it is currently on
if (effects[i].canSetState && effects[i].state == AUDIO_EFFECT_STATE_ON)
{
HRESULT hr = audioEffectsManager->SetAudioEffectState(effects[i].id, AUDIO_EFFECT_STATE_OFF);
// If canSetState changed to false, or the effect was removed, SetAudioEffectState
// can fail with one of the following error codes.
if (hr != AUDCLNT_E_EFFECT_NOT_AVAILABLE && hr != AUDCLNT_E_EFFECT_STATE_READ_ONLY)
{
return hr;
}
}
return S_OK;
}
}
return S_OK;
}
以下示例演示如何使用 IAudioEffectsManager.SetAudioEffectState 启用 AUDIO_EFFECT_TYPE_DEEP_NOISE_SUPPRESSION 效果。
HRESULT TryEnablePlatformDeepNoiseSuppression(_In_ IAudioClient *client)
{
wil::com_ptr_nothrow<IAudioEffectsManager> audioEffectsManager;
RETURN_IF_FAILED(client->GetService(IID_PPV_ARGS(&audioEffectsManager)));
wil::unique_cotaskmem_array_ptr<AUDIO_EFFECT> effects;
UINT32 numEffects;
RETURN_IF_FAILED(audioEffectsManager->GetAudioEffects(&effects, &numEffects));
for (UINT32 i = 0; i < numEffects; i++)
{
if (effects[i].id == AUDIO_EFFECT_TYPE_DEEP_NOISE_SUPPRESSION)
{
// Check if deep noise suppression can be set and if it is currently off
if (effects[i].canSetState && effects[i].state == AUDIO_EFFECT_STATE_OFF)
{
HRESULT hr = audioEffectsManager->SetAudioEffectState(effects[i].id, AUDIO_EFFECT_STATE_ON);
// If canSetState changed to false, or the effect was removed, SetAudioEffectState
// can fail with one of the following error codes.
if (hr != AUDCLNT_E_EFFECT_NOT_AVAILABLE && hr != AUDCLNT_E_EFFECT_STATE_READ_ONLY)
{
return hr;
}
}
return S_OK;
}
}
return S_OK;
}
要求
要求 | 值 |
---|---|
最低受支持的客户端 | Windows 内部版本 22000 |
标头 | audioclient.h |