38
|
1 /*
|
|
2 LuaOpenAL
|
|
3 Copyright (C) 2010 Eric Wing <ewing . public @ playcontrol.net>
|
|
4
|
|
5 Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6 of this software and associated documentation files (the "Software"), to deal
|
|
7 in the Software without restriction, including without limitation the rights
|
|
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9 copies of the Software, and to permit persons to whom the Software is
|
|
10 furnished to do so, subject to the following conditions:
|
|
11
|
|
12 The above copyright notice and this permission notice shall be included in
|
|
13 all copies or substantial portions of the Software.
|
|
14
|
|
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21 THE SOFTWARE.
|
|
22
|
|
23 */
|
|
24 #include "al.h"
|
|
25 /* #include "alc.h" */
|
|
26
|
|
27 #include "lua.h"
|
|
28 #include "lauxlib.h"
|
|
29
|
|
30 #define LUAAL_VERSION "1.1"
|
|
31
|
|
32 typedef struct luaopenal_Enum
|
|
33 {
|
|
34 const char* stringName;
|
|
35 ALenum alValue;
|
|
36 } luaopenal_Enum;
|
|
37
|
|
38
|
|
39 void luaopenal_initenum(lua_State* lua_state, const luaopenal_Enum* al_enums)
|
|
40 {
|
|
41 for( ; al_enums->stringName; al_enums++)
|
|
42 {
|
|
43 lua_pushstring(lua_state, al_enums->stringName);
|
|
44 lua_pushinteger(lua_state, al_enums->alValue);
|
|
45 lua_settable(lua_state, -3);
|
|
46 }
|
|
47 }
|
|
48
|
|
49
|
|
50 static const luaopenal_Enum s_luaALEnum[] = {
|
|
51 { "INVALID", AL_INVALID },
|
|
52 { "NONE", AL_NONE },
|
|
53 { "FALSE", AL_FALSE },
|
|
54 { "TRUE", AL_TRUE },
|
|
55 { "SOURCE_RELATIVE", AL_SOURCE_RELATIVE },
|
|
56 { "CONE_INNER_ANGLE", AL_CONE_INNER_ANGLE },
|
|
57 { "CONE_OUTER_ANGLE", AL_CONE_OUTER_ANGLE },
|
|
58 { "PITCH", AL_PITCH },
|
|
59 { "POSITION", AL_POSITION },
|
|
60 { "DIRECTION", AL_DIRECTION },
|
|
61 { "VELOCITY", AL_VELOCITY },
|
|
62 { "LOOPING", AL_LOOPING },
|
|
63 { "BUFFER", AL_BUFFER },
|
|
64 { "GAIN", AL_GAIN },
|
|
65 { "MIN_GAIN", AL_MIN_GAIN },
|
|
66 { "MAX_GAIN", AL_MAX_GAIN },
|
|
67 { "ORIENTATION", AL_ORIENTATION },
|
|
68 /* { "CHANNEL_MASK", AL_CHANNEL_MASK }, */
|
|
69 { "SOURCE_STATE", AL_SOURCE_STATE },
|
|
70 { "INITIAL", AL_INITIAL },
|
|
71 { "PLAYING", AL_PLAYING },
|
|
72 { "PAUSED", AL_PAUSED },
|
|
73 { "STOPPED", AL_STOPPED },
|
|
74 { "BUFFERS_QUEUED", AL_BUFFERS_QUEUED },
|
|
75 { "BUFFERS_PROCESSED", AL_BUFFERS_PROCESSED },
|
|
76 { "SEC_OFFSET", AL_SEC_OFFSET },
|
|
77 { "SAMPLE_OFFSET", AL_SAMPLE_OFFSET },
|
|
78 { "BYTE_OFFSET", AL_BYTE_OFFSET },
|
|
79 { "SOURCE_TYPE", AL_SOURCE_TYPE },
|
|
80 { "STATIC", AL_STATIC },
|
|
81 { "STREAMING", AL_STREAMING },
|
|
82 { "UNDETERMINED", AL_UNDETERMINED },
|
|
83 { "FORMAT_MONO8", AL_FORMAT_MONO8 },
|
|
84 { "FORMAT_MONO16", AL_FORMAT_MONO16 },
|
|
85 { "FORMAT_STEREO8", AL_FORMAT_STEREO8 },
|
|
86 { "FORMAT_STEREO16", AL_FORMAT_STEREO16 },
|
|
87 { "REFERENCE_DISTANCE", AL_REFERENCE_DISTANCE },
|
|
88 { "ROLLOFF_FACTOR", AL_ROLLOFF_FACTOR },
|
|
89 { "CONE_OUTER_GAIN", AL_CONE_OUTER_GAIN },
|
|
90 { "MAX_DISTANCE", AL_MAX_DISTANCE },
|
|
91 { "FREQUENCY", AL_FREQUENCY },
|
|
92 { "BITS", AL_BITS },
|
|
93 { "CHANNELS", AL_CHANNELS },
|
|
94 { "SIZE", AL_SIZE },
|
|
95 /*
|
|
96 { "UNUSED", AL_UNUSED },
|
|
97 { "PENDING", AL_PENDING },
|
|
98 { "PROCESSED", AL_PROCESSED },
|
|
99 */
|
|
100 { "NO_ERROR", AL_NO_ERROR },
|
|
101 { "INVALID_NAME", AL_INVALID_NAME },
|
|
102 { "ILLEGAL_ENUM", AL_ILLEGAL_ENUM },
|
|
103 { "INVALID_VALUE", AL_INVALID_VALUE },
|
|
104 { "ILLEGAL_COMMAND", AL_ILLEGAL_COMMAND },
|
|
105 { "INVALID_OPERATION", AL_INVALID_OPERATION },
|
|
106 { "OUT_OF_MEMORY", AL_OUT_OF_MEMORY },
|
|
107 { "VENDOR", AL_VENDOR },
|
|
108 { "VERSION", AL_VERSION },
|
|
109 { "RENDERER", AL_RENDERER },
|
|
110 { "EXTENSIONS", AL_EXTENSIONS },
|
|
111 { "DOPPLER_FACTOR", AL_DOPPLER_FACTOR },
|
|
112 { "DOPPLER_VELOCITY", AL_DOPPLER_VELOCITY },
|
|
113 { "SPEED_OF_SOUND", AL_SPEED_OF_SOUND },
|
|
114 { "DISTANCE_MODEL", AL_DISTANCE_MODEL },
|
|
115 { "INVERSE_DISTANCE", AL_INVERSE_DISTANCE },
|
|
116 { "INVERSE_DISTANCE_CLAMPED", AL_INVERSE_DISTANCE_CLAMPED },
|
|
117 { "LINEAR_DISTANCE", AL_LINEAR_DISTANCE },
|
|
118 { "LINEAR_DISTANCE_CLAMPED", AL_LINEAR_DISTANCE_CLAMPED },
|
|
119 { "EXPONENT_DISTANCE", AL_EXPONENT_DISTANCE },
|
|
120 { "EXPONENT_DISTANCE_CLAMPED", AL_EXPONENT_DISTANCE_CLAMPED },
|
|
121 { 0, 0 }
|
|
122 };
|
|
123
|
|
124
|
|
125 #define LUAOPENAL_BOOL_TYPE 1
|
|
126 #define LUAOPENAL_INT_TYPE 2
|
|
127 #define LUAOPENAL_FLOAT_TYPE 3
|
|
128
|
|
129
|
|
130 #define LUAOPENAL_INT_3_TYPE 4
|
|
131 #define LUAOPENAL_FLOAT_3_TYPE 5
|
|
132 #define LUAOPENAL_FLOAT_6_TYPE 6
|
|
133 #define LUAOPENAL_STRING_TYPE 7
|
|
134
|
|
135
|
|
136 static int lua_getTypeForEnum(ALenum enum_parameter)
|
|
137 {
|
|
138 switch(enum_parameter)
|
|
139 {
|
|
140 case AL_SOURCE_RELATIVE:
|
|
141 case AL_LOOPING:
|
|
142 {
|
|
143 return LUAOPENAL_BOOL_TYPE;
|
|
144 break;
|
|
145 }
|
|
146
|
|
147 case AL_SOURCE_TYPE:
|
|
148 case AL_BUFFER:
|
|
149 case AL_BUFFERS_QUEUED:
|
|
150 case AL_BUFFERS_PROCESSED:
|
|
151 {
|
|
152 return LUAOPENAL_INT_TYPE;
|
|
153 break;
|
|
154 }
|
|
155 case AL_GAIN:
|
|
156 case AL_MIN_GAIN:
|
|
157 case AL_MAX_GAIN:
|
|
158 case AL_REFERENCE_DISTANCE: /* could be integer */
|
|
159 case AL_ROLLOFF_FACTOR: /* could be integer */
|
|
160 case AL_MAX_DISTANCE: /* could be integer */
|
|
161 case AL_PITCH:
|
|
162 case AL_CONE_INNER_ANGLE: /* could be integer */
|
|
163 case AL_CONE_OUTER_ANGLE: /* could be integer */
|
|
164 case AL_CONE_OUTER_GAIN: /* interesting...only f,fv according to spec */
|
|
165 case AL_SAMPLE_OFFSET: /* could be integer */
|
|
166 case AL_BYTE_OFFSET: /* could be integer */
|
|
167 case AL_SEC_OFFSET: /* could be integer */
|
|
168
|
|
169 case AL_DOPPLER_FACTOR:
|
|
170 case AL_DOPPLER_VELOCITY:
|
|
171 case AL_SPEED_OF_SOUND:
|
|
172 {
|
|
173 return LUAOPENAL_FLOAT_TYPE;
|
|
174 break;
|
|
175 }
|
|
176
|
|
177 case AL_POSITION: /* could be integer */
|
|
178 case AL_VELOCITY: /* could be integer */
|
|
179 case AL_DIRECTION: /* could be integer */
|
|
180 {
|
|
181 return LUAOPENAL_FLOAT_3_TYPE;
|
|
182 break;
|
|
183 }
|
|
184
|
|
185 case AL_ORIENTATION: /* could be integer */
|
|
186 {
|
|
187 return LUAOPENAL_FLOAT_6_TYPE;
|
|
188 break;
|
|
189 }
|
|
190
|
|
191 case AL_NO_ERROR:
|
|
192 case AL_INVALID_NAME:
|
|
193 case AL_ILLEGAL_ENUM:
|
|
194 /* case AL_INVALID_ENUM: */ /* same as AL_ILLEGAL_ENUM */
|
|
195 case AL_INVALID_VALUE:
|
|
196 case AL_ILLEGAL_COMMAND:
|
|
197 /* case AL_INVALID_OPERATION: */ /* same as AL_ILLEGAL_COMMAND */
|
|
198 case AL_OUT_OF_MEMORY:
|
|
199 case AL_VENDOR:
|
|
200 case AL_VERSION:
|
|
201 case AL_RENDERER:
|
|
202 case AL_EXTENSIONS:
|
|
203 {
|
|
204 return LUAOPENAL_STRING_TYPE;
|
|
205 break;
|
|
206 }
|
|
207
|
|
208 }
|
|
209 return 0;
|
|
210 }
|
|
211
|
|
212 static int lua_alEnable(lua_State* lua_state)
|
|
213 {
|
|
214 ALenum enum_parameter;
|
|
215 enum_parameter = lua_tointeger(lua_state, 1);
|
|
216 alEnable(enum_parameter);
|
|
217 return 0;
|
|
218 }
|
|
219
|
|
220 static int lua_alDisable(lua_State* lua_state)
|
|
221 {
|
|
222 ALenum enum_parameter;
|
|
223 enum_parameter = lua_tointeger(lua_state, 1);
|
|
224 alDisable(enum_parameter);
|
|
225 return 0;
|
|
226 }
|
|
227
|
|
228 static int lua_alIsEnabled(lua_State* lua_state)
|
|
229 {
|
|
230 ALenum enum_parameter;
|
|
231 ALboolean ret_val;
|
|
232 enum_parameter = lua_tointeger(lua_state, 1);
|
|
233 ret_val = alIsEnabled(enum_parameter);
|
|
234 lua_pushboolean(lua_state, ret_val);
|
|
235 return 1;
|
|
236 }
|
|
237
|
|
238 static int lua_alGetError(lua_State* lua_state)
|
|
239 {
|
|
240 ALenum ret_val;
|
|
241 ret_val = alGetError();
|
|
242 lua_pushinteger(lua_state, ret_val);
|
|
243 return 1;
|
|
244 }
|
|
245
|
|
246 static int lua_alIsExtensionPresent(lua_State* lua_state)
|
|
247 {
|
|
248 const ALchar* string_name;
|
|
249 ALboolean ret_val;
|
|
250 string_name = lua_tostring(lua_state, 1);
|
|
251 ret_val = alIsExtensionPresent(string_name);
|
|
252 lua_pushboolean(lua_state, ret_val);
|
|
253 return 1;
|
|
254 }
|
|
255
|
|
256 /* TODO: alGetProcAddress */
|
|
257
|
|
258 static int lua_alGetEnumValue(lua_State* lua_state)
|
|
259 {
|
|
260 const ALchar* string_name;
|
|
261 ALenum ret_val;
|
|
262 string_name = lua_tostring(lua_state, 1);
|
|
263 ret_val = alGetEnumValue(string_name);
|
|
264 lua_pushinteger(lua_state, ret_val);
|
|
265 return 1;
|
|
266 }
|
|
267
|
|
268
|
|
269
|
|
270
|
|
271 static int lua_alGetListener(lua_State* lua_state)
|
|
272 {
|
|
273 ALenum enum_parameter;
|
|
274 int openal_primitive_type;
|
|
275
|
|
276 enum_parameter = lua_tointeger(lua_state, 1);
|
|
277
|
|
278 openal_primitive_type = lua_getTypeForEnum(enum_parameter);
|
|
279
|
|
280 switch(openal_primitive_type)
|
|
281 {
|
|
282 case LUAOPENAL_BOOL_TYPE:
|
|
283 {
|
|
284 ALint ret_val;
|
|
285 alGetListeneri(enum_parameter, &ret_val);
|
|
286 lua_pushboolean(lua_state, ret_val);
|
|
287 return 1;
|
|
288 break;
|
|
289 }
|
|
290 case LUAOPENAL_INT_TYPE:
|
|
291 {
|
|
292 ALint ret_val;
|
|
293 alGetListeneri(enum_parameter, &ret_val);
|
|
294 lua_pushinteger(lua_state, ret_val);
|
|
295 return 1;
|
|
296 break;
|
|
297 }
|
|
298 case LUAOPENAL_FLOAT_TYPE:
|
|
299 {
|
|
300 ALfloat ret_val;
|
|
301 alGetListenerf(enum_parameter, &ret_val);
|
|
302 lua_pushnumber(lua_state, ret_val);
|
|
303 return 1;
|
|
304 break;
|
|
305 }
|
|
306 case LUAOPENAL_INT_3_TYPE:
|
|
307 {
|
|
308 ALint ret_val[3];
|
|
309 alGetListeneriv(enum_parameter, ret_val);
|
|
310 lua_pushinteger(lua_state, ret_val[0]);
|
|
311 lua_pushinteger(lua_state, ret_val[1]);
|
|
312 lua_pushinteger(lua_state, ret_val[2]);
|
|
313 return 3;
|
|
314 break;
|
|
315 }
|
|
316 case LUAOPENAL_FLOAT_3_TYPE:
|
|
317 {
|
|
318 ALfloat ret_val[3];
|
|
319 alGetListenerfv(enum_parameter, ret_val);
|
|
320 lua_pushnumber(lua_state, ret_val[0]);
|
|
321 lua_pushnumber(lua_state, ret_val[1]);
|
|
322 lua_pushnumber(lua_state, ret_val[2]);
|
|
323 return 3;
|
|
324 break;
|
|
325 }
|
|
326 case LUAOPENAL_FLOAT_6_TYPE:
|
|
327 {
|
|
328 ALfloat ret_val[6];
|
|
329 alGetListenerfv(enum_parameter, ret_val);
|
|
330 lua_pushnumber(lua_state, ret_val[0]);
|
|
331 lua_pushnumber(lua_state, ret_val[1]);
|
|
332 lua_pushnumber(lua_state, ret_val[2]);
|
|
333 lua_pushnumber(lua_state, ret_val[3]);
|
|
334 lua_pushnumber(lua_state, ret_val[4]);
|
|
335 lua_pushnumber(lua_state, ret_val[5]);
|
|
336 return 6;
|
|
337 break;
|
|
338 }
|
|
339 default:
|
|
340 {
|
|
341 /* TODO: Figure out how to handle OpenAL extensions. */
|
|
342 luaL_error(lua_state, "Unhandled parameter type for alGetSource*");
|
|
343 }
|
|
344 }
|
|
345 return 0;
|
|
346 }
|
|
347
|
|
348 static int lua_alListener(lua_State* lua_state)
|
|
349 {
|
|
350 ALenum enum_parameter;
|
|
351 int openal_primitive_type;
|
|
352
|
|
353 enum_parameter = lua_tointeger(lua_state, 1);
|
|
354
|
|
355
|
|
356 openal_primitive_type = lua_getTypeForEnum(enum_parameter);
|
|
357
|
|
358 switch(openal_primitive_type)
|
|
359 {
|
|
360 case LUAOPENAL_BOOL_TYPE:
|
|
361 case LUAOPENAL_INT_TYPE:
|
|
362 {
|
|
363 alListeneri(enum_parameter, lua_tointeger(lua_state, 2));
|
|
364 break;
|
|
365 }
|
|
366 case LUAOPENAL_FLOAT_TYPE:
|
|
367 {
|
|
368 alListenerf(enum_parameter, lua_tonumber(lua_state, 2));
|
|
369 break;
|
|
370 }
|
|
371 case LUAOPENAL_INT_3_TYPE:
|
|
372 {
|
|
373 alListener3i(enum_parameter, lua_tointeger(lua_state, 2), lua_tointeger(lua_state, 3), lua_tointeger(lua_state, 4));
|
|
374 break;
|
|
375 }
|
|
376 case LUAOPENAL_FLOAT_3_TYPE:
|
|
377 {
|
|
378 alListener3f(enum_parameter, lua_tonumber(lua_state, 2), lua_tonumber(lua_state, 3), lua_tonumber(lua_state, 4));
|
|
379 break;
|
|
380 }
|
|
381 case LUAOPENAL_FLOAT_6_TYPE:
|
|
382 {
|
|
383 ALfloat val_array[6] =
|
|
384 {
|
|
385 lua_tonumber(lua_state, 2),
|
|
386 lua_tonumber(lua_state, 3),
|
|
387 lua_tonumber(lua_state, 4),
|
|
388 lua_tonumber(lua_state, 5),
|
|
389 lua_tonumber(lua_state, 6),
|
|
390 lua_tonumber(lua_state, 7)
|
|
391 };
|
|
392
|
|
393 alListenerfv(enum_parameter, val_array);
|
|
394 break;
|
|
395 }
|
|
396 default:
|
|
397 {
|
|
398 /* TODO: Figure out how to handle OpenAL extensions. */
|
|
399 luaL_error(lua_state, "Unhandled parameter type for alSource*");
|
|
400 }
|
|
401 }
|
|
402 return 0;
|
|
403 }
|
|
404
|
|
405
|
|
406
|
|
407
|
|
408 static int lua_alGetSource(lua_State* lua_state)
|
|
409 {
|
|
410 ALuint source_id;
|
|
411 ALenum enum_parameter;
|
|
412 int openal_primitive_type;
|
|
413
|
|
414 source_id = lua_tointeger(lua_state, 1);
|
|
415 enum_parameter = lua_tointeger(lua_state, 2);
|
|
416
|
|
417 openal_primitive_type = lua_getTypeForEnum(enum_parameter);
|
|
418
|
|
419 switch(openal_primitive_type)
|
|
420 {
|
|
421 case LUAOPENAL_BOOL_TYPE:
|
|
422 {
|
|
423 ALint ret_val;
|
|
424 alGetSourcei(source_id, enum_parameter, &ret_val);
|
|
425 lua_pushboolean(lua_state, ret_val);
|
|
426 return 1;
|
|
427 break;
|
|
428 }
|
|
429 case LUAOPENAL_INT_TYPE:
|
|
430 {
|
|
431 ALint ret_val;
|
|
432 alGetSourcei(source_id, enum_parameter, &ret_val);
|
|
433 lua_pushinteger(lua_state, ret_val);
|
|
434 return 1;
|
|
435 break;
|
|
436 }
|
|
437 case LUAOPENAL_FLOAT_TYPE:
|
|
438 {
|
|
439 ALfloat ret_val;
|
|
440 alGetSourcef(source_id, enum_parameter, &ret_val);
|
|
441 lua_pushnumber(lua_state, ret_val);
|
|
442 return 1;
|
|
443 break;
|
|
444 }
|
|
445 case LUAOPENAL_INT_3_TYPE:
|
|
446 {
|
|
447 ALint ret_val[3];
|
|
448 alGetSourceiv(source_id, enum_parameter, ret_val);
|
|
449 lua_pushinteger(lua_state, ret_val[0]);
|
|
450 lua_pushinteger(lua_state, ret_val[1]);
|
|
451 lua_pushinteger(lua_state, ret_val[2]);
|
|
452 return 3;
|
|
453 break;
|
|
454 }
|
|
455 case LUAOPENAL_FLOAT_3_TYPE:
|
|
456 {
|
|
457 ALfloat ret_val[3];
|
|
458 alGetSourcefv(source_id, enum_parameter, ret_val);
|
|
459 lua_pushnumber(lua_state, ret_val[0]);
|
|
460 lua_pushnumber(lua_state, ret_val[1]);
|
|
461 lua_pushnumber(lua_state, ret_val[2]);
|
|
462 return 3;
|
|
463 break;
|
|
464 }
|
|
465 default:
|
|
466 {
|
|
467 /* TODO: Figure out how to handle OpenAL extensions. */
|
|
468 luaL_error(lua_state, "Unhandled parameter type for alGetSource*");
|
|
469 }
|
|
470 }
|
|
471 return 0;
|
|
472 }
|
|
473
|
|
474
|
|
475 static int lua_alSource(lua_State* lua_state)
|
|
476 {
|
|
477 ALuint source_id;
|
|
478 ALenum enum_parameter;
|
|
479 int openal_primitive_type;
|
|
480
|
|
481 source_id = lua_tointeger(lua_state, 1);
|
|
482 enum_parameter = lua_tointeger(lua_state, 2);
|
|
483
|
|
484 openal_primitive_type = lua_getTypeForEnum(enum_parameter);
|
|
485
|
|
486 switch(openal_primitive_type)
|
|
487 {
|
|
488 case LUAOPENAL_BOOL_TYPE:
|
|
489 case LUAOPENAL_INT_TYPE:
|
|
490 {
|
|
491 alSourcei(source_id, enum_parameter, lua_tointeger(lua_state, 3));
|
|
492 break;
|
|
493 }
|
|
494 case LUAOPENAL_FLOAT_TYPE:
|
|
495 {
|
|
496 alSourcef(source_id, enum_parameter, lua_tonumber(lua_state, 3));
|
|
497 break;
|
|
498 }
|
|
499 case LUAOPENAL_INT_3_TYPE:
|
|
500 {
|
|
501 alSource3i(source_id, enum_parameter, lua_tointeger(lua_state, 3), lua_tointeger(lua_state, 4), lua_tointeger(lua_state, 5));
|
|
502 break;
|
|
503 }
|
|
504 case LUAOPENAL_FLOAT_3_TYPE:
|
|
505 {
|
|
506 alSource3f(source_id, enum_parameter, lua_tonumber(lua_state, 3), lua_tonumber(lua_state, 4), lua_tonumber(lua_state, 5));
|
|
507 break;
|
|
508 }
|
|
509 default:
|
|
510 {
|
|
511 /* TODO: Figure out how to handle OpenAL extensions. */
|
|
512 luaL_error(lua_state, "Unhandled parameter type for alSource*");
|
|
513 }
|
|
514 }
|
|
515 return 0;
|
|
516 }
|
|
517
|
|
518
|
|
519 static int lua_alDopplerFactor(lua_State* lua_state)
|
|
520 {
|
|
521 ALfloat the_value;
|
|
522 the_value = lua_tonumber(lua_state, 1);
|
|
523 alDopplerFactor(the_value);
|
|
524 return 0;
|
|
525 }
|
|
526
|
|
527 static int lua_alDopplerVelocity(lua_State* lua_state)
|
|
528 {
|
|
529 ALfloat the_value;
|
|
530 the_value = lua_tonumber(lua_state, 1);
|
|
531 alDopplerVelocity(the_value);
|
|
532 return 0;
|
|
533 }
|
|
534
|
|
535 static int lua_alSpeedOfSound(lua_State* lua_state)
|
|
536 {
|
|
537 ALfloat the_value;
|
|
538 the_value = lua_tonumber(lua_state, 1);
|
|
539 alSpeedOfSound(the_value);
|
|
540 return 0;
|
|
541 }
|
|
542
|
|
543 static int lua_alDistanceModel(lua_State* lua_state)
|
|
544 {
|
|
545 ALenum enum_parameter;
|
|
546 enum_parameter = lua_tointeger(lua_state, 1);
|
|
547 alDistanceModel(enum_parameter);
|
|
548 return 0;
|
|
549 }
|
|
550
|
|
551 static int lua_alGet(lua_State* lua_state)
|
|
552 {
|
|
553 ALenum enum_parameter;
|
|
554 int openal_primitive_type;
|
|
555
|
|
556 enum_parameter = lua_tointeger(lua_state, 1);
|
|
557
|
|
558 openal_primitive_type = lua_getTypeForEnum(enum_parameter);
|
|
559
|
|
560 switch(openal_primitive_type)
|
|
561 {
|
|
562 case LUAOPENAL_BOOL_TYPE:
|
|
563 {
|
|
564 ALboolean ret_val;
|
|
565 ret_val = alGetBoolean(enum_parameter);
|
|
566 lua_pushboolean(lua_state, ret_val);
|
|
567 return 1;
|
|
568 break;
|
|
569 }
|
|
570 case LUAOPENAL_INT_TYPE:
|
|
571 {
|
|
572 ALint ret_val;
|
|
573 ret_val = alGetInteger(enum_parameter);
|
|
574 lua_pushinteger(lua_state, ret_val);
|
|
575 return 1;
|
|
576 break;
|
|
577 }
|
|
578 case LUAOPENAL_FLOAT_TYPE:
|
|
579 {
|
|
580 ALfloat ret_val;
|
|
581 ret_val = alGetFloat(enum_parameter);
|
|
582 lua_pushnumber(lua_state, ret_val);
|
|
583 return 1;
|
|
584 break;
|
|
585 }
|
|
586 case LUAOPENAL_INT_3_TYPE:
|
|
587 {
|
|
588 ALint ret_val[3];
|
|
589 alGetIntegerv(enum_parameter, ret_val);
|
|
590 lua_pushinteger(lua_state, ret_val[0]);
|
|
591 lua_pushinteger(lua_state, ret_val[1]);
|
|
592 lua_pushinteger(lua_state, ret_val[2]);
|
|
593 return 3;
|
|
594 break;
|
|
595 }
|
|
596 case LUAOPENAL_FLOAT_3_TYPE:
|
|
597 {
|
|
598 ALfloat ret_val[3];
|
|
599 alGetFloatv(enum_parameter, ret_val);
|
|
600 lua_pushnumber(lua_state, ret_val[0]);
|
|
601 lua_pushnumber(lua_state, ret_val[1]);
|
|
602 lua_pushnumber(lua_state, ret_val[2]);
|
|
603 return 3;
|
|
604 break;
|
|
605 }
|
|
606 case LUAOPENAL_FLOAT_6_TYPE:
|
|
607 {
|
|
608 ALfloat ret_val[6];
|
|
609 alGetFloatv(enum_parameter, ret_val);
|
|
610 lua_pushnumber(lua_state, ret_val[0]);
|
|
611 lua_pushnumber(lua_state, ret_val[1]);
|
|
612 lua_pushnumber(lua_state, ret_val[2]);
|
|
613 lua_pushnumber(lua_state, ret_val[3]);
|
|
614 lua_pushnumber(lua_state, ret_val[4]);
|
|
615 lua_pushnumber(lua_state, ret_val[5]);
|
|
616 return 6;
|
|
617 break;
|
|
618 }
|
|
619 case LUAOPENAL_STRING_TYPE:
|
|
620 {
|
|
621 const ALchar* ret_val;
|
|
622 ret_val = alGetString(enum_parameter);
|
|
623 lua_pushstring(lua_state, ret_val);
|
|
624 return 1;
|
|
625 break;
|
|
626 }
|
|
627 default:
|
|
628 {
|
|
629 /* TODO: Figure out how to handle OpenAL extensions. */
|
|
630 luaL_error(lua_state, "Unhandled parameter type for alGetSource*");
|
|
631 }
|
|
632 }
|
|
633 return 0;
|
|
634 }
|
|
635
|
|
636 static const luaL_reg luaALFuncs[] =
|
|
637 {
|
|
638 { "Enable", lua_alEnable },
|
|
639 { "Disable", lua_alDisable },
|
|
640 { "IsEnabled", lua_alIsEnabled },
|
|
641 { "Get", lua_alGet },
|
|
642 { "GetError", lua_alGetError },
|
|
643 { "IsExtensionPresent", lua_alIsExtensionPresent },
|
|
644 { "GetEnumValue", lua_alGetEnumValue },
|
|
645 { "Listener", lua_alListener },
|
|
646 { "GetListener", lua_alGetListener },
|
|
647 { "Source", lua_alSource },
|
|
648 { "GetSource", lua_alGetSource },
|
|
649 { "DopplerFactor", lua_alDopplerFactor },
|
|
650 { "DopplerVelocity", lua_alDopplerVelocity },
|
|
651 { "SpeedOfSound", lua_alSpeedOfSound },
|
|
652 { "DistanceModel", lua_alDistanceModel },
|
|
653 { "DopplerVelocity", lua_alDopplerVelocity },
|
|
654 {NULL, NULL}
|
|
655 };
|
|
656
|
|
657
|
|
658 int luaopen_luaal(lua_State *L)
|
|
659 {
|
|
660 luaL_register(L, "al", luaALFuncs);
|
|
661
|
|
662 luaopenal_initenum(L, s_luaALEnum);
|
|
663
|
|
664 lua_pushstring(L, "_VERSION");
|
|
665 lua_pushstring(L, LUAAL_VERSION);
|
|
666 lua_settable(L,-3);
|
|
667
|
|
668 return 1;
|
|
669 }
|
|
670
|
|
671
|