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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
//
// DelayAPO.h -- Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description:
//
// Declaration of the CDelayAPO class.
//
#pragma once
#include <audioenginebaseapo.h>
#include <BaseAudioProcessingObject.h>
#include <DelayAPOInterface.h>
#include <DelayAPODll.h>
#include <commonmacros.h>
#include <devicetopology.h>
_Analysis_mode_(_Analysis_code_type_user_driver_)
#define PK_EQUAL(x, y) ((x.fmtid == y.fmtid) && (x.pid == y.pid))
//
// Define a GUID identifying the type of this APO's custom effect.
//
// APOs generally should not define new GUIDs for types of effects and instead
// should use predefined effect types. Only define a new GUID if the effect is
// truly very different from all predefined types of effects.
//
// {29FBFBB5-9002-4ABC-DCBC-DD45462478C8}
DEFINE_GUID(DelayEffectId, 0x29FBFBB5, 0x9002, 0x4ABC, 0xDC, 0xBC, 0xDD, 0x45, 0x46, 0x24, 0x78, 0xC8);
// 1000 ms of delay
#define HNS_DELAY HNS_PER_SECOND
#define FRAMES_FROM_HNS(hns) (ULONG)(1.0 * hns / HNS_PER_SECOND * GetFramesPerSecond() + 0.5)
LONG GetCurrentEffectsSetting(IPropertyStore* properties, PROPERTYKEY pkeyEnable, GUID processingMode);
#pragma AVRT_VTABLES_BEGIN
// Delay APO class - MFX
class CDelayAPOMFX :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CDelayAPOMFX, &CLSID_DelayAPOMFX>,
public CBaseAudioProcessingObject,
public IMMNotificationClient,
public IAudioSystemEffects2,
// IAudioSystemEffectsCustomFormats may be optionally supported
// by APOs that attach directly to the connector in the DEFAULT mode streaming graph
public IAudioSystemEffectsCustomFormats,
public IDelayAPOMFX
{
public:
// constructor
CDelayAPOMFX()
: CBaseAudioProcessingObject(sm_RegProperties)
, m_hEffectsChangedEvent(NULL)
, m_AudioProcessingMode(AUDIO_SIGNALPROCESSINGMODE_DEFAULT)
, m_fEnableDelayMFX(FALSE)
, m_nDelayFrames(0)
, m_iDelayIndex(0)
{
m_pf32Coefficients = NULL;
}
virtual ~CDelayAPOMFX(); // destructor
DECLARE_REGISTRY_RESOURCEID(IDR_DELAYAPOMFX)
BEGIN_COM_MAP(CDelayAPOMFX)
COM_INTERFACE_ENTRY(IDelayAPOMFX)
COM_INTERFACE_ENTRY(IAudioSystemEffects)
COM_INTERFACE_ENTRY(IAudioSystemEffects2)
// IAudioSystemEffectsCustomFormats may be optionally supported
// by APOs that attach directly to the connector in the DEFAULT mode streaming graph
COM_INTERFACE_ENTRY(IAudioSystemEffectsCustomFormats)
COM_INTERFACE_ENTRY(IMMNotificationClient)
COM_INTERFACE_ENTRY(IAudioProcessingObjectRT)
COM_INTERFACE_ENTRY(IAudioProcessingObject)
COM_INTERFACE_ENTRY(IAudioProcessingObjectConfiguration)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
public:
STDMETHOD_(void, APOProcess)(UINT32 u32NumInputConnections,
APO_CONNECTION_PROPERTY** ppInputConnections, UINT32 u32NumOutputConnections,
APO_CONNECTION_PROPERTY** ppOutputConnections);
STDMETHOD(GetLatency)(HNSTIME* pTime);
STDMETHOD(LockForProcess)(UINT32 u32NumInputConnections,
APO_CONNECTION_DESCRIPTOR** ppInputConnections,
UINT32 u32NumOutputConnections, APO_CONNECTION_DESCRIPTOR** ppOutputConnections);
STDMETHOD(Initialize)(UINT32 cbDataSize, BYTE* pbyData);
// IAudioSystemEffects2
STDMETHOD(GetEffectsList)(_Outptr_result_buffer_maybenull_(*pcEffects) LPGUID *ppEffectsIds, _Out_ UINT *pcEffects, _In_ HANDLE Event);
virtual HRESULT ValidateAndCacheConnectionInfo(
UINT32 u32NumInputConnections,
APO_CONNECTION_DESCRIPTOR** ppInputConnections,
UINT32 u32NumOutputConnections,
APO_CONNECTION_DESCRIPTOR** ppOutputConnections);
// IMMNotificationClient
STDMETHODIMP OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
{
UNREFERENCED_PARAMETER(pwstrDeviceId);
UNREFERENCED_PARAMETER(dwNewState);
return S_OK;
}
STDMETHODIMP OnDeviceAdded(LPCWSTR pwstrDeviceId)
{
UNREFERENCED_PARAMETER(pwstrDeviceId);
return S_OK;
}
STDMETHODIMP OnDeviceRemoved(LPCWSTR pwstrDeviceId)
{
UNREFERENCED_PARAMETER(pwstrDeviceId);
return S_OK;
}
STDMETHODIMP OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId)
{
UNREFERENCED_PARAMETER(flow);
UNREFERENCED_PARAMETER(role);
UNREFERENCED_PARAMETER(pwstrDefaultDeviceId);
return S_OK;
}
STDMETHODIMP OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key);
// IAudioSystemEffectsCustomFormats
// This interface may be optionally supported by APOs that attach directly to the connector in the DEFAULT mode streaming graph
STDMETHODIMP GetFormatCount(UINT* pcFormats);
STDMETHODIMP GetFormat(UINT nFormat, IAudioMediaType** ppFormat);
STDMETHODIMP GetFormatRepresentation(UINT nFormat, _Outptr_ LPWSTR* ppwstrFormatRep);
// IAudioProcessingObject
STDMETHODIMP IsOutputFormatSupported(IAudioMediaType *pOppositeFormat, IAudioMediaType *pRequestedOutputFormat, IAudioMediaType **ppSupportedOutputFormat);
STDMETHODIMP CheckCustomFormats(IAudioMediaType *pRequestedFormat);
public:
LONG m_fEnableDelayMFX;
GUID m_AudioProcessingMode;
CComPtr<IPropertyStore> m_spAPOSystemEffectsProperties;
CComPtr<IMMDeviceEnumerator> m_spEnumerator;
static const CRegAPOProperties<1> sm_RegProperties; // registration properties
// Locked memory
FLOAT32 *m_pf32Coefficients;
CComHeapPtr<FLOAT32> m_pf32DelayBuffer;
UINT32 m_nDelayFrames;
UINT32 m_iDelayIndex;
private:
CCriticalSection m_EffectsLock;
HANDLE m_hEffectsChangedEvent;
HRESULT ProprietaryCommunicationWithDriver(APOInitSystemEffects2 *_pAPOSysFxInit2);
};
#pragma AVRT_VTABLES_END
#pragma AVRT_VTABLES_BEGIN
// Delay APO class - SFX
class CDelayAPOSFX :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CDelayAPOSFX, &CLSID_DelayAPOSFX>,
public CBaseAudioProcessingObject,
public IMMNotificationClient,
public IAudioSystemEffects2,
public IDelayAPOSFX
{
public:
// constructor
CDelayAPOSFX()
: CBaseAudioProcessingObject(sm_RegProperties)
, m_hEffectsChangedEvent(NULL)
, m_AudioProcessingMode(AUDIO_SIGNALPROCESSINGMODE_DEFAULT)
, m_fEnableDelaySFX(FALSE)
, m_nDelayFrames(0)
, m_iDelayIndex(0)
{
}
virtual ~CDelayAPOSFX(); // destructor
DECLARE_REGISTRY_RESOURCEID(IDR_DELAYAPOSFX)
BEGIN_COM_MAP(CDelayAPOSFX)
COM_INTERFACE_ENTRY(IDelayAPOSFX)
COM_INTERFACE_ENTRY(IAudioSystemEffects)
COM_INTERFACE_ENTRY(IAudioSystemEffects2)
COM_INTERFACE_ENTRY(IMMNotificationClient)
COM_INTERFACE_ENTRY(IAudioProcessingObjectRT)
COM_INTERFACE_ENTRY(IAudioProcessingObject)
COM_INTERFACE_ENTRY(IAudioProcessingObjectConfiguration)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
public:
STDMETHOD_(void, APOProcess)(UINT32 u32NumInputConnections,
APO_CONNECTION_PROPERTY** ppInputConnections, UINT32 u32NumOutputConnections,
APO_CONNECTION_PROPERTY** ppOutputConnections);
STDMETHOD(GetLatency)(HNSTIME* pTime);
STDMETHOD(LockForProcess)(UINT32 u32NumInputConnections,
APO_CONNECTION_DESCRIPTOR** ppInputConnections,
UINT32 u32NumOutputConnections, APO_CONNECTION_DESCRIPTOR** ppOutputConnections);
STDMETHOD(Initialize)(UINT32 cbDataSize, BYTE* pbyData);
// IAudioSystemEffects2
STDMETHOD(GetEffectsList)(_Outptr_result_buffer_maybenull_(*pcEffects) LPGUID *ppEffectsIds, _Out_ UINT *pcEffects, _In_ HANDLE Event);
// IMMNotificationClient
STDMETHODIMP OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
{
UNREFERENCED_PARAMETER(pwstrDeviceId);
UNREFERENCED_PARAMETER(dwNewState);
return S_OK;
}
STDMETHODIMP OnDeviceAdded(LPCWSTR pwstrDeviceId)
{
UNREFERENCED_PARAMETER(pwstrDeviceId);
return S_OK;
}
STDMETHODIMP OnDeviceRemoved(LPCWSTR pwstrDeviceId)
{
UNREFERENCED_PARAMETER(pwstrDeviceId);
return S_OK;
}
STDMETHODIMP OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId)
{
UNREFERENCED_PARAMETER(flow);
UNREFERENCED_PARAMETER(role);
UNREFERENCED_PARAMETER(pwstrDefaultDeviceId);
return S_OK;
}
STDMETHODIMP OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key);
public:
LONG m_fEnableDelaySFX;
GUID m_AudioProcessingMode;
CComPtr<IPropertyStore> m_spAPOSystemEffectsProperties;
CComPtr<IMMDeviceEnumerator> m_spEnumerator;
static const CRegAPOProperties<1> sm_RegProperties; // registration properties
CCriticalSection m_EffectsLock;
HANDLE m_hEffectsChangedEvent;
CComHeapPtr<FLOAT32> m_pf32DelayBuffer;
UINT32 m_nDelayFrames;
UINT32 m_iDelayIndex;
};
#pragma AVRT_VTABLES_END
OBJECT_ENTRY_AUTO(__uuidof(DelayAPOMFX), CDelayAPOMFX)
OBJECT_ENTRY_AUTO(__uuidof(DelayAPOSFX), CDelayAPOSFX)
//
// Declaration of the ProcessDelay routine.
//
void ProcessDelay(
_Out_writes_(u32ValidFrameCount * u32SamplesPerFrame)
FLOAT32 *pf32OutputFrames,
_In_reads_(u32ValidFrameCount * u32SamplesPerFrame)
const FLOAT32 *pf32InputFrames,
UINT32 u32ValidFrameCount,
UINT32 u32SamplesPerFrame,
_Inout_updates_(u32DelayFrames * u32SamplesPerFrame)
FLOAT32 *pf32DelayBuffer,
UINT32 u32DelayFrames,
_Inout_
UINT32 *pu32DelayIndex );
//
// Convenience methods
//
void WriteSilence(
_Out_writes_(u32FrameCount * u32SamplesPerFrame)
FLOAT32 *pf32Frames,
UINT32 u32FrameCount,
UINT32 u32SamplesPerFrame );
void CopyFrames(
_Out_writes_(u32FrameCount * u32SamplesPerFrame)
FLOAT32 *pf32OutFrames,
_In_reads_(u32FrameCount * u32SamplesPerFrame)
const FLOAT32 *pf32InFrames,
UINT32 u32FrameCount,
UINT32 u32SamplesPerFrame );
|