aboutsummaryrefslogtreecommitdiff
path: root/src/library_openal.js
diff options
context:
space:
mode:
authorÉloi Rivard <azmeuk@gmail.com>2013-04-02 16:03:00 +0200
committerÉloi Rivard <azmeuk@gmail.com>2013-04-05 10:25:27 +0200
commit1ccc910e34f9c6e874848cecdd2c5d48eb27a981 (patch)
treed07f1b891049ec79240d7b871dc19a10435d7473 /src/library_openal.js
parent727c68db5fcd62fa797ef8cf72e57b6b7746dc9d (diff)
* Fixed alcGetCurrentContext.
Diffstat (limited to 'src/library_openal.js')
-rw-r--r--src/library_openal.js187
1 files changed, 91 insertions, 96 deletions
diff --git a/src/library_openal.js b/src/library_openal.js
index 5e76eee6..87393291 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -4,24 +4,19 @@ var LibraryOpenAL = {
$AL__deps: ['$Browser'],
$AL: {
contexts: [],
- currentContext: null,
+ currentContext: 0,
},
alcProcessContext: function(context) {},
alcSuspendContext: function(context) {},
alcMakeContextCurrent: function(context) {
- if (context == 0) {
- AL.currentContext = null;
- return 0;
- } else {
- AL.currentContext = AL.contexts[context - 1];
- return 1;
- }
+ AL.currentContext = context;
+ return (context > 0);
},
alcGetContextsDevice: function(context) {
- if (context < AL.contexts.length && context >= 0) {
+ if (context <= AL.contexts.length && context > 0) {
// Returns the only one audio device
return 1;
}
@@ -79,10 +74,10 @@ var LibraryOpenAL = {
},
alGetError: function() {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
return 0xA004 /* AL_INVALID_OPERATION */;
} else {
- return AL.currentContext.err;
+ return AL.contexts[AL.currentContext -1].err;
}
},
@@ -94,7 +89,7 @@ var LibraryOpenAL = {
alDeleteSources: function(count, sources)
{
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alDeleteSources called without a valid context");
#endif
@@ -102,26 +97,26 @@ var LibraryOpenAL = {
}
for (var i = 0; i < count; ++i) {
var sourceIdx = {{{ makeGetValue('sources', 'i*4', 'i32') }}} - 1;
- delete AL.currentContext.src[sourceIdx];
+ delete AL.contexts[AL.currentContext -1].src[sourceIdx];
}
},
alGenSources: function(count, sources) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alGenSources called without a valid context");
#endif
return;
}
for (var i = 0; i < count; ++i) {
- var gain = AL.currentContext.ctx.createGain();
- var panner = AL.currentContext.ctx.createPanner();
+ var gain = AL.contexts[AL.currentContext -1].ctx.createGain();
+ var panner = AL.contexts[AL.currentContext -1].ctx.createPanner();
panner.panningModel = "equalpower";
panner.distanceModel = "linear";
panner.rolloffFactor = 0.3;
gain.connect(panner);
- panner.connect(AL.currentContext.ctx.destination);
- AL.currentContext.src.push({
+ panner.connect(AL.contexts[AL.currentContext -1].ctx.destination);
+ AL.contexts[AL.currentContext -1].src.push({
loop: false,
buffer: null,
gain: gain,
@@ -130,18 +125,18 @@ var LibraryOpenAL = {
playTime: -1,
pausedTime: 0
});
- {{{ makeSetValue('sources', 'i*4', 'AL.currentContext.src.length', 'i32') }}};
+ {{{ makeSetValue('sources', 'i*4', 'AL.contexts[AL.currentContext -1].src.length', 'i32') }}};
}
},
alSourcei: function(source, param, value) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alSourcei called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].src.length) {
#if OPENAL_DEBUG
console.error("alSourcei called with an invalid source");
#endif
@@ -149,13 +144,13 @@ var LibraryOpenAL = {
}
switch (param) {
case 0x1007 /* AL_LOOPING */:
- AL.currentContext.src[source - 1].loop = (value != 0 /* AL_FALSE */);
+ AL.contexts[AL.currentContext -1].src[source - 1].loop = (value != 0 /* AL_FALSE */);
break;
case 0x1009 /* AL_BUFFER */:
if (value == 0) {
- AL.currentContext.src[source - 1].buffer = null;
+ AL.contexts[AL.currentContext -1].src[source - 1].buffer = null;
} else {
- AL.currentContext.src[source - 1].buffer = AL.currentContext.buf[value - 1].buf;
+ AL.contexts[AL.currentContext -1].src[source - 1].buffer = AL.contexts[AL.currentContext -1].buf[value - 1].buf;
}
break;
default:
@@ -167,13 +162,13 @@ var LibraryOpenAL = {
},
alSourcef: function(source, param, value) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alSourcef called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].src.length) {
#if OPENAL_DEBUG
console.error("alSourcef called with an invalid source");
#endif
@@ -181,7 +176,7 @@ var LibraryOpenAL = {
}
switch (param) {
case 0x100A /* AL_GAIN */:
- AL.currentContext.src[source - 1].gain.gain.value = value;
+ AL.contexts[AL.currentContext -1].src[source - 1].gain.gain.value = value;
break;
case 0x1003 /* AL_PITCH */:
#if OPENAL_DEBUG
@@ -197,13 +192,13 @@ var LibraryOpenAL = {
},
alSourcefv: function(source, param, value) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alSourcefv called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].src.length) {
#if OPENAL_DEBUG
console.error("alSourcefv called with an invalid source");
#endif
@@ -211,14 +206,14 @@ var LibraryOpenAL = {
}
switch (param) {
case 0x1004 /* AL_POSITION */:
- AL.currentContext.src[source - 1].panner.setPosition(
+ AL.contexts[AL.currentContext -1].src[source - 1].panner.setPosition(
{{{ makeGetValue('value', '0', 'float') }}},
{{{ makeGetValue('value', '4', 'float') }}},
{{{ makeGetValue('value', '8', 'float') }}}
);
break;
case 0x1006 /* AL_VELOCITY */:
- AL.currentContext.src[source - 1].panner.setVelocity(
+ AL.contexts[AL.currentContext -1].src[source - 1].panner.setVelocity(
{{{ makeGetValue('value', '0', 'float') }}},
{{{ makeGetValue('value', '4', 'float') }}},
{{{ makeGetValue('value', '8', 'float') }}}
@@ -233,13 +228,13 @@ var LibraryOpenAL = {
},
alSourceQueueBuffers: function(source, count, buffers) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alSourceQueueBuffers called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].src.length) {
#if OPENAL_DEBUG
console.error("alSourceQueueBuffers called with an invalid source");
#endif
@@ -253,25 +248,25 @@ var LibraryOpenAL = {
}
for (var i = 0; i < count; ++i) {
var buffer = {{{ makeGetValue('buffers', 'i*4', 'i32') }}};
- if (buffer > AL.currentContext.buf.length) {
+ if (buffer > AL.contexts[AL.currentContext -1].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;
+ AL.contexts[AL.currentContext -1].src[source - 1].buffer = AL.contexts[AL.currentContext -1].buf[buffer - 1].buf;
}
},
alSourceUnqueueBuffers: function(source, count, buffers)
{
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alSourceUnqueueBuffers called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].src.length) {
#if OPENAL_DEBUG
console.error("alSourceUnqueueBuffers called with an invalid source");
#endif
@@ -284,11 +279,11 @@ var LibraryOpenAL = {
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) {
+ var buffer = AL.contexts[AL.currentContext -1].src[source - 1].buffer;
+ for (var j = 0; j < AL.contexts[AL.currentContext -1].buf.length; ++j) {
+ if (buffer == AL.contexts[AL.currentContext -1].buf[j].buf) {
{{{ makeSetValue('buffers', 'i*4', 'j+1', 'i32') }}};
- AL.currentContext.src[source - 1].buffer = null;
+ AL.contexts[AL.currentContext -1].src[source - 1].buffer = null;
break;
}
}
@@ -297,7 +292,7 @@ var LibraryOpenAL = {
alDeleteBuffers: function(count, buffers)
{
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alDeleteBuffers called without a valid context");
#endif
@@ -305,38 +300,38 @@ var LibraryOpenAL = {
}
for (var i = 0; i < count; ++i) {
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) {
- AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
+ var buffer = AL.contexts[AL.currentContext -1].buf[bufferIdx].buf;
+ for (var j = 0; j < AL.contexts[AL.currentContext -1].src.length; ++j) {
+ if (buffer == AL.contexts[AL.currentContext -1].src[j].buffer) {
+ AL.contexts[AL.currentContext -1].err = 0xA004 /* AL_INVALID_OPERATION */;
return;
}
}
- delete AL.currentContext.buf[bufferIdx];
+ delete AL.contexts[AL.currentContext -1].buf[bufferIdx];
}
},
alGenBuffers: function(count, buffers) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#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*4', 'AL.currentContext.buf.length', 'i32') }}};
+ AL.contexts[AL.currentContext -1].buf.push({buf: null});
+ {{{ makeSetValue('buffers', 'i*4', 'AL.contexts[AL.currentContext -1].buf.length', 'i32') }}};
}
},
alBufferData: function(buffer, format, data, size, freq) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alBufferData called without a valid context");
#endif
return;
}
- if (buffer > AL.currentContext.buf.length) {
+ if (buffer > AL.contexts[AL.currentContext -1].buf.length) {
#if OPENAL_DEBUG
console.error("alBufferData called with an invalid buffer");
#endif
@@ -366,10 +361,10 @@ var LibraryOpenAL = {
#endif
return;
}
- AL.currentContext.buf[buffer - 1].buf = AL.currentContext.ctx.createBuffer(channels, size / (bytes * channels), freq);
+ AL.contexts[AL.currentContext -1].buf[buffer - 1].buf = AL.contexts[AL.currentContext -1].ctx.createBuffer(channels, size / (bytes * channels), freq);
var buf = new Array(channels);
for (var i = 0; i < channels; ++i) {
- buf[i] = AL.currentContext.buf[buffer - 1].buf.getChannelData(i);
+ buf[i] = AL.contexts[AL.currentContext -1].buf[buffer - 1].buf.getChannelData(i);
}
for (var i = 0; i < size / (bytes * channels); ++i) {
for (var j = 0; j < channels; ++j) {
@@ -389,91 +384,91 @@ var LibraryOpenAL = {
alSourcePlay__deps: ["alSourceStop"],
alSourcePlay: function(source) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alSourcePlay called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].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] &&
- AL.currentContext.src[source - 1]["src"].buffer ==
- AL.currentContext.src[source - 1].buffer) {
- if (AL.currentContext.src[source - 1].paused) {
+ if ("src" in AL.contexts[AL.currentContext -1].src[source - 1] &&
+ AL.contexts[AL.currentContext -1].src[source - 1]["src"].buffer ==
+ AL.contexts[AL.currentContext -1].src[source - 1].buffer) {
+ if (AL.contexts[AL.currentContext -1].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;
+ offset = AL.contexts[AL.currentContext -1].src[source - 1].pausedTime -
+ AL.contexts[AL.currentContext -1].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;
- src.buffer = AL.currentContext.src[source - 1].buffer;
- src.connect(AL.currentContext.src[source - 1].gain);
+ var src = AL.contexts[AL.currentContext -1].ctx.createBufferSource();
+ src.loop = AL.contexts[AL.currentContext -1].src[source - 1].loop;
+ src.buffer = AL.contexts[AL.currentContext -1].src[source - 1].buffer;
+ src.connect(AL.contexts[AL.currentContext -1].src[source - 1].gain);
src.start(0, offset);
- AL.currentContext.src[source - 1].playTime = AL.currentContext.ctx.currentTime;
- AL.currentContext.src[source - 1].paused = false;
- AL.currentContext.src[source - 1]['src'] = src;
+ AL.contexts[AL.currentContext -1].src[source - 1].playTime = AL.contexts[AL.currentContext -1].ctx.currentTime;
+ AL.contexts[AL.currentContext -1].src[source - 1].paused = false;
+ AL.contexts[AL.currentContext -1].src[source - 1]['src'] = src;
},
alSourceStop: function(source) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alSourceStop called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].src.length) {
#if OPENAL_DEBUG
console.error("alSourceStop called with an invalid source");
#endif
return;
}
- if ("src" in AL.currentContext.src[source - 1]) {
- AL.currentContext.src[source - 1]["src"].stop(0);
- delete AL.currentContext.src[source - 1]["src"];
+ if ("src" in AL.contexts[AL.currentContext -1].src[source - 1]) {
+ AL.contexts[AL.currentContext -1].src[source - 1]["src"].stop(0);
+ delete AL.contexts[AL.currentContext -1].src[source - 1]["src"];
}
},
alSourcePause: function(source) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alSourcePause called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].src.length) {
#if OPENAL_DEBUG
console.error("alSourcePause called with an invalid source");
#endif
return;
}
- if ("src" in AL.currentContext.src[source - 1] &&
- !AL.currentContext.src[source - 1].paused) {
- AL.currentContext.src[source - 1].paused = true;
- AL.currentContext.src[source - 1].pausedTime = AL.currentContext.ctx.currentTime;
- AL.currentContext.src[source - 1]["src"].stop(0);
- delete AL.currentContext.src[source - 1].src;
+ if ("src" in AL.contexts[AL.currentContext -1].src[source - 1] &&
+ !AL.contexts[AL.currentContext -1].src[source - 1].paused) {
+ AL.contexts[AL.currentContext -1].src[source - 1].paused = true;
+ AL.contexts[AL.currentContext -1].src[source - 1].pausedTime = AL.contexts[AL.currentContext -1].ctx.currentTime;
+ AL.contexts[AL.currentContext -1].src[source - 1]["src"].stop(0);
+ delete AL.contexts[AL.currentContext -1].src[source - 1].src;
}
},
alGetSourcei: function(source, param, value) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alGetSourcei called without a valid context");
#endif
return;
}
- if (source > AL.currentContext.src.length) {
+ if (source > AL.contexts[AL.currentContext -1].src.length) {
#if OPENAL_DEBUG
console.error("alGetSourcei called with an invalid source");
#endif
@@ -485,12 +480,12 @@ var LibraryOpenAL = {
{{{ makeSetValue('value', '0', '1', 'i32') }}};
break;
case 0x1009 /* AL_BUFFER */:
- if (AL.currentContext.src[source - 1].buffer == null) {
+ if (AL.contexts[AL.currentContext -1].src[source - 1].buffer == null) {
{{{ makeSetValue('value', '0', '0', 'i32') }}};
} else {
- var buf = AL.currentContext.src[source - 1].buffer;
- for (var i = 0; i < AL.currentContext.buf.length; ++i) {
- if (buf == AL.currentContext.buf[i].buf) {
+ var buf = AL.contexts[AL.currentContext -1].src[source - 1].buffer;
+ for (var i = 0; i < AL.contexts[AL.currentContext -1].buf.length; ++i) {
+ if (buf == AL.contexts[AL.currentContext -1].buf[i].buf) {
{{{ makeSetValue('value', '0', 'i+1', 'i32') }}};
return;
}
@@ -499,18 +494,18 @@ var LibraryOpenAL = {
}
break;
case 0x1010 /* AL_SOURCE_STATE */:
- if ("src" in AL.currentContext.src[source - 1]) {
+ if ("src" in AL.contexts[AL.currentContext -1].src[source - 1]) {
{{{ makeSetValue('value', '0', '0x1012', 'i32') }}} /* AL_PLAYING */;
- } else if (AL.currentContext.src[source - 1].paused) {
+ } else if (AL.contexts[AL.currentContext -1].src[source - 1].paused) {
{{{ makeSetValue('value', '0', '0x1013', 'i32') }}} /* AL_PAUSED */;
- } else if (AL.currentContext.src[source - 1].playTime == -1) {
+ } else if (AL.contexts[AL.currentContext -1].src[source - 1].playTime == -1) {
{{{ makeSetValue('value', '0', '0x1011', 'i32') }}} /* AL_INITIAL */;
} else {
{{{ makeSetValue('value', '0', '0x1014', 'i32') }}} /* AL_STOPPED */;
}
break;
case 0x1015 /* AL_BUFFERS_QUEUED */:
- if (AL.currentContext.src[source - 1].buffer) {
+ if (AL.contexts[AL.currentContext -1].src[source - 1].buffer) {
{{{ makeSetValue('value', '0', '1', 'i32') }}}
} else {
{{{ makeSetValue('value', '0', '0', 'i32') }}}
@@ -532,7 +527,7 @@ var LibraryOpenAL = {
},
alListenerfv: function(param, values) {
- if (!AL.currentContext) {
+ if (AL.currentContext == 0) {
#if OPENAL_DEBUG
console.error("alListenerfv called without a valid context");
#endif
@@ -540,21 +535,21 @@ var LibraryOpenAL = {
}
switch (param) {
case 0x1004 /* AL_POSITION */:
- AL.currentContext.ctx.listener.setPosition(
+ AL.contexts[AL.currentContext -1].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(
+ AL.contexts[AL.currentContext -1].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(
+ AL.contexts[AL.currentContext -1].ctx.listener.setOrientation(
{{{ makeGetValue('values', '0', 'float') }}},
{{{ makeGetValue('values', '4', 'float') }}},
{{{ makeGetValue('values', '8', 'float') }}},