> ## 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.

# AudioStateMonitorSoundLevel 列挙型

> AudioStateMonitorSoundLevel 列挙型

# AudioStateMonitorSoundLevel 列挙型

キャプチャ ストリームまたはレンダー ストリームのサウンド レベルを指定します。

## 構文

```cpp theme={null}
typedef enum _AudioStateMonitorSoundLevel { 
  Full = 0,
  Low = 1,
  Muted = 2
} AudioStateMonitorSoundLevel;
```

## 定数

| 定数    | 説明                   |
| ----- | -------------------- |
| Full  | サウンド レベルはフル ボリュームです。 |
| Low   | サウンド レベルは低です。        |
| Muted | サウンド レベルはミュート状態です。   |

## 解説

この列挙型は、[IAudioStateMonitor::GetSoundLevel](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-getsoundlevel) メソッドで使用されます。

次のシナリオを考えてみます。ゲームが、OS のポリシーによってオーディオがミュートされないことがわかっている場合にのみ GameMedia オーディオを再生するとします。これを実現するために、ゲームは既定のコンソール エンドポイントの [AudioCategory\_GameMedia](https://learn.microsoft.com/windows/desktop/api/audiosessiontypes/ne-audiosessiontypes-audio_stream_category) ストリーム カテゴリに対して SoundLevel 通知を登録します。このカテゴリの SoundLevel が 'Muted' に設定されている場合、ゲームは GameMedia ストリームの再生を停止します。SoundLevel がそれ以外の値に設定されている場合、ゲームは GameMedia ストリームを再生します。

```cpp theme={null}
// global variables 
winrt::com_ptr<IAudioStateMonitor> g_audioStateMonitor; 
AudioStateMonitorRegistrationHandle g_registration = 0; 

// Returns true if the GameMedia stream should be disabled, false if it should be 
// enabled. 
bool IsSoundLevelMuted(_In_ IAudioStateMonitor* audioStateMonitor) 
{ 
return (audioStateMonitor->GetSoundLevel() == AudioStateMonitorSoundLevel::Muted); 
} 

HRESULT StartTrackingSoundLevel() 
{ 
// Create an AudioStateMonitor and register for callbacks from it. 
HRESULT hr = RegisterForSoundLevelChanges(); 
if (SUCCEEDED(hr)) 
{ 
// Check the current sound level and determine if the GameMedia stream should 
// be enabled. 
bool disableGameMediaStream = IsSoundLevelMuted(g_audioStateMonitor.get()); 

// Add code here that enables or disables the GameMedia stream based on the 
// value of the boolean. 
} 
return hr; 
} 

HRESULT RegisterForSoundLevelChanges() 
{ 
HRESULT hr = S_OK; 

// Create a new AudioStateMonitor for the GameMedia category, if needed, and 
// register for callbacks. 
if (m_audioStateMonitor == nullptr) 
{ 
hr = CreateRenderAudioStateMonitorForCategoryAndDeviceRole( 
AudioCategory_GameMedia, ERole::eConsole, 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, &g_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; 
} 

// Unregister callbacks on program shutdown 
void UnregisterForSoundLevelChanges() 
{ 
if (g_audioStateMonitor != nullptr) 
{ 
if (g_registration) 
{ 
g_audioStateMonitor->UnregisterCallback(g_registration); 
} 

// g_audioStateMonitor is a smart pointer, so setting it to null 
// invokes the Release method to decrement its usage count. 
g_audioStateMonitor = nullptr; 
} 
} 

void OnAudioStateMonitorCallback(_In_ IAudioStateMonitor* audioStateMonitor, _In_opt_ void* context) 
{ bool disableGameMediaStream = IsSoundLevelMuted(audioStateMonitor); 

// Add code here that enables or disables the GameMedia stream based on the value 
// of the boolean. 
} 
```

## 要件

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

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

## 関連項目

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


## Related topics

- [IAudioStateMonitor::GetSoundLevel メソッド](/ja-jp/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-getsoundlevel.md)
- [AudioStateMonitor](/ja-jp/reference/audio/audiostatemonitor/audiostatemonitor_members.md)
- [CreateCaptureAudioStateMonitorForCategoryAndDeviceRole](/ja-jp/reference/audio/audiostatemonitor/functions/createcaptureaudiostatemonitorforcategoryanddevicerole.md)
- [CreateRenderAudioStateMonitorForCategoryAndDeviceRole](/ja-jp/reference/audio/audiostatemonitor/functions/createrenderaudiostatemonitorforcategoryanddevicerole.md)
- [CreateRenderAudioStateMonitorForCategory](/ja-jp/reference/audio/audiostatemonitor/functions/createrenderaudiostatemonitorforcategory.md)
