-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathWASAPIRenderer.h
67 lines (53 loc) · 2.24 KB
/
WASAPIRenderer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//--------------------------------------------------------------------------------------
// WASAPIRenderer.h
//
// Functions to assist in rendering audio in WASAPI
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include <Windows.h>
#include <wrl\implements.h>
#include <mfapi.h>
#include <AudioClient.h>
#include <mmdeviceapi.h>
#include "DeviceState.h"
#include "Common.h"
#include "CBuffer.h"
#include <mutex>
#pragma once
// Primary WASAPI Renderering Class
class WASAPIRenderer :
public Microsoft::WRL::RuntimeClass< Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::ClassicCom >, Microsoft::WRL::FtmBase, IActivateAudioInterfaceCompletionHandler >
{
public:
WASAPIRenderer();
HRESULT InitializeAudioDeviceAsync();
HRESULT StartPlaybackAsync(CBuffer* bufferToUse);
HRESULT StopPlaybackAsync();
DeviceStateChangedEvent^ GetDeviceStateEvent() { return m_deviceStateChanged; };
WAVEFORMATEX* GetMixFormat() { return m_mixFormat; }
METHODASYNCCALLBACK( WASAPIRenderer, StartPlayback, OnStartPlayback );
METHODASYNCCALLBACK( WASAPIRenderer, StopPlayback, OnStopPlayback );
METHODASYNCCALLBACK( WASAPIRenderer, SampleReady, OnSampleReady );
// IActivateAudioInterfaceCompletionHandler
STDMETHOD(ActivateCompleted)( IActivateAudioInterfaceAsyncOperation *operation );
private:
~WASAPIRenderer();
HRESULT OnStartPlayback( IMFAsyncResult* );
HRESULT OnStopPlayback( IMFAsyncResult* );
HRESULT OnSampleReady( IMFAsyncResult* );
HRESULT ConfigureDeviceInternal();
HRESULT OnAudioSampleRequested( bool isSilence = false );
private:
uint32_t m_bufferFrames;
HANDLE m_sampleReadyEvent;
MFWORKITEM_KEY m_sampleReadyKey;
std::mutex m_mutex;
CBuffer* m_buffer;
WAVEFORMATEX* m_mixFormat;
Microsoft::WRL::ComPtr<IAudioClient2> m_audioClient;
Microsoft::WRL::ComPtr<IAudioRenderClient> m_audioRenderClient;
Microsoft::WRL::ComPtr<IMFAsyncResult> m_sampleReadyAsyncResult;
DeviceStateChangedEvent^ m_deviceStateChanged;
};