msvcirt: Add implementation of streambuf::sputbackc.
[wine.git] / dlls / xaudio2_7 / xaudio_dll.c
blobb13436c01f2ec066094389e640472b0d56ca2705
1 /*
2 * Copyright (c) 2015 Mark Harmstone
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
27 #include "ole2.h"
28 #include "rpcproxy.h"
30 #include "wine/debug.h"
31 #include <propsys.h>
32 #include "initguid.h"
34 #include "xaudio2.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(xaudio2);
38 static HINSTANCE instance;
40 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD reason, void *pReserved)
42 TRACE("(%p, %d, %p)\n", hinstDLL, reason, pReserved);
44 switch (reason)
46 case DLL_WINE_PREATTACH:
47 return FALSE; /* prefer native version */
48 case DLL_PROCESS_ATTACH:
49 instance = hinstDLL;
50 DisableThreadLibraryCalls( hinstDLL );
51 break;
53 return TRUE;
56 HRESULT WINAPI DllCanUnloadNow(void)
58 return S_FALSE;
61 HRESULT WINAPI DllRegisterServer(void)
63 TRACE("\n");
64 return __wine_register_resources(instance);
67 HRESULT WINAPI DllUnregisterServer(void)
69 TRACE("\n");
70 return __wine_unregister_resources(instance);
73 typedef struct {
74 IXAudio27 IXAudio27_iface;
75 IXAudio2 IXAudio2_iface;
76 LONG ref;
78 DWORD version;
79 } IXAudio2Impl;
81 static inline IXAudio2Impl *impl_from_IXAudio2(IXAudio2 *iface)
83 return CONTAINING_RECORD(iface, IXAudio2Impl, IXAudio2_iface);
86 static inline IXAudio2Impl *impl_from_IXAudio27(IXAudio27 *iface)
88 return CONTAINING_RECORD(iface, IXAudio2Impl, IXAudio27_iface);
91 static HRESULT WINAPI IXAudio2Impl_QueryInterface(IXAudio2 *iface, REFIID riid,
92 void **ppvObject)
94 IXAudio2Impl *This = impl_from_IXAudio2(iface);
96 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
98 if(IsEqualGUID(riid, &IID_IUnknown) ||
99 IsEqualGUID(riid, &IID_IXAudio2))
100 *ppvObject = &This->IXAudio2_iface;
101 else if(IsEqualGUID(riid, &IID_IXAudio27))
102 *ppvObject = &This->IXAudio27_iface;
103 else
104 *ppvObject = NULL;
106 if(*ppvObject){
107 IUnknown_AddRef((IUnknown*)*ppvObject);
108 return S_OK;
111 FIXME("(%p)->(%s,%p), not found\n", This,debugstr_guid(riid), ppvObject);
113 return E_NOINTERFACE;
116 static ULONG WINAPI IXAudio2Impl_AddRef(IXAudio2 *iface)
118 IXAudio2Impl *This = impl_from_IXAudio2(iface);
119 ULONG ref = InterlockedIncrement(&This->ref);
120 TRACE("(%p)->(): Refcount now %u\n", This, ref);
121 return ref;
124 static ULONG WINAPI IXAudio2Impl_Release(IXAudio2 *iface)
126 IXAudio2Impl *This = impl_from_IXAudio2(iface);
127 ULONG ref = InterlockedDecrement(&This->ref);
129 TRACE("(%p)->(): Refcount now %u\n", This, ref);
131 if (!ref)
132 HeapFree(GetProcessHeap(), 0, This);
134 return ref;
137 static HRESULT WINAPI IXAudio2Impl_RegisterForCallbacks(IXAudio2 *iface,
138 IXAudio2EngineCallback *pCallback)
140 IXAudio2Impl *This = impl_from_IXAudio2(iface);
142 FIXME("(%p)->(%p): stub!\n", This, pCallback);
144 return E_NOTIMPL;
147 static void WINAPI IXAudio2Impl_UnregisterForCallbacks(IXAudio2 *iface,
148 IXAudio2EngineCallback *pCallback)
150 IXAudio2Impl *This = impl_from_IXAudio2(iface);
152 FIXME("(%p)->(%p): stub!\n", This, pCallback);
155 static HRESULT WINAPI IXAudio2Impl_CreateSourceVoice(IXAudio2 *iface,
156 IXAudio2SourceVoice **ppSourceVoice, const WAVEFORMATEX *pSourceFormat,
157 UINT32 flags, float maxFrequencyRatio,
158 IXAudio2VoiceCallback *pCallback, const XAUDIO2_VOICE_SENDS *pSendList,
159 const XAUDIO2_EFFECT_CHAIN *pEffectChain)
161 IXAudio2Impl *This = impl_from_IXAudio2(iface);
163 FIXME("(%p)->(%p, %p, 0x%x, %f, %p, %p, %p): stub!\n", This, ppSourceVoice,
164 pSourceFormat, flags, maxFrequencyRatio, pCallback, pSendList,
165 pEffectChain);
167 return E_NOTIMPL;
170 static HRESULT WINAPI IXAudio2Impl_CreateSubmixVoice(IXAudio2 *iface,
171 IXAudio2SubmixVoice **ppSubmixVoice, UINT32 inputChannels,
172 UINT32 inputSampleRate, UINT32 flags, UINT32 processingStage,
173 const XAUDIO2_VOICE_SENDS *pSendList,
174 const XAUDIO2_EFFECT_CHAIN *pEffectChain)
176 IXAudio2Impl *This = impl_from_IXAudio2(iface);
178 FIXME("(%p)->(%p, %u, %u, 0x%x, %u, %p, %p): stub!\n", This, ppSubmixVoice,
179 inputChannels, inputSampleRate, flags, processingStage, pSendList,
180 pEffectChain);
182 return E_NOTIMPL;
185 static HRESULT WINAPI IXAudio2Impl_CreateMasteringVoice(IXAudio2 *iface,
186 IXAudio2MasteringVoice **ppMasteringVoice, UINT32 inputChannels,
187 UINT32 inputSampleRate, UINT32 flags, const WCHAR *deviceId,
188 const XAUDIO2_EFFECT_CHAIN *pEffectChain,
189 AUDIO_STREAM_CATEGORY streamCategory)
191 IXAudio2Impl *This = impl_from_IXAudio2(iface);
193 FIXME("(%p)->(%p, %u, %u, 0x%x, %s, %p, 0x%x): stub!\n", This,
194 ppMasteringVoice, inputChannels, inputSampleRate, flags,
195 wine_dbgstr_w(deviceId), pEffectChain, streamCategory);
197 return E_NOTIMPL;
200 static HRESULT WINAPI IXAudio2Impl_StartEngine(IXAudio2 *iface)
202 IXAudio2Impl *This = impl_from_IXAudio2(iface);
204 FIXME("(%p)->(): stub!\n", This);
206 return E_NOTIMPL;
209 static void WINAPI IXAudio2Impl_StopEngine(IXAudio2 *iface)
211 IXAudio2Impl *This = impl_from_IXAudio2(iface);
213 FIXME("(%p)->(): stub!\n", This);
216 static HRESULT WINAPI IXAudio2Impl_CommitChanges(IXAudio2 *iface,
217 UINT32 operationSet)
219 IXAudio2Impl *This = impl_from_IXAudio2(iface);
221 FIXME("(%p)->(0x%x): stub!\n", This, operationSet);
223 return E_NOTIMPL;
226 static void WINAPI IXAudio2Impl_GetPerformanceData(IXAudio2 *iface,
227 XAUDIO2_PERFORMANCE_DATA *pPerfData)
229 IXAudio2Impl *This = impl_from_IXAudio2(iface);
231 FIXME("(%p)->(%p): stub!\n", This, pPerfData);
234 static void WINAPI IXAudio2Impl_SetDebugConfiguration(IXAudio2 *iface,
235 const XAUDIO2_DEBUG_CONFIGURATION *pDebugConfiguration,
236 void *pReserved)
238 IXAudio2Impl *This = impl_from_IXAudio2(iface);
240 FIXME("(%p)->(%p, %p): stub!\n", This, pDebugConfiguration, pReserved);
243 /* XAudio2 2.8 */
244 static const IXAudio2Vtbl XAudio2_Vtbl =
246 IXAudio2Impl_QueryInterface,
247 IXAudio2Impl_AddRef,
248 IXAudio2Impl_Release,
249 IXAudio2Impl_RegisterForCallbacks,
250 IXAudio2Impl_UnregisterForCallbacks,
251 IXAudio2Impl_CreateSourceVoice,
252 IXAudio2Impl_CreateSubmixVoice,
253 IXAudio2Impl_CreateMasteringVoice,
254 IXAudio2Impl_StartEngine,
255 IXAudio2Impl_StopEngine,
256 IXAudio2Impl_CommitChanges,
257 IXAudio2Impl_GetPerformanceData,
258 IXAudio2Impl_SetDebugConfiguration
261 static HRESULT WINAPI XA27_QueryInterface(IXAudio27 *iface, REFIID riid,
262 void **ppvObject)
264 IXAudio2Impl *This = impl_from_IXAudio27(iface);
265 return IXAudio2Impl_QueryInterface(&This->IXAudio2_iface, riid, ppvObject);
268 static ULONG WINAPI XA27_AddRef(IXAudio27 *iface)
270 IXAudio2Impl *This = impl_from_IXAudio27(iface);
271 return IXAudio2Impl_AddRef(&This->IXAudio2_iface);
274 static ULONG WINAPI XA27_Release(IXAudio27 *iface)
276 IXAudio2Impl *This = impl_from_IXAudio27(iface);
277 return IXAudio2Impl_Release(&This->IXAudio2_iface);
280 static HRESULT WINAPI XA27_GetDeviceCount(IXAudio27 *iface, UINT32 *pCount)
282 IXAudio2Impl *This = impl_from_IXAudio27(iface);
283 TRACE("(%p)->(%p)\n", This, pCount);
284 return E_NOTIMPL;
287 static HRESULT WINAPI XA27_GetDeviceDetails(IXAudio27 *iface, UINT32 index,
288 XAUDIO2_DEVICE_DETAILS *pDeviceDetails)
290 IXAudio2Impl *This = impl_from_IXAudio27(iface);
291 TRACE("(%p)->(%u, %p)\n", This, index, pDeviceDetails);
292 return E_NOTIMPL;
295 static HRESULT WINAPI XA27_Initialize(IXAudio27 *iface, UINT32 flags,
296 XAUDIO2_PROCESSOR processor)
298 IXAudio2Impl *This = impl_from_IXAudio27(iface);
299 TRACE("(%p)->(0x%x, 0x%x)\n", This, flags, processor);
300 return E_NOTIMPL;
303 static HRESULT WINAPI XA27_RegisterForCallbacks(IXAudio27 *iface,
304 IXAudio2EngineCallback *pCallback)
306 IXAudio2Impl *This = impl_from_IXAudio27(iface);
307 return IXAudio2Impl_RegisterForCallbacks(&This->IXAudio2_iface, pCallback);
310 static void WINAPI XA27_UnregisterForCallbacks(IXAudio27 *iface,
311 IXAudio2EngineCallback *pCallback)
313 IXAudio2Impl *This = impl_from_IXAudio27(iface);
314 IXAudio2Impl_UnregisterForCallbacks(&This->IXAudio2_iface, pCallback);
317 static HRESULT WINAPI XA27_CreateSourceVoice(IXAudio27 *iface,
318 IXAudio2SourceVoice **ppSourceVoice, const WAVEFORMATEX *pSourceFormat,
319 UINT32 flags, float maxFrequencyRatio,
320 IXAudio2VoiceCallback *pCallback, const XAUDIO2_VOICE_SENDS *pSendList,
321 const XAUDIO2_EFFECT_CHAIN *pEffectChain)
323 IXAudio2Impl *This = impl_from_IXAudio27(iface);
324 return IXAudio2Impl_CreateSourceVoice(&This->IXAudio2_iface, ppSourceVoice,
325 pSourceFormat, flags, maxFrequencyRatio, pCallback, pSendList,
326 pEffectChain);
329 static HRESULT WINAPI XA27_CreateSubmixVoice(IXAudio27 *iface,
330 IXAudio2SubmixVoice **ppSubmixVoice, UINT32 inputChannels,
331 UINT32 inputSampleRate, UINT32 flags, UINT32 processingStage,
332 const XAUDIO2_VOICE_SENDS *pSendList,
333 const XAUDIO2_EFFECT_CHAIN *pEffectChain)
335 IXAudio2Impl *This = impl_from_IXAudio27(iface);
336 return IXAudio2Impl_CreateSubmixVoice(&This->IXAudio2_iface, ppSubmixVoice,
337 inputChannels, inputSampleRate, flags, processingStage, pSendList,
338 pEffectChain);
341 static HRESULT WINAPI XA27_CreateMasteringVoice(IXAudio27 *iface,
342 IXAudio2MasteringVoice **ppMasteringVoice, UINT32 inputChannels,
343 UINT32 inputSampleRate, UINT32 flags, UINT32 deviceIndex,
344 const XAUDIO2_EFFECT_CHAIN *pEffectChain)
346 IXAudio2Impl *This = impl_from_IXAudio27(iface);
347 TRACE("(%p)->(%p, %u, %u, 0x%x, %u, %p)\n", This, ppMasteringVoice,
348 inputChannels, inputSampleRate, flags, deviceIndex,
349 pEffectChain);
350 /* TODO: Convert DeviceIndex to DeviceId */
351 return IXAudio2Impl_CreateMasteringVoice(&This->IXAudio2_iface,
352 ppMasteringVoice, inputChannels, inputSampleRate, flags, 0,
353 pEffectChain, AudioCategory_GameEffects);
356 static HRESULT WINAPI XA27_StartEngine(IXAudio27 *iface)
358 IXAudio2Impl *This = impl_from_IXAudio27(iface);
359 return IXAudio2Impl_StartEngine(&This->IXAudio2_iface);
362 static void WINAPI XA27_StopEngine(IXAudio27 *iface)
364 IXAudio2Impl *This = impl_from_IXAudio27(iface);
365 return IXAudio2Impl_StopEngine(&This->IXAudio2_iface);
368 static HRESULT WINAPI XA27_CommitChanges(IXAudio27 *iface, UINT32 operationSet)
370 IXAudio2Impl *This = impl_from_IXAudio27(iface);
371 return IXAudio2Impl_CommitChanges(&This->IXAudio2_iface, operationSet);
374 static void WINAPI XA27_GetPerformanceData(IXAudio27 *iface,
375 XAUDIO2_PERFORMANCE_DATA *pPerfData)
377 IXAudio2Impl *This = impl_from_IXAudio27(iface);
378 return IXAudio2Impl_GetPerformanceData(&This->IXAudio2_iface, pPerfData);
381 static void WINAPI XA27_SetDebugConfiguration(IXAudio27 *iface,
382 const XAUDIO2_DEBUG_CONFIGURATION *pDebugConfiguration,
383 void *pReserved)
385 IXAudio2Impl *This = impl_from_IXAudio27(iface);
386 return IXAudio2Impl_SetDebugConfiguration(&This->IXAudio2_iface,
387 pDebugConfiguration, pReserved);
390 static const IXAudio27Vtbl XAudio27_Vtbl = {
391 XA27_QueryInterface,
392 XA27_AddRef,
393 XA27_Release,
394 XA27_GetDeviceCount,
395 XA27_GetDeviceDetails,
396 XA27_Initialize,
397 XA27_RegisterForCallbacks,
398 XA27_UnregisterForCallbacks,
399 XA27_CreateSourceVoice,
400 XA27_CreateSubmixVoice,
401 XA27_CreateMasteringVoice,
402 XA27_StartEngine,
403 XA27_StopEngine,
404 XA27_CommitChanges,
405 XA27_GetPerformanceData,
406 XA27_SetDebugConfiguration
409 static HRESULT WINAPI XAudio2CF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
411 if(IsEqualGUID(riid, &IID_IUnknown)
412 || IsEqualGUID(riid, &IID_IClassFactory))
414 IClassFactory_AddRef(iface);
415 *ppobj = iface;
416 return S_OK;
419 *ppobj = NULL;
420 WARN("(%p)->(%s, %p): interface not found\n", iface, debugstr_guid(riid), ppobj);
421 return E_NOINTERFACE;
424 static ULONG WINAPI XAudio2CF_AddRef(IClassFactory *iface)
426 return 2;
429 static ULONG WINAPI XAudio2CF_Release(IClassFactory *iface)
431 return 1;
434 static HRESULT WINAPI XAudio2CF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
435 REFIID riid, void **ppobj)
437 HRESULT hr;
438 IXAudio2Impl *object;
440 TRACE("(static)->(%p,%s,%p)\n", pOuter, debugstr_guid(riid), ppobj);
442 *ppobj = NULL;
444 if(pOuter)
445 return CLASS_E_NOAGGREGATION;
447 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
448 if(!object)
449 return E_OUTOFMEMORY;
451 object->IXAudio27_iface.lpVtbl = &XAudio27_Vtbl;
452 object->IXAudio2_iface.lpVtbl = &XAudio2_Vtbl;
454 if(IsEqualGUID(riid, &IID_IXAudio27))
455 object->version = 27;
456 else
457 object->version = 28;
459 hr = IXAudio2_QueryInterface(&object->IXAudio2_iface, riid, ppobj);
460 if(FAILED(hr))
461 HeapFree(GetProcessHeap(), 0, object);
462 return hr;
465 static HRESULT WINAPI XAudio2CF_LockServer(IClassFactory *iface, BOOL dolock)
467 FIXME("(static)->(%d): stub!\n", dolock);
468 return S_OK;
471 static const IClassFactoryVtbl XAudio2CF_Vtbl =
473 XAudio2CF_QueryInterface,
474 XAudio2CF_AddRef,
475 XAudio2CF_Release,
476 XAudio2CF_CreateInstance,
477 XAudio2CF_LockServer
480 static IClassFactory xaudio2_cf = { &XAudio2CF_Vtbl };
482 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
484 IClassFactory *factory = NULL;
486 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
488 if(IsEqualGUID(rclsid, &CLSID_XAudio2)) {
489 factory = &xaudio2_cf;
491 if(!factory) return CLASS_E_CLASSNOTAVAILABLE;
493 return IClassFactory_QueryInterface(factory, riid, ppv);