Skip to content

Commit be5bc3b

Browse files
ehsankripken
authored andcommitted
Implement alGetSourcei
1 parent 00a39d2 commit be5bc3b

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/library_openal.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var LibraryOpenAL = {
9292
gain: gain,
9393
panner: panner,
9494
paused: false,
95-
playTime: 0,
95+
playTime: -1,
9696
pausedTime: 0
9797
});
9898
{{{ makeSetValue('sources', 'i', 'AL.currentContext.src.length', 'i32') }}};
@@ -326,6 +326,59 @@ var LibraryOpenAL = {
326326
}
327327
},
328328

329+
alGetSourcei: function(source, param, value) {
330+
if (!AL.currentContext) {
331+
console.error("alGetSourcei called without a valid context");
332+
return;
333+
}
334+
if (source > AL.currentContext.src.length) {
335+
console.error("alGetSourcei called with an invalid source");
336+
return;
337+
}
338+
switch (param) {
339+
case 0x202 /* AL_SOURCE_RELATIVE */:
340+
// Always return 1
341+
{{{ makeSetValue('value', '0', '1', 'i32') }}};
342+
break;
343+
case 0x1009 /* AL_BUFFER */:
344+
if (AL.currentContext.src[source - 1].buffer == null) {
345+
{{{ makeSetValue('value', '0', '0', 'i32') }}};
346+
} else {
347+
var buf = AL.currentContext.src[source - 1].buffer;
348+
for (var i = 0; i < AL.currentContext.buf.length; ++i) {
349+
if (buf == AL.currentContext.buf[i].buf) {
350+
{{{ makeSetValue('value', '0', 'i+1', 'i32') }}};
351+
return;
352+
}
353+
}
354+
{{{ makeSetValue('value', '0', '0', 'i32') }}};
355+
}
356+
break;
357+
case 0x1010 /* AL_SOURCE_STATE */:
358+
if ("src" in AL.currentContext.src[source - 1]) {
359+
{{{ makeSetValue('value', '0', '0x1012', 'i32') }}} /* AL_PLAYING */;
360+
} else if (AL.currentContext.src[source - 1].paused) {
361+
{{{ makeSetValue('value', '0', '0x1013', 'i32') }}} /* AL_PAUSED */;
362+
} else if (AL.currentContext.src[source - 1].playTime == -1) {
363+
{{{ makeSetValue('value', '0', '0x1011', 'i32') }}} /* AL_INITIAL */;
364+
} else {
365+
{{{ makeSetValue('value', '0', '0x1014', 'i32') }}} /* AL_STOPPED */;
366+
}
367+
break;
368+
case 0x1015 /* AL_BUFFERS_QUEUED */:
369+
if (AL.currentContext.src[source - 1].buffer) {
370+
{{{ makeSetValue('value', '0', '1', 'i32') }}}
371+
} else {
372+
{{{ makeSetValue('value', '0', '0', 'i32') }}}
373+
}
374+
break;
375+
case 0x1016 /* AL_BUFFERS_PROCESSED */:
376+
// Always return 1
377+
{{{ makeSetValue('value', '0', '1', 'i32') }}}
378+
break;
379+
}
380+
},
381+
329382
alDistanceModel: function(model) {
330383
if (model != 0 /* AL_NONE */) {
331384
console.log("Only alDistanceModel(AL_NONE) is currently supported");

0 commit comments

Comments
 (0)