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

# IAudioStateMonitor::GetSoundLevel method

> IAudioStateMonitor::GetSoundLevel method

# IAudioStateMonitor::GetSoundLevel method

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

[IAudioStateMonitor](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor)와 연결된 스트림의 현재 사운드 레벨을 가져옵니다.

## Syntax

```cpp theme={null}
AudioStateMonitorSoundLevel GetSoundLevel();
```

### Parameters

이 메서드에는 매개변수가 없습니다.

### Return value

[IAudioStateMonitor](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor)와 연결된 스트림의 현재 사운드 레벨을 나타내는 [AudioStateMonitorSoundLevel](/reference/audio/audiostatemonitor/enums/audiostatemonitorsoundlevel) 열거형의 값입니다.

## Remarks

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

[AudioStateMonitorSoundLevel](/reference/audio/audiostatemonitor/enums/audiostatemonitorsoundlevel) 열거형의 값입니다. [IAudioStateMonitor](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor)와 연결된 스트림의 현재 사운드 레벨을 나타냅니다.

## Requirements

**Header:** Audiostatemonitorapi.h

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

## See also

[IAudioStateMonitor](/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor)

[WASAPI 소개](https://learn.microsoft.com/windows/desktop/CoreAudio/wasapi)


## Related topics

- [AudioStateMonitorSoundLevel enumeration](/ko/reference/audio/audiostatemonitor/enums/audiostatemonitorsoundlevel.md)
- [IAudioStateMonitor::RegisterCallback method](/ko/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-registercallback.md)
- [IAudioStateMonitor::UnregisterCallback method](/ko/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor-unregistercallback.md)
- [IAudioStateMonitor interface](/ko/reference/audio/audiostatemonitor/interfaces/iaudiostatemonitor.md)
- [CreateCaptureAudioStateMonitor](/ko/reference/audio/audiostatemonitor/functions/createcaptureaudiostatemonitor.md)
