diff options
Diffstat (limited to 'src/library_openal.js')
-rw-r--r-- | src/library_openal.js | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/src/library_openal.js b/src/library_openal.js index 6bd0f6b0..3d3c11f2 100644 --- a/src/library_openal.js +++ b/src/library_openal.js @@ -57,6 +57,7 @@ var LibraryOpenAL = { } if (ctx) { + ctx.listener.panningModel = "equalpower"; AL.contexts.push({ctx: ctx, err: 0, src: [], buf: []}); return AL.contexts.length; } else { @@ -81,7 +82,7 @@ var LibraryOpenAL = { return; } for (var i = 0; i < count; ++i) { - var sourceIdx = {{{ makeGetValue('sources', 'i', 'i32') }}} - 1; + var sourceIdx = {{{ makeGetValue('sources', 'i*4', 'i32') }}} - 1; delete AL.currentContext.src[sourceIdx]; } }, @@ -196,15 +197,15 @@ var LibraryOpenAL = { case 0x1004 /* AL_POSITION */: AL.currentContext.src[source - 1].panner.setPosition( {{{ makeGetValue('value', '0', 'float') }}}, - {{{ makeGetValue('value', '1', 'float') }}}, - {{{ makeGetValue('value', '2', 'float') }}} + {{{ makeGetValue('value', '4', 'float') }}}, + {{{ makeGetValue('value', '8', 'float') }}} ); break; case 0x1006 /* AL_VELOCITY */: AL.currentContext.src[source - 1].panner.setVelocity( {{{ makeGetValue('value', '0', 'float') }}}, - {{{ makeGetValue('value', '1', 'float') }}}, - {{{ makeGetValue('value', '2', 'float') }}} + {{{ makeGetValue('value', '4', 'float') }}}, + {{{ makeGetValue('value', '8', 'float') }}} ); break; default: @@ -235,7 +236,7 @@ var LibraryOpenAL = { return; } for (var i = 0; i < count; ++i) { - var buffer = {{{ makeGetValue('buffers', 'i', 'i32') }}}; + var buffer = {{{ makeGetValue('buffers', 'i*4', 'i32') }}}; if (buffer > AL.currentContext.buf.length) { #if OPENAL_DEBUG console.error("alSourceQueueBuffers called with an invalid buffer"); @@ -287,7 +288,7 @@ var LibraryOpenAL = { return; } for (var i = 0; i < count; ++i) { - var bufferIdx = {{{ makeGetValue('buffers', 'i', 'i32') }}} - 1; + var bufferIdx = {{{ makeGetValue('buffers', 'i*4', 'i32') }}} - 1; var buffer = AL.currentContext.buf[bufferIdx].buf; for (var j = 0; j < AL.currentContext.src.length; ++j) { if (buffer == AL.currentContext.src[j].buffer) { @@ -385,14 +386,18 @@ var LibraryOpenAL = { return; } var offset = 0; - if ("src" in AL.currentContext.src[source - 1]) { - // If the source is already playing, we need to resume from beginning. - // We do that by stopping the current source and replaying it. - _alSourceStop(source); - } else if (AL.currentContext.src[source - 1].paused) { - // So now we have to resume playback, remember the offset here. - offset = AL.currentContext.src[source - 1].pausedTime - - AL.currentContext.src[source - 1].playTime; + if ("src" in AL.currentContext.src[source - 1] && + AL.currentContext.src[source - 1]["src"].buffer == + AL.currentContext.src[source - 1].buffer) { + if (AL.currentContext.src[source - 1].paused) { + // So now we have to resume playback, remember the offset here. + offset = AL.currentContext.src[source - 1].pausedTime - + AL.currentContext.src[source - 1].playTime; + } else { + // If the source is already playing, we need to resume from beginning. + // We do that by stopping the current source and replaying it. + _alSourceStop(source); + } } var src = AL.currentContext.ctx.createBufferSource(); src.loop = AL.currentContext.src[source - 1].loop; @@ -513,9 +518,43 @@ var LibraryOpenAL = { }, alListenerfv: function(param, values) { + if (!AL.currentContext) { #if OPENAL_DEBUG - console.log("alListenerfv is not supported yet"); + console.error("alListenerfv called without a valid context"); #endif + return; + } + switch (param) { + case 0x1004 /* AL_POSITION */: + AL.currentContext.ctx.listener.setPosition( + {{{ makeGetValue('values', '0', 'float') }}}, + {{{ makeGetValue('values', '4', 'float') }}}, + {{{ makeGetValue('values', '8', 'float') }}} + ); + break; + case 0x1006 /* AL_VELOCITY */: + AL.currentContext.ctx.listener.setVelocity( + {{{ makeGetValue('values', '0', 'float') }}}, + {{{ makeGetValue('values', '4', 'float') }}}, + {{{ makeGetValue('values', '8', 'float') }}} + ); + break; + case 0x100F /* AL_ORIENTATION */: + AL.currentContext.ctx.listener.setOrientation( + {{{ makeGetValue('values', '0', 'float') }}}, + {{{ makeGetValue('values', '4', 'float') }}}, + {{{ makeGetValue('values', '8', 'float') }}}, + {{{ makeGetValue('values', '12', 'float') }}}, + {{{ makeGetValue('values', '16', 'float') }}}, + {{{ makeGetValue('values', '20', 'float') }}} + ); + break; + default: +#if OPENAL_DEBUG + console.log("alListenerfv with param " + param + " not implemented yet"); +#endif + break; + } }, alIsExtensionPresent: function(extName) { |