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

# CreateRenderAudioStateMonitor

> CreateRenderAudioStateMonitor

# CreateRenderAudioStateMonitor

\[일부 정보는 상용 출시 전에 크게 변경될 수 있는 사전 출시 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 명시적이든 묵시적이든 어떠한 보증도 하지 않습니다.]

모든 오디오 렌더링 스트림의 오디오 레벨을 모니터링하는 [IAudioStateMonitor](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor)의 새 인스턴스를 만듭니다.

## Syntax

```cpp theme={null}
HRESULT WINAPI CreateRenderAudioStateMonitor(
  _Out_ IAudioStateMonitor **audioStateMonitor
);
```

### Parameters

*audioStateMonitor* \_Out\_\
Type: IAudioStateMonitor\*\*

이 출력 매개변수에는 생성된 `IAudioStateMonitor` 객체가 채워집니다.

### Return value

Type: HRESULT

메서드가 성공하면 `S\_OK`를 반환합니다.

## Remarks

이 함수는 `AudioStateMonitor` 인스턴스를 생성하고 반환하는 함수들 중 하나입니다.

캡처 및 렌더링 스트림 각각에 대해 네 가지 변형이 있으며, 프로세스가 특정 역할에 대해 다음 중 하나를 수행할 수 있는지 결정합니다:

* 모든 카테고리의 오디오를 캡처 또는 렌더링
* 특정 카테고리의 오디오를 캡처 또는 렌더링
* 특정 카테고리의 오디오를 특정 엔드포인트로 캡처 또는 렌더링.\
  엔드포인트는 `MMDevice` ID(`IMMDevice::GetId()`를 사용하여 얻음)나 `SWD` ID(`Windows.Devices.Enumeration` 또는 `Windows.Media.Devices.MediaDevice`를 사용하여 얻음)로 지정할 수 있습니다.
* 특정 카테고리의 오디오를 기본 엔드포인트로 캡처 또는 렌더링

다음 시나리오를 고려해 보세요. 게임이 정책상 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. 
} 
```

## Requirements

**Header:** Audiostatemonitorapi.h

**Library:** Windows.Media.MediaControl.lib

**지원 플랫폼:** Windows, XBOX One 제품군 콘솔 및 XBOX Series 콘솔

## See also

[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 interface](/ko/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor.md)
- [AudioStateMonitor](/ko/reference/audio/audiostatemonitor/audiostatemonitor_members.md)
- [CreateRenderAudioStateMonitorForCategory](/ko/reference/audio/audiostatemonitor/functions/createrenderaudiostatemonitorforcategory.md)
- [CreateRenderAudioStateMonitorForCategoryAndDeviceId](/ko/reference/audio/audiostatemonitor/functions/createrenderaudiostatemonitorforcategoryanddeviceid.md)
- [CreateRenderAudioStateMonitorForCategoryAndDeviceRole](/ko/reference/audio/audiostatemonitor/functions/createrenderaudiostatemonitorforcategoryanddevicerole.md)
