Table of Contents

Target Platform(s):
Wwise SDK 2019.2.3
AkWinSoundEngine.h
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
26 *******************************************************************************/
27 
28 // AkWinSoundEngine.h
29 
30 /// \file
31 /// Main Sound Engine interface, specific WIN32.
32 
33 #ifndef _AK_WIN_SOUND_ENGINE_H_
34 #define _AK_WIN_SOUND_ENGINE_H_
35 
36 #include <AK/SoundEngine/Common/AkTypes.h>
37 #include <AK/Tools/Common/AkPlatformFuncs.h>
38 
39 ///< API used for audio output
40 ///< Use with AkPlatformInitSettings to select the API used for audio output.
41 ///< Use AkAPI_Default, it will select the more appropriate API depending on the computer's capabilities. Other values should be used for testing purposes.
42 ///< \sa AK::SoundEngine::Init
43 typedef enum AkAudioAPIWindows
44 {
45  AkAPI_Wasapi = 1 << 0, ///< Use Wasapi
46  AkAPI_XAudio2 = 1 << 1, ///< Use XAudio2 (this is the preferred API on Windows)
47  AkAPI_DirectSound = 1 << 2, ///< Use DirectSound
48  AkAPI_Default = AkAPI_Wasapi | AkAPI_XAudio2 | AkAPI_DirectSound, ///< Default value, will select the more appropriate API (XAudio2 is the default)
49 } AkAudioAPI;
50 
51 struct IXAudio2;
52 
53 /// Platform specific initialization settings
54 /// \sa AK::SoundEngine::Init
55 /// \sa AK::SoundEngine::GetDefaultPlatformInitSettings
56 
58 {
59  // Direct sound.
60  HWND hWnd; ///< Handle to the window associated to the audio.
61  ///< Each game must specify the HWND that will be passed to DirectSound initialization.
62  ///< The value returned by GetDefaultPlatformInitSettings is the foreground HWND at
63  ///< the moment of the initialization of the sound engine and may not be the correct one for your game.
64  ///< It is required that each game provides the correct HWND to be used.
65 
66 
67  // Threading model.
68  AkThreadProperties threadLEngine; ///< Lower engine threading properties
69  AkThreadProperties threadOutputMgr; ///< Ouput thread threading properties
70  AkThreadProperties threadBankManager; ///< Bank manager threading properties (its default priority is AK_THREAD_PRIORITY_NORMAL)
71  AkThreadProperties threadMonitor; ///< Monitor threading properties (its default priority is AK_THREAD_PRIORITY_ABOVENORMAL). This parameter is not used in Release build.
72 
73  // Voices.
74  AkUInt16 uNumRefillsInVoice; ///< Number of refill buffers in voice buffer. 2 == double-buffered, defaults to 4.
75 
76  AkUInt32 uSampleRate; ///< Sampling Rate. Default is 48000 Hz. Use 24000hz for low quality. Any positive reasonable sample rate is supported. However be careful setting a custom value. Using an odd or really low sample rate may result in malfunctionning sound engine.
77 
78 
79  AkAudioAPI eAudioAPI; ///< Main audio API to use. Leave to AkAPI_Default for the default sink (default value).
80  ///< If a valid audioDeviceShareset plug-in is provided, the AkAudioAPI will be Ignored.
81  ///< \ref AkAudioAPI
82 
83  bool bGlobalFocus; ///< Corresponding to DSBCAPS_GLOBALFOCUS. If using the AkAPI_DirectSound AkAudioAPI type, sounds will be muted if set to false when the game loses the focus.
84  ///< This setting is ignored when using other AkAudioAPI types.
85 
86  IXAudio2* pXAudio2; ///< XAudio2 instance to use for the Wwise sound engine. If NULL (default) Wwise will initialize its own instance. Used only if the sink type is XAudio2 in AkInitSettings.outputType.
87 
88  bool bEnableAvxSupport; ///< Enables run-time detection of AVX and AVX2 SIMD support in the engine and plug-ins. Disabling this may improve CPU performance by allowing for higher CPU clockspeeds.
89 };
90 
91 struct IDirectSound8;
92 struct IXAudio2;
93 struct IMMDevice;
94 struct IUnknown;
95 
96 namespace AK
97 {
98  /// Get instance of XAudio2 created by the sound engine at initialization.
99  /// \return Non-addref'd pointer to XAudio2 interface. NULL if sound engine is not initialized or XAudio2 is not used.
100  /// The returned pointer can be of either XAudio 2.7, XAudio 2.8, Xaudio 2.9 depending on the Windows version the game is running on. Use QueryInterface to identify which one and cast appropriately
101  AK_EXTERNAPIFUNC( IUnknown *, GetWwiseXAudio2Interface)();
102 
103  /// Get instance of DirectSound created by the sound engine at initialization.
104  /// \return Non-addref'd pointer to DirectSound interface. NULL if sound engine is not initialized or DirectSound is not used.
105  AK_EXTERNAPIFUNC( IDirectSound8 *, GetDirectSoundInstance )();
106 
107  /// Finds the device ID for particular Audio Endpoint.
108  /// \note CoInitialize must have been called for the calling thread. See Microsoft's documentation about CoInitialize for more details.
109  /// \return A device ID to use with AkPlatformInitSettings.idAudioDevice
110  AK_EXTERNAPIFUNC( AkUInt32, GetDeviceID ) (IMMDevice* in_pDevice);
111 
112  /// Finds an audio endpoint that matches the token in the device name or device ID and returns an ID.
113  /// This is a helper function that searches in the device ID (as returned by IMMDevice->GetId) and
114  /// in the property PKEY_Device_FriendlyName. The token parameter is case-sensitive. If you need to do matching on different conditions, use IMMDeviceEnumerator directly and AK::GetDeviceID.
115  /// \note CoInitialize must have been called for the calling thread. See Microsoft's documentation about CoInitialize for more details.
116  /// \return The device ID as returned by IMMDevice->GetId, hashed by AK::SoundEngine::GetIDFromName()
117  AK_EXTERNAPIFUNC( AkUInt32, GetDeviceIDFromName )(wchar_t* in_szToken);
118 
119  /// Get the user-friendly name for the specified device. Call repeatedly with index starting at 0 and increasing to get all available devices, including disabled and unplugged devices, until the returned string is null and out_uDeviceID is zero.
120  /// The number of indexable devices for the given uDeviceStateMask can be fetched by calling AK::SoundEngine::GetWindowsDeviceCount().
121  /// You can also get the default device information by specifying index=-1. The default device is the one with a green checkmark in the Audio Playback Device panel in Windows.
122  /// The returned out_uDeviceID parameter is the Device ID to use with Wwise. Use it to specify the main device in AkPlatformInitSettings.idAudioDevice.
123  /// \note CoInitialize must have been called for the calling thread. See Microsoft's documentation about CoInitialize for more details.
124  /// \return The name of the device at the "index" specified. The pointer is valid until the next call to GetWindowsDeviceName.
125  AK_EXTERNAPIFUNC(const wchar_t*, GetWindowsDeviceName) (
126  AkInt32 index, ///< Index of the device in the array. -1 to get information on the default device.
127  AkUInt32 &out_uDeviceID, ///< Device ID for Wwise. This is the same as what is returned from AK::GetDeviceID and AK::GetDeviceIDFromName. Use it to specify the main device in AkPlatformInitSettings.idAudioDevice.
128  AkAudioDeviceState uDeviceStateMask = AkDeviceState_All ///< Optional bitmask used to filter the device based on their state.
129  );
130 
131  /// Get the number of Audio Endpoints available for the specified device state mask.
132  /// \note CoInitialize must have been called for the calling thread. See Microsoft's documentation about CoInitialize for more details.
133  /// \return The number of Audio Endpoints available for the specified device state mask.
134  AK_EXTERNAPIFUNC( AkUInt32, GetWindowsDeviceCount ) (
135  AkAudioDeviceState uDeviceStateMask = AkDeviceState_All ///< Optional bitmask used to filter the device based on their state.
136  );
137 
138  /// Get the Audio Endpoint for the specified device index. Call repeatedly with index starting at 0 and increasing to get all available devices, including disabled and unplugged devices, until the false is returned.
139  /// You can also get the default device information by specifying index=-1. The default device is the one with a green checkmark in the Audio Playback Device panel in Windows.
140  /// The returned out_uDeviceID parameter is the Device ID to use with Wwise. Use it to specify the main device in AkPlatformInitSettings.idAudioDevice.
141  /// The returned out_ppDevice is a pointer to a pointer variable to which the method writes the address of the IMMDevice. out_ppDevice is optional; if it is null, then no action is taken.
142  /// If the method returns false, *out_ppDevice is null. If the method successed, *out_ppDevice will be a counted reference to the interface, and the caller is responsible for releasing the interface when it is no longer needed, by calling Release(), or encapsulating the device in a COM Smart Pointer.
143  /// \note CoInitialize must have been called for the calling thread. See Microsoft's documentation about CoInitialize for more details.
144  /// \return Whether or not a device was found at the given index.
145  AK_EXTERNAPIFUNC( bool, GetWindowsDevice) (
146  AkInt32 in_index, ///< Index of the device in the array. -1 to get information on the default device.
147  AkUInt32& out_uDeviceID, ///< Device ID for Wwise. This is the same as what is returned from AK::GetDeviceID and AK::GetDeviceIDFromName. Use it to specify the main device in AkPlatformInitSettings.idAudioDevice.
148  IMMDevice** out_ppDevice, ///< pointer to a pointer variable to which the method writes the address of the IMMDevice in question.
149  AkAudioDeviceState uDeviceStateMask = AkDeviceState_All ///< Optional bitmask used to filter the device based on their state.
150  );
151 
152 #ifdef AK_UWP_CPP_CX
153 
154  /// Get the device ID corresponding to a Universal Windows Platform Gamepad reference. This device ID can be used to add/remove motion output for that gamepad.
155  /// \note The ID returned is unique to Wwise and does not correspond to any sensible value outside of Wwise.
156  /// \note This function is only available for project code using C++/CX.
157  /// \return Unique device ID, or AK_INVALID_DEVICE_ID if the reference is no longer valid (such as if the gamepad was disconnected)
158  AK_EXTERNAPIFUNC(AkDeviceID, GetDeviceIDFromGamepad) (Windows::Gaming::Input::Gamepad^ rGamepad);
159 
160 #endif
161 
162 };
163 
164 #endif //_AK_WIN_SOUND_ENGINE_H_
AKSOUNDENGINE_API bool __cdecl GetWindowsDevice(AkInt32 in_index, AkUInt32 &out_uDeviceID, IMMDevice **out_ppDevice, AkAudioDeviceState uDeviceStateMask=AkDeviceState_All)
Audiokinetic namespace.
AKSOUNDENGINE_API IDirectSound8 *__cdecl GetDirectSoundInstance()
AKSOUNDENGINE_API AkDeviceID __cdecl GetDeviceIDFromGamepad(Windows::Gaming::Input::Gamepad^ rGamepad)
AkThreadProperties threadMonitor
Monitor threading properties (its default priority is AK_THREAD_PRIORITY_ABOVENORMAL)....
AKSOUNDENGINE_API AkUInt32 __cdecl GetDeviceIDFromName(wchar_t *in_szToken)
AkThreadProperties threadLEngine
Lower engine threading properties.
AkUInt16 uNumRefillsInVoice
Number of refill buffers in voice buffer. Defaults to 4.
AKSOUNDENGINE_API AkUInt32 __cdecl GetWindowsDeviceCount(AkAudioDeviceState uDeviceStateMask=AkDeviceState_All)
AkThreadProperties threadOutputMgr
Ouput thread threading properties.
const AKSOUNDENGINE_API wchar_t *__cdecl GetWindowsDeviceName(AkInt32 index, AkUInt32 &out_uDeviceID, AkAudioDeviceState uDeviceStateMask=AkDeviceState_All)
bool bEnableAvxSupport
Enables run-time detection of AVX and AVX2 SIMD support in the engine and plug-ins....
Definition: AkWinSoundEngine.h:88
AkUInt32 uSampleRate
Sampling Rate. Set to 0 to get the native sample rate. Default value is 0.
AKSOUNDENGINE_API AkUInt32 __cdecl GetDeviceID(IMMDevice *in_pDevice)
AKSOUNDENGINE_API IUnknown *__cdecl GetWwiseXAudio2Interface()
IXAudio2 * pXAudio2
XAudio2 instance to use for the Wwise sound engine. If NULL (default) Wwise will initialize its own i...
Definition: AkWinSoundEngine.h:86
AkThreadProperties threadBankManager
Bank manager threading properties (its default priority is AK_THREAD_PRIORITY_NORMAL)