1919*/
2020
2121#pragma once
22+ #pragma warning(disable : 4996)
2223
2324#include < vector>
2425using namespace std ;
@@ -29,13 +30,59 @@ struct IMMDevice;
2930struct IAudioClient ;
3031struct IAudioRenderClient ;
3132
33+ #define SAFE_RELEASE (punk ) \
34+ if ((punk) != NULL ) \
35+ { (punk)->Release (); (punk) = NULL ; }
36+
37+ #include < Mmdeviceapi.h>
3238#include " COMBaseClasses.h"
3339#include " asiosys.h"
3440#include " iasiodrv.h"
3541
3642extern CLSID CLSID_ASIO2WASAPI_DRIVER;
3743const char * const szDescription = " ASIO2WASAPI" ;
3844
45+ class ASIO2WASAPI ;
46+
47+ class CMMNotificationClient : public IMMNotificationClient
48+ {
49+ LONG _cRef;
50+ IMMDeviceEnumerator* _pEnumerator;
51+ ASIO2WASAPI* _asio2Wasapi;
52+
53+ public:
54+ CMMNotificationClient (ASIO2WASAPI* asio2Wasapi);
55+
56+ ~CMMNotificationClient ();
57+
58+ // IUnknown methods -- AddRef, Release, and QueryInterface
59+
60+ ULONG STDMETHODCALLTYPE AddRef ();
61+
62+ ULONG STDMETHODCALLTYPE Release ();
63+
64+ HRESULT STDMETHODCALLTYPE QueryInterface (
65+ REFIID riid, VOID** ppvInterface);
66+
67+ // Callback methods for device-event notifications.
68+
69+ HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged (
70+ EDataFlow flow, ERole role,
71+ LPCWSTR pwstrDeviceId);
72+
73+ HRESULT STDMETHODCALLTYPE OnDeviceAdded (LPCWSTR pwstrDeviceId);;
74+
75+ HRESULT STDMETHODCALLTYPE OnDeviceRemoved (LPCWSTR pwstrDeviceId);
76+
77+ HRESULT STDMETHODCALLTYPE OnDeviceStateChanged (
78+ LPCWSTR pwstrDeviceId,
79+ DWORD dwNewState);
80+
81+ HRESULT STDMETHODCALLTYPE OnPropertyValueChanged (
82+ LPCWSTR pwstrDeviceId,
83+ const PROPERTYKEY key);
84+ };
85+
3986
4087class ASIO2WASAPI : public IASIO , public CUnknown
4188{
@@ -58,11 +105,15 @@ class ASIO2WASAPI : public IASIO, public CUnknown
58105 // IUnknown
59106 virtual HRESULT STDMETHODCALLTYPE NonDelegatingQueryInterface (REFIID riid,void **ppvObject);
60107
108+
109+
61110 ASIOBool init (void * sysRef);
62111 void getDriverName (char *name); // max 32 bytes incl. terminating zero
63112 long getDriverVersion ();
64113 void getErrorMessage (char *string); // max 128 bytes incl. terminating zero
65114
115+ ASIOCallbacks* getCallbacks () { return m_callbacks; }
116+
66117 ASIOError start ();
67118 ASIOError stop ();
68119
@@ -87,24 +138,30 @@ class ASIO2WASAPI : public IASIO, public CUnknown
87138 ASIOError future (long selector, void *opt);
88139 ASIOError outputReady ();
89140
141+ // / WASAPI specific
142+ bool getUseDefaultDevice () { return m_useDefaultDevice; };
143+ void setUseDefaultDevice (bool value) { m_useDefaultDevice = value; };
90144private:
145+ // for default device changed notification
146+ CMMNotificationClient* pNotificationClient;
91147
92148 static DWORD WINAPI PlayThreadProc (LPVOID pThis);
93149 static BOOL CALLBACK ControlPanelProc (HWND hwndDlg,
94150 UINT message, WPARAM wParam, LPARAM lParam);
95151 HRESULT LoadData (IAudioRenderClient * pRenderClient);
96152 long refTimeToBufferSize (LONGLONG time) const ;
97- LONGLONG bufferSizeToRefTime (long bufferSize) const ;
98- void readFromRegistry ();
153+ LONGLONG bufferSizeToRefTime (long bufferSize) const ;
99154 void writeToRegistry ();
100- ASIOSampleType getASIOSampleType () const ;
155+ void readFromRegistry () ;
101156 void shutdown ();
157+ ASIOSampleType getASIOSampleType () const ;
102158 void clearState ();
103159 void setMostReliableFormat ();
104160
105161 // fields valid before initialization
106162 int m_nChannels;
107163 int m_nSampleRate;
164+ int m_nBufferSize;
108165 char m_errorMessage[128 ];
109166 vector<wchar_t > m_deviceId;
110167
@@ -115,10 +172,13 @@ class ASIO2WASAPI : public IASIO, public CUnknown
115172 WAVEFORMATEXTENSIBLE m_waveFormat;
116173 int m_bufferSize; // in audio frames
117174 HWND m_hAppWindowHandle;
175+
176+ // WASAPI specific
177+ bool m_useDefaultDevice;
118178
119179 // fields filled by createBuffers()/cleaned by disposeBuffers()
120180 vector< vector<BYTE> > m_buffers[2 ];
121- ASIOCallbacks * m_callbacks;
181+ ASIOCallbacks * m_callbacks;
122182
123183 // fields filled by start()/cleaned by stop()
124184 HANDLE m_hPlayThreadIsRunningEvent;
0 commit comments