> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CreateCaptureAudioStateMonitorForCategoryAndDeviceRole

> CreateCaptureAudioStateMonitorForCategoryAndDeviceRole

# CreateCaptureAudioStateMonitorForCategoryAndDeviceRole

指定したカテゴリかつ指定したロールに属するすべてのオーディオ キャプチャ ストリームのオーディオ レベルを監視する、[IAudioStateMonitor](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor) の新しいインスタンスを作成します。

## 構文

```cpp theme={null}
HRESULT WINAPI CreateCaptureAudioStateMonitorForCategoryAndDeviceRole(
  AUDIO_STREAM_CATEGORY category,
  ERole role,
  _Out_ IAudioStateMonitor **audioStateMonitor
);
```

### パラメーター

*category*\
型: AUDIO\_STREAM\_CATEGORY

監視するオーディオ キャプチャ ストリームのカテゴリを指定する、**AUDIO\_STREAM\_CATEGORY** 列挙型のメンバーです。

*role*\
型: ERole

監視するオーディオ キャプチャ ストリームのロールを指定する、<a href="https://learn.microsoft.com/en-us/windows/desktop/api/mmdeviceapi/ne-mmdeviceapi-erole" target="_blank">ERole</a> 列挙型のメンバーです。

*audioStateMonitor* \_Out\_\
型: IAudioStateMonitor\*\*

作成された `IAudioStateMonitor` オブジェクトがこの出力パラメーターに設定されます。

### 戻り値

メソッドが成功した場合、`S\_OK` が返されます。

## 解説

これは、`AudioStateMonitor` インスタンスを作成して返す関数の 1 つです。

キャプチャ ストリームとレンダー ストリームのそれぞれに 4 つのバリアントがあり、特定のロールに対してプロセスが以下のいずれを実行できるかを決定します。

* あらゆるカテゴリの任意のオーディオをキャプチャまたはレンダリングする
* 特定のカテゴリのオーディオをキャプチャまたはレンダリングする
* 特定のカテゴリのオーディオを特定のエンドポイントに対してキャプチャまたはレンダリングする。エンドポイントは `MMDevice` ID (`IMMDevice::GetId()` を使用して取得) または `SWD` ID (`Windows.Devices.Enumeration` あるいは `Windows.Media.Devices.MediaDevice` を使用して取得) を用いて指定できます。
* 特定のカテゴリのオーディオを既定のエンドポイントに対してキャプチャまたはレンダリングする

次のシナリオを考えてみます。ゲームが、OS のポリシーによってオーディオがミュートされないことがわかっている場合にのみ、ゲーム内 GameChat 機能を有効化したいとします。これを実現するために、ゲームは既定の通信エンドポイントの [AudioCategory\_GameChat](https://learn.microsoft.com/windows/win32/api/audiosessiontypes/ne-audiosessiontypes-audio_stream_category) ストリーム カテゴリに対して SoundLevel 通知を登録します。

このカテゴリの SoundLevel が 'Muted' に設定されている場合、ゲームは GameChat セッションを停止します。SoundLevel がそれ以外の値に設定されている場合、ゲームは GameChat ストリームを有効化します。

次のコード例は、このシナリオに合わせて適切な `IAudioStateMonitor` オブジェクトをゲームで作成する方法を示しています。

```cpp theme={null}
HRESULT RegisterForSoundLevelChanges() 
{ 
HRESULT hr = S_OK; 

// Create a new AudioStateMonitor for the GameChat category, if needed, and 
// register for callbacks. 
if (m_audioStateMonitor == nullptr) 
{ 
hr = CreateCaptureAudioStateMonitorForCategoryAndDeviceRole( 
AudioCategory_GameChat, ERole::eCommunications, 
g_audioStateMonitor.put()); 
if (SUCCEEDED(hr)) 
{ 
// Optional "context" parameter is not used in this example, 
// and is set to nullptr. 
hr = g_audioStateMonitor->RegisterCallback(OnAudioStateMonitorCallback, nullptr, &m_registration); 
} 
} 

if (FAILED(hr)) 
{ 
// g_audioStateMonitor is a smart pointer, so if an IAudioStateMonitor was 
// allocated, setting the smart pointer to null invokes the Release method 
// which will decrement its usage count and ensure that the object is properly 
// destroyed. 
g_audioStateMonitor = nullptr; 
} 
return hr; 
} 
```

## 要件

**ヘッダー:** Audiostatemonitorapi.h

**ライブラリ:** Windows.Media.MediaControl.lib

**サポートされるプラットフォーム:** Windows、XBOX One ファミリ本体および XBOX Series 本体

## 関連項目

[AUDIO\_STREAM\_CATEGORY](https://learn.microsoft.com/windows/win32/api/audiosessiontypes/ne-audiosessiontypes-audio_stream_category)

[WASAPI について](https://learn.microsoft.com/windows/desktop/CoreAudio/wasapi)

[WASAPI](/build/console-features/audio/overviews/wasapi-overview)


## Related topics

- [IAudioStateMonitor インターフェイス](/ja-jp/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor.md)
- [AudioStateMonitor](/ja-jp/reference/audio/audiostatemonitor/audiostatemonitor_members.md)
- [CreateRenderAudioStateMonitorForCategoryAndDeviceRole](/ja-jp/reference/audio/audiostatemonitor/functions/createrenderaudiostatemonitorforcategoryanddevicerole.md)
- [CreateCaptureAudioStateMonitorForCategoryAndDeviceId](/ja-jp/reference/audio/audiostatemonitor/functions/createcaptureaudiostatemonitorforcategoryanddeviceid.md)
- [CreateCaptureAudioStateMonitorForCategory](/ja-jp/reference/audio/audiostatemonitor/functions/createcaptureaudiostatemonitorforcategory.md)
