aboutsummaryrefslogtreecommitdiff
path: root/src/library_openal.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-20 13:44:50 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-03-20 13:44:50 -0700
commit669c786e3554b280e31dcb7bd92931482547dae0 (patch)
tree110d48a9e6bf29ceed41ac6282dc37d2f0f3f433 /src/library_openal.js
parentb22f6fbbbebb5df55ceb8fdc9f7c4d111c902c5e (diff)
parent421e70ecf266d6619415b53c1bc03d4a127a585d (diff)
Merge branch 'incoming'
Diffstat (limited to 'src/library_openal.js')
-rw-r--r--src/library_openal.js154
1 files changed, 133 insertions, 21 deletions
diff --git a/src/library_openal.js b/src/library_openal.js
index 5511ccb7..719d8cf8 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -41,7 +41,9 @@ var LibraryOpenAL = {
}
if (attrList) {
+#if OPENAL_DEBUG
console.log("The attrList argument of alcCreateContext is not supported yet");
+#endif
return 0;
}
@@ -55,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 {
@@ -73,18 +76,22 @@ var LibraryOpenAL = {
alDeleteSources: function(count, sources)
{
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alDeleteSources called without a valid context");
+#endif
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];
}
},
alGenSources: function(count, sources) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alGenSources called without a valid context");
+#endif
return;
}
for (var i = 0; i < count; ++i) {
@@ -107,17 +114,21 @@ var LibraryOpenAL = {
playTime: -1,
pausedTime: 0
});
- {{{ makeSetValue('sources', 'i', 'AL.currentContext.src.length', 'i32') }}};
+ {{{ makeSetValue('sources', 'i*4', 'AL.currentContext.src.length', 'i32') }}};
}
},
alSourcei: function(source, param, value) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alSourcei called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alSourcei called with an invalid source");
+#endif
return;
}
switch (param) {
@@ -132,18 +143,24 @@ var LibraryOpenAL = {
}
break;
default:
+#if OPENAL_DEBUG
console.log("alSourcei with param " + param + " not implemented yet");
+#endif
break;
}
},
alSourcef: function(source, param, value) {
if (!AL.currentContext) {
- consoue.error("alSourcef called without a valid context");
+#if OPENAL_DEBUG
+ console.error("alSourcef called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alSourcef called with an invalid source");
+#endif
return;
}
switch (param) {
@@ -151,61 +168,79 @@ var LibraryOpenAL = {
AL.currentContext.src[source - 1].gain.gain.value = value;
break;
case 0x1003 /* AL_PITCH */:
+#if OPENAL_DEBUG
console.log("alSourcef was called with AL_PITCH, but Web Audio does not support static pitch changes");
+#endif
break;
default:
+#if OPENAL_DEBUG
console.log("alSourcef with param " + param + " not implemented yet");
+#endif
break;
}
},
alSourcefv: function(source, param, value) {
if (!AL.currentContext) {
- consoue.error("alSourcefv called without a valid context");
+#if OPENAL_DEBUG
+ console.error("alSourcefv called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alSourcefv called with an invalid source");
+#endif
return;
}
switch (param) {
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:
+#if OPENAL_DEBUG
console.log("alSourcefv with param " + param + " not implemented yet");
+#endif
break;
}
},
alSourceQueueBuffers: function(source, count, buffers) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alSourceQueueBuffers called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alSourceQueueBuffers called with an invalid source");
+#endif
return;
}
if (count != 1) {
+#if OPENAL_DEBUG
console.error("Queuing multiple buffers using alSourceQueueBuffers is not supported yet");
+#endif
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");
+#endif
return;
}
AL.currentContext.src[source - 1].buffer = AL.currentContext.buf[buffer - 1].buf;
@@ -215,22 +250,28 @@ var LibraryOpenAL = {
alSourceUnqueueBuffers: function(source, count, buffers)
{
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alSourceUnqueueBuffers called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alSourceUnqueueBuffers called with an invalid source");
+#endif
return;
}
if (count != 1) {
+#if OPENAL_DEBUG
console.error("Queuing multiple buffers using alSourceUnqueueBuffers is not supported yet");
+#endif
return;
}
for (var i = 0; i < count; ++i) {
var buffer = AL.currentContext.src[source - 1].buffer;
for (var j = 0; j < AL.currentContext.buf.length; ++j) {
if (buffer == AL.currentContext.buf[j].buf) {
- {{{ makeSetValue('buffers', 'i', 'j+1', 'i32') }}};
+ {{{ makeSetValue('buffers', 'i*4', 'j+1', 'i32') }}};
AL.currentContext.src[source - 1].buffer = null;
break;
}
@@ -241,11 +282,13 @@ var LibraryOpenAL = {
alDeleteBuffers: function(count, buffers)
{
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alDeleteBuffers called without a valid context");
+#endif
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) {
@@ -259,22 +302,28 @@ var LibraryOpenAL = {
alGenBuffers: function(count, buffers) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alGenBuffers called without a valid context");
+#endif
return;
}
for (var i = 0; i < count; ++i) {
AL.currentContext.buf.push({buf: null});
- {{{ makeSetValue('buffers', 'i', 'AL.currentContext.buf.length', 'i32') }}};
+ {{{ makeSetValue('buffers', 'i*4', 'AL.currentContext.buf.length', 'i32') }}};
}
},
alBufferData: function(buffer, format, data, size, freq) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alBufferData called without a valid context");
+#endif
return;
}
if (buffer > AL.currentContext.buf.length) {
+#if OPENAL_DEBUG
console.error("alBufferData called with an invalid buffer");
+#endif
return;
}
var channels, bytes;
@@ -296,7 +345,9 @@ var LibraryOpenAL = {
channels = 2;
break;
default:
+#if OPENAL_DEBUG
console.error("alBufferData called with invalid format " + format);
+#endif
return;
}
AL.currentContext.buf[buffer - 1].buf = AL.currentContext.ctx.createBuffer(channels, size / (bytes * channels), freq);
@@ -323,22 +374,30 @@ var LibraryOpenAL = {
alSourcePlay__deps: ["alSourceStop"],
alSourcePlay: function(source) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alSourcePlay called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alSourcePlay called with an invalid source");
+#endif
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;
@@ -353,11 +412,15 @@ var LibraryOpenAL = {
alSourceStop: function(source) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alSourceStop called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alSourceStop called with an invalid source");
+#endif
return;
}
if ("src" in AL.currentContext.src[source - 1]) {
@@ -368,11 +431,15 @@ var LibraryOpenAL = {
alSourcePause: function(source) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alSourcePause called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alSourcePause called with an invalid source");
+#endif
return;
}
if ("src" in AL.currentContext.src[source - 1] &&
@@ -387,11 +454,15 @@ var LibraryOpenAL = {
alGetSourcei: function(source, param, value) {
if (!AL.currentContext) {
+#if OPENAL_DEBUG
console.error("alGetSourcei called without a valid context");
+#endif
return;
}
if (source > AL.currentContext.src.length) {
+#if OPENAL_DEBUG
console.error("alGetSourcei called with an invalid source");
+#endif
return;
}
switch (param) {
@@ -440,12 +511,50 @@ var LibraryOpenAL = {
alDistanceModel: function(model) {
if (model != 0 /* AL_NONE */) {
+#if OPENAL_DEBUG
console.log("Only alDistanceModel(AL_NONE) is currently supported");
+#endif
}
},
alListenerfv: function(param, values) {
- console.log("alListenerfv is not supported yet");
+ if (!AL.currentContext) {
+#if OPENAL_DEBUG
+ 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) {
@@ -464,6 +573,9 @@ var LibraryOpenAL = {
return 0;
},
+ alcGetError: function(device) {
+ return 0;
+ },
};
autoAddDeps(LibraryOpenAL, '$AL');