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
#[cfg(not(wwconfig = "release"))]
pub use crate::bindings::root::AkCommSettings;
#[cfg(not(wwconfig = "release"))]
use crate::bindings::root::AK::Comm;
use crate::bindings::root::AK::{MemoryMgr, SoundEngine, StreamMgr};
pub use crate::bindings::root::{
AkDeviceSettings, AkMemSettings, AkPlatformInitSettings, AkStreamMgrSettings,
};
use crate::to_os_char;
use crate::OsChar;
pub struct AkInitSettings {
settings: crate::bindings::root::AkInitSettings,
plugin_dll_path: Vec<OsChar>,
}
impl Default for AkMemSettings {
fn default() -> Self {
unsafe {
let mut ss: AkMemSettings = std::mem::zeroed();
MemoryMgr::GetDefaultSettings(&mut ss);
ss
}
}
}
impl Default for AkStreamMgrSettings {
fn default() -> Self {
unsafe {
let mut ss: AkStreamMgrSettings = std::mem::zeroed();
StreamMgr::GetDefaultSettings(&mut ss);
ss
}
}
}
impl Default for AkDeviceSettings {
fn default() -> Self {
unsafe {
let mut ss: AkDeviceSettings = std::mem::zeroed();
StreamMgr::GetDefaultDeviceSettings(&mut ss);
ss
}
}
}
impl Default for AkInitSettings {
fn default() -> Self {
unsafe {
let mut ss = AkInitSettings {
settings: std::mem::zeroed(),
plugin_dll_path: vec![],
};
SoundEngine::GetDefaultInitSettings(&mut ss.settings);
ss
}
}
}
impl Default for AkPlatformInitSettings {
fn default() -> Self {
unsafe {
let mut ss: AkPlatformInitSettings = std::mem::zeroed();
SoundEngine::GetDefaultPlatformInitSettings(&mut ss);
ss
}
}
}
#[cfg(not(wwconfig = "release"))]
impl Default for AkCommSettings {
fn default() -> Self {
unsafe {
let mut ss: AkCommSettings = std::mem::zeroed();
Comm::GetDefaultInitSettings(&mut ss);
if let Some(app_name) = app_name() {
ss.szAppNetworkName = app_name;
}
ss
}
}
}
unsafe fn app_name() -> Option<[i8; 64]> {
if let Some(mut name) = std::env::current_exe()
.ok()?
.file_name()?
.to_str()?
.to_owned()
.into()
{
if name.ends_with(".exe") {
name.truncate(name.len() - 4);
}
if name.len() < 64 {
name.extend(std::iter::repeat('\0').take(64 - name.len()));
} else {
name.truncate(64);
}
let mut truncated = [0_u8; 64];
truncated.copy_from_slice(name.as_bytes());
truncated[63] = 0;
Some(std::mem::transmute(truncated))
} else {
None
}
}
impl AkInitSettings {
pub fn with_plugin_dll_path<T: AsRef<str>>(mut self, path: T) -> Self {
self.plugin_dll_path = to_os_char(path.as_ref());
self.settings.szPluginDLLPath = self.plugin_dll_path.as_mut_ptr();
self
}
pub(crate) fn as_ak(&mut self) -> &mut crate::bindings::root::AkInitSettings {
&mut self.settings
}
}