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
300
301
302
303
|
#include <lua.h>
#include <lauxlib.h>
#include <miniaudio.h>
#include "audio.h"
#define GET_PARAM(param) \
do { \
lua_getfield(L, conf_tbl, #param); \
if (!lua_isnil(L, -1)) { \
config.param = lua_tointeger(L, -1); \
} \
lua_pop(L, 1); \
} while (0)
int ma_engine_init_bind(lua_State *L)
{
luaL_checktype(L, 1, LUA_TTABLE);
const int conf_tbl = 1;
ma_engine_config config = ma_engine_config_init();
GET_PARAM(listenerCount);
GET_PARAM(sampleRate);
GET_PARAM(gainSmoothTimeInFrames);
GET_PARAM(gainSmoothTimeInMilliseconds);
ma_engine *engine = lua_newuserdata(L, sizeof(ma_engine));
int engine_index = lua_gettop(L);
ma_result result = ma_engine_init(&config, engine);
lua_pushinteger(L, result);
lua_pushvalue(L, engine_index);
lua_remove(L, engine_index);
luaL_getmetatable(L, ma_engine_tname);
lua_setmetatable(L, -2);
return 2;
}
int ma_engine_uninit_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_engine_uninit(pEngine);
return 0;
}
int ma_engine_get_time_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint64 bind_result = ma_engine_get_time(pEngine);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_set_time_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint64 globalTime = luaL_checkinteger(L, 2);
ma_result bind_result = ma_engine_set_time(pEngine, globalTime);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_get_channels_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 bind_result = ma_engine_get_channels(pEngine);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_get_sample_rate_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 bind_result = ma_engine_get_sample_rate(pEngine);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_start_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_result bind_result = ma_engine_start(pEngine);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_stop_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_result bind_result = ma_engine_stop(pEngine);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_set_volume_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
float volume = luaL_checknumber(L, 2);
ma_result bind_result = ma_engine_set_volume(pEngine, volume);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_set_gain_db_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
float gainDB = luaL_checknumber(L, 2);
ma_result bind_result = ma_engine_set_gain_db(pEngine, gainDB);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_get_listener_count_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 bind_result = ma_engine_get_listener_count(pEngine);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_find_closest_listener_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
float absolutePosX = luaL_checknumber(L, 2);
float absolutePosY = luaL_checknumber(L, 3);
float absolutePosZ = luaL_checknumber(L, 4);
ma_uint32 bind_result = ma_engine_find_closest_listener(pEngine, absolutePosX, absolutePosY, absolutePosZ);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_listener_set_position_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
float x = luaL_checknumber(L, 3);
float y = luaL_checknumber(L, 4);
float z = luaL_checknumber(L, 5);
ma_engine_listener_set_position(pEngine, listenerIndex, x, y, z);
return 0;
}
int ma_engine_listener_get_position_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
ma_vec3f bind_result = ma_engine_listener_get_position(pEngine, listenerIndex);
lua_pushnumber(L, bind_result.x);
lua_pushnumber(L, bind_result.y);
lua_pushnumber(L, bind_result.z);
return 3;
}
int ma_engine_listener_set_direction_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
float x = luaL_checknumber(L, 3);
float y = luaL_checknumber(L, 4);
float z = luaL_checknumber(L, 5);
ma_engine_listener_set_direction(pEngine, listenerIndex, x, y, z);
return 0;
}
int ma_engine_listener_get_direction_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
ma_vec3f bind_result = ma_engine_listener_get_direction(pEngine, listenerIndex);
lua_pushnumber(L, bind_result.x);
lua_pushnumber(L, bind_result.y);
lua_pushnumber(L, bind_result.z);
return 3;
}
int ma_engine_listener_set_velocity_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
float x = luaL_checknumber(L, 3);
float y = luaL_checknumber(L, 4);
float z = luaL_checknumber(L, 5);
ma_engine_listener_set_velocity(pEngine, listenerIndex, x, y, z);
return 0;
}
int ma_engine_listener_get_velocity_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
ma_vec3f bind_result = ma_engine_listener_get_velocity(pEngine, listenerIndex);
lua_pushnumber(L, bind_result.x);
lua_pushnumber(L, bind_result.y);
lua_pushnumber(L, bind_result.z);
return 3;
}
int ma_engine_listener_set_cone_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
float innerAngleInRadians = luaL_checknumber(L, 3);
float outerAngleInRadians = luaL_checknumber(L, 4);
float outerGain = luaL_checknumber(L, 5);
ma_engine_listener_set_cone(pEngine, listenerIndex, innerAngleInRadians, outerAngleInRadians, outerGain);
return 0;
}
int ma_engine_listener_get_cone_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
float innerAngleInRadians, outerAngleInRadians, outerGain;
ma_engine_listener_get_cone(pEngine, listenerIndex, &innerAngleInRadians, &outerAngleInRadians, &outerGain);
lua_pushnumber(L, innerAngleInRadians);
lua_pushnumber(L, outerAngleInRadians);
lua_pushnumber(L, outerGain);
return 3;
}
int ma_engine_listener_set_world_up_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
float x = luaL_checknumber(L, 3);
float y = luaL_checknumber(L, 4);
float z = luaL_checknumber(L, 5);
ma_engine_listener_set_world_up(pEngine, listenerIndex, x, y, z);
return 0;
}
int ma_engine_listener_get_world_up_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
ma_vec3f bind_result = ma_engine_listener_get_world_up(pEngine, listenerIndex);
lua_pushnumber(L, bind_result.x);
lua_pushnumber(L, bind_result.y);
lua_pushnumber(L, bind_result.z);
return 3;
}
int ma_engine_listener_set_enabled_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
ma_bool32 isEnabled = luaL_checkinteger(L, 3);
ma_engine_listener_set_enabled(pEngine, listenerIndex, isEnabled);
return 0;
}
int ma_engine_listener_is_enabled_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
ma_uint32 listenerIndex = luaL_checkinteger(L, 2);
ma_bool32 bind_result = ma_engine_listener_is_enabled(pEngine, listenerIndex);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_play_sound_ex_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
const char * pFilePath = luaL_checkstring(L, 2);
ma_node * pNode = luaL_checkudata(L, 3, ma_node_tname);
ma_uint32 nodeInputBusIndex = luaL_checkinteger(L, 4);
ma_result bind_result = ma_engine_play_sound_ex(pEngine, pFilePath, pNode, nodeInputBusIndex);
lua_pushinteger(L, bind_result);
return 1;
}
int ma_engine_play_sound_bind(lua_State *L)
{
ma_engine * pEngine = luaL_checkudata(L, 1, ma_engine_tname);
const char * pFilePath = luaL_checkstring(L, 2);
ma_sound_group * pGroup = to_sound_group(L, 3);
ma_result bind_result = ma_engine_play_sound(pEngine, pFilePath, pGroup);
lua_pushinteger(L, bind_result);
return 1;
}
|