Commit 3a8d7d38 authored by Brateau Etienne's avatar Brateau Etienne Committed by Jean-Baptiste Kempf
Browse files

Apply Emscripten PR #5367 : Significant overhaul of the OpenAL implementation

parent 152bd6c0
From 5581631cc23d5e91035e269a1514598c2235f29a Mon Sep 17 00:00:00 2001
From: Jameson Ernst <jameson@jpernst.com>
Date: Fri, 7 Jul 2017 11:21:55 -0700
Subject: [PATCH 06/23] Add -Os flag to al.c
---
tools/system_libs.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/system_libs.py b/tools/system_libs.py
index 65ff8f8d0..99bbbbdbd 100755
--- a/tools/system_libs.py
+++ b/tools/system_libs.py
@@ -257,7 +257,7 @@ def calculate(temp_files, in_temp, stdout_, stderr_, forced=[]):
# al
def create_al(libname): # libname is ignored, this is just one .o file
o = in_temp('al.o')
- check_call([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', 'al.c'), '-o', o])
+ check_call([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', 'al.c'), '-o', o, '-Os'])
return o
def create_html5(libname):
--
2.14.1
From 5b6004917512f7de3548702e02c4753fb5a638f2 Mon Sep 17 00:00:00 2001
From: Jameson Ernst <jameson@jpernst.com>
Date: Fri, 7 Jul 2017 11:49:02 -0700
Subject: [PATCH 07/23] Minor fix to AL panner initialization when source has
leading zero-buffers
---
src/library_openal.js | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/library_openal.js b/src/library_openal.js
index c6e326fcc..7f65f6d67 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -376,8 +376,16 @@ var LibraryOpenAL = {
return;
}
+ // Find the first non-zero buffer in the queue to determine the proper format
+ var templateBuf = AL.buffers[0];
+ for (var i = 0; i < src.bufQueue.length; i++) {
+ if (src.bufQueue[i].id !== 0) {
+ templateBuf = src.bufQueue[i];
+ break;
+ }
+ }
// Create a panner if AL_SOURCE_SPATIALIZE_SOFT is set to true, or alternatively if it's set to auto and the source is mono
- if (src.spatialize === 1 /* AL_TRUE */ || (src.spatialize === 2 /* AL_AUTO_SOFT */ && src.bufQueue[0].channels === 1)) {
+ if (src.spatialize === 1 /* AL_TRUE */ || (src.spatialize === 2 /* AL_AUTO_SOFT */ && templateBuf.channels === 1)) {
if (src.panner) {
return;
}
--
2.14.1
From 45b70ef08c5a7ea75cc0c7e1869aa6aae3b09c15 Mon Sep 17 00:00:00 2001
From: yoanlcq <yoanlecoq.io@gmail.com>
Date: Mon, 10 Jul 2017 19:45:26 +0200
Subject: [PATCH 08/23] Change docs w.r.t juj's review
---
site/source/docs/porting/Audio.rst | 46 ++++++++++++--------------------------
1 file changed, 14 insertions(+), 32 deletions(-)
diff --git a/site/source/docs/porting/Audio.rst b/site/source/docs/porting/Audio.rst
index 43b55b8d7..241559efb 100644
--- a/site/source/docs/porting/Audio.rst
+++ b/site/source/docs/porting/Audio.rst
@@ -4,10 +4,13 @@
Audio
=====
-Emscripten supports OpenAL 1.1 "out of the box", with no additional compilation flag required. The implementation uses the Web Audio API.
+Emscripten ships with its own implementation of the OpenAL 1.1 API, using the Web Audio API as a backend.
-You can reasonably expect ported OpenAL applications to "just work" with no additional effort.
-However, there are some implementation-specific aspects which are worth considering - these are documented here.
+You can reasonably expect ported OpenAL applications to "just work" with no additional effort. Just link with the ``-lopenal`` linker flag.
+
+There are some implementation-specific aspects which are worth considering and are documented here.
+
+.. warning:: There used to be no additional flag to pass to the compiler in order to use OpenAL. However, specifying ``-lopenal`` as mentioned above should be considered mandatory (at some point in the future, it **will** be)!
.. _Audio-openal-extensions-g:
@@ -33,32 +36,21 @@ The following extensions are supported by Emscripten's OpenAL implementation.
Guidelines for Audio on Emscripten
==================================
-First: Do not loop on OpenAL calls.
+Know that your application needs to yield to the Javascript main loop for audio processing to take place (See :ref:`Browser main loop <emscripten-runtime-environment-main-loop>`).
-Put simply, avoid completely this kind of code :
+Put simply, this kind of code will block indefinitely :
.. code-block:: c
while(nframes < THE_NUMBER_OF_FRAMES_WE_WANT)
alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, 1, &nframes);
+The above snippet usually works in native applications because most OpenAL implementations own and manage one or more separate threads. This is **not** the case in Emscripten.
-The reason for this is simple: Your application needs to yield to the Javascript main loop for audio processing to take place (See :ref:`Browser main loop <emscripten-runtime-environment-main-loop>`).
-
-The above snippet usually works because most OpenAL implementations own and manage one or more separate threads. This is not the case in Emscripten.
What you must do instead is perform each such query only once per "main loop iteration" (i.e the callback you provide via :c:func:`emscripten_set_main_loop` or :c:func:`emscripten_set_main_loop_arg`).
-Second: Avoid creating and destroying resources relentlessly.
-
-On some browsers (except, apparently, Firefox), garbage collection does not occur as much as it should. Knowing this, your app should ideally at most use one ``ALCcontext`` for playback and one ``ALCdevice`` for capture.
-
-Even if you're planning to suspend audio capture or playback for extended periods of time, it is probably better to keep contexts in memory (unlike in native apps where you should rather destroy them) to avoid risking memory leaks caused by poorly garbage-collected Javascript implementations.
-
-Of course, the current OpenAL implementation strives to be memory-efficient, but it has no control over lower-level mechanisms involved.
-
-
.. _Audio-openal-capture-behavior-g:
Emscripten-specific capture behavior
@@ -66,11 +58,8 @@ Emscripten-specific capture behavior
Attempting to open an input stream to the user's audio capture device
results in the asynchronous appearance of a small browser-specific dialog
-asking for the user's permission.
+asking for the user's permission, and on some browsers, the capture device to choose.
-.. note::
- On Firefox, the user is also given the opportunity to pick from a list of devices at that moment.
- On other browsers, this is normally a simple "Allow/Deny" button pair on a toast.
With this in mind, when ``alcCaptureOpenDevice()`` is called with valid and
supported parameters, a "proxy" device is returned, which successfully
@@ -81,7 +70,7 @@ That means, when calling ``alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, 1, &nfram
If the user clicks "Deny", the device is invalidated (because this is somewhat
similar to unplugging the physical device) and calls to ``alcCapture*`` functions on that
device then consistently fail with ``ALC_INVALID_DEVICE``.
-Your application must be prepared to handle this properly.
+Your application should be prepared to handle this properly.
.. note::
Some browsers "remember" this choice and apply it automatically every time it would be asked again instead.
@@ -94,16 +83,9 @@ Useful implementation details of OpenAL capture
===============================================
Internally, Web Audio's capture data is always backed by a Javascript ``Float32Array``.
-Thus, ``AL_FORMAT_MONO_FLOAT32`` and ``AL_FORMAT_STEREO_FLOAT32`` are the only formats which do not require running "type conversion passes" on acquired buffers.
-
-Note, however, that :
-
-- It's probably pointless to pick a stereo format for capture;
-- float32 samples use more memory than the standard 16-bit or 8-bit integer formats;
-- Most microphones aren't very high quality.
- Especially for real-time apps such as games, users will likely tolerate lower quality recordings.
+Thus, ``AL_FORMAT_MONO_FLOAT32`` and ``AL_FORMAT_STEREO_FLOAT32`` are the only formats which do not require converting acquired samples from their initial type to another.
-Also, the actual sample rate at which samples are acquired from the device is unpredictable and depends on many factors, including the user's browser and setup. If this sample rate does not match the one your app requests, the implementation is required to perform resampling on your behalf.
+Also, the actual sample rate at which samples are acquired from the device is currently dictated by the browser and hardware, instead of user code. If this sample rate does not match the one your app requests, the implementation is required to perform resampling on your behalf.
That sample rate is given by ``audioCtx.sampleRate``, where ``audioCtx`` is the ``AudioContext`` object used internally by the relevant capture ``ALCdevice``.
Currently, Emscripten provides no direct way for applications to access this value, but this might be provided through an Emscripten-specific OpenAL extension (which is not here yet because it requires registration).
@@ -138,6 +120,6 @@ Improving and extending the implementation
Currently, the OpenAL capture implementation performs naïve linear resampling because it is simple and the small loss of quality was deemed acceptable.
-However, you're welcome to improve this by contributing if you so wish!
+However, you're welcome to improve this by contributing if you so wish! See `this issue <https://github.com/kripken/emscripten/issues/5349>`_ , for instance.
Likewise, if you'd like to see a particlar extension implemented (whether it is registered or not), then your best bet is to either file an issue (provided no related prior issue existed for this), or contribute! See :ref:`Contributing <contributing>` for guidelines.
--
2.14.1
From e5e73b656f5843f199bbf9725637d3c4d475420b Mon Sep 17 00:00:00 2001
From: yoanlcq <yoanlecoq.io@gmail.com>
Date: Mon, 10 Jul 2017 20:32:31 +0200
Subject: [PATCH 09/23] First style fix pass
---
src/library_openal.js | 72 +++++++++++++++++++++++++--------------------------
1 file changed, 36 insertions(+), 36 deletions(-)
diff --git a/src/library_openal.js b/src/library_openal.js
index 7f65f6d67..9cbab90b3 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -410,7 +410,7 @@ var LibraryOpenAL = {
},
updateContextGlobal: function(ctx) {
- for (i in ctx.sources) {
+ for (var i in ctx.sources) {
AL.updateSourceGlobal(ctx.sources[i]);
}
},
@@ -638,7 +638,7 @@ var LibraryOpenAL = {
sourceDuration: function(src) {
var length = 0.0;
- for (i = 0; i < src.bufQueue.length; i++) {
+ for (var i = 0; i < src.bufQueue.length; i++) {
var audioBuf = src.bufQueue[i].audioBuf;
length += audioBuf ? audioBuf.duration : 0.0;
}
@@ -649,7 +649,7 @@ var LibraryOpenAL = {
AL.updateSourceTime(src);
var offset = 0.0;
- for (i = 0; i < src.bufsProcessed; i++) {
+ for (var i = 0; i < src.bufsProcessed; i++) {
offset += src.bufQueue[i].audioBuf.duration;
}
offset += src.bufOffset;
@@ -1063,7 +1063,7 @@ var LibraryOpenAL = {
case 0x2009 /* AL_BYTE_LENGTH_SOFT */:
var length = 0;
var bytesPerFrame = 0;
- for (i = 0; i < src.bufQueue.length; i++) {
+ for (var i = 0; i < src.bufQueue.length; i++) {
length += src.bufQueue[i].length;
if (src.bufQueue[i].id !== 0) {
bytesPerFrame = src.bufQueue[i].bytes * src.bufQueue[i].channels;
@@ -1072,7 +1072,7 @@ var LibraryOpenAL = {
return length * bytesPerFrame;
case 0x200A /* AL_SAMPLE_LENGTH_SOFT */:
var length = 0;
- for (i = 0; i < src.bufQueue.length; i++) {
+ for (var i = 0; i < src.bufQueue.length; i++) {
length += src.bufQueue[i].length;
}
return length;
@@ -1496,7 +1496,7 @@ var LibraryOpenAL = {
return null;
}
var c = AL.captures[deviceId];
- if(!c) {
+ if (!c) {
#if OPENAL_DEBUG
console.error(funcname+"() on an invalid device");
#endif
@@ -1504,7 +1504,7 @@ var LibraryOpenAL = {
return null;
}
var err = c.mediaStreamError;
- if(err) {
+ if (err) {
#if OPENAL_DEBUG
switch(err.name) {
case "PermissionDeniedError":
@@ -1541,9 +1541,9 @@ var LibraryOpenAL = {
var resolvedDeviceName = AL.CAPTURE_DEVICE_NAME;
// NULL is a valid device name here (resolves to default);
- if(pDeviceName !== 0) {
+ if (pDeviceName !== 0) {
resolvedDeviceName = Pointer_stringify(pDeviceName);
- if(resolvedDeviceName !== AL.CAPTURE_DEVICE_NAME) {
+ if (resolvedDeviceName !== AL.CAPTURE_DEVICE_NAME) {
#if OPENAL_DEBUG
console.error("alcCaptureOpenDevice() with invalid device name \""+resolvedDeviceName+"\"");
#endif
@@ -1585,7 +1585,7 @@ var LibraryOpenAL = {
var AudioContext = window.AudioContext || window.webkitAudioContext;
- if(!AL.sharedCaptureAudioCtx) {
+ if (!AL.sharedCaptureAudioCtx) {
try {
AL.sharedCaptureAudioCtx = new AudioContext();
} catch(e) {
@@ -1659,7 +1659,7 @@ var LibraryOpenAL = {
var buffers = [];
try {
- for(var chan=0 ; chan < outputChannelCount ; ++chan)
+ for (var chan=0 ; chan < outputChannelCount ; ++chan)
buffers[chan] = newSampleArray(bufferFrameCapacity);
} catch(e) {
#if OPENAL_DEBUG
@@ -1722,7 +1722,7 @@ var LibraryOpenAL = {
newCapture.inputChannelCount = inputChannelCount;
#if OPENAL_DEBUG
- if(inputChannelCount > 2 || outputChannelCount > 2)
+ if (inputChannelCount > 2 || outputChannelCount > 2)
console.warn("The number of input or output channels is too high, capture might not work as expected!");
#endif
@@ -1735,11 +1735,11 @@ var LibraryOpenAL = {
processorFrameCount, inputChannelCount, outputChannelCount
);
- if(inputChannelCount > outputChannelCount) {
+ if (inputChannelCount > outputChannelCount) {
newCapture.mergerNode = newCapture.audioCtx.createChannelMerger(inputChannelCount);
newCapture.mediaStreamSourceNode.connect(newCapture.mergerNode);
newCapture.mergerNode.connect(newCapture.scriptProcessorNode);
- } else if(inputChannelCount < outputChannelCount) {
+ } else if (inputChannelCount < outputChannelCount) {
newCapture.splitterNode = newCapture.audioCtx.createChannelSplitter(outputChannelCount);
newCapture.mediaStreamSourceNode.connect(newCapture.splitterNode);
newCapture.splitterNode.connect(newCapture.scriptProcessorNode);
@@ -1751,14 +1751,14 @@ var LibraryOpenAL = {
newCapture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {
- if(!newCapture.isCapturing)
+ if (!newCapture.isCapturing)
return;
var srcBuf = audioProcessingEvent.inputBuffer;
var c = newCapture;
- for(var chan=0 ; chan < srcBuf.numberOfChannels ; ++chan) {
+ for (var chan=0 ; chan < srcBuf.numberOfChannels ; ++chan) {
var srcArray = srcBuf.getChannelData(chan);
- for(var i=0 ; i<srcArray.length ; ++i) {
+ for (var i=0 ; i<srcArray.length ; ++i) {
var wi = (c.capturePlayhead + i) % c.bufferFrameCapacity;
c.buffers[chan][wi] = c.f32ToSampleFormat(srcArray[i]);
}
@@ -1771,7 +1771,7 @@ var LibraryOpenAL = {
};
// The latest way to call getUserMedia()
- if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices
.getUserMedia({audio: true})
.then(onSuccess)
@@ -1787,7 +1787,7 @@ var LibraryOpenAL = {
alcCaptureCloseDevice: function(deviceId) {
var c = AL.requireValidCaptureDevice(deviceId, "alcCaptureCloseDevice");
- if(!c)
+ if (!c)
return false;
delete AL.captures[deviceId];
@@ -1796,14 +1796,14 @@ var LibraryOpenAL = {
// This clean-up might be unnecessary (paranoid) ?
// May happen if user hasn't decided to grant or deny input
- if(c.mediaStreamSourceNode)
+ if (c.mediaStreamSourceNode)
c.mediaStreamSourceNode.disconnect();
- if(c.mergerNode)
+ if (c.mergerNode)
c.mergerNode.disconnect();
- if(c.splitterNode)
+ if (c.splitterNode)
c.splitterNode.disconnect();
// May happen if user hasn't decided to grant or deny input
- if(c.scriptProcessorNode)
+ if (c.scriptProcessorNode)
c.scriptProcessorNode.disconnect();
delete c.buffers;
@@ -1816,10 +1816,10 @@ var LibraryOpenAL = {
alcCaptureStart: function(deviceId) {
var c = AL.requireValidCaptureDevice(deviceId, "alcCaptureStart");
- if(!c)
+ if (!c)
return;
- if(c.isCapturing) {
+ if (c.isCapturing) {
#if OPENAL_DEBUG
console.warn("Redundant call to alcCaptureStart()");
#endif
@@ -1836,11 +1836,11 @@ var LibraryOpenAL = {
alcCaptureStop: function(deviceId) {
var c = AL.requireValidCaptureDevice(deviceId, "alcCaptureStop");
- if(!c)
+ if (!c)
return;
#if OPENAL_DEBUG
- if(!c.isCapturing)
+ if (!c.isCapturing)
console.warn("Redundant call to alcCaptureStop()");
#endif
c.isCapturing = false;
@@ -1853,7 +1853,7 @@ var LibraryOpenAL = {
// renamed accordingly here
alcCaptureSamples: function(deviceId, pFrames, requestedFrameCount) {
var c = AL.requireValidCaptureDevice(deviceId, "alcCaptureSamples");
- if(!c)
+ if (!c)
return;
// ALCsizei is actually 32-bit signed int, so could be negative
@@ -1896,9 +1896,9 @@ var LibraryOpenAL = {
var dstfreq = c.requestedSampleRate;
var srcfreq = c.audioCtx.sampleRate;
- if(srcfreq == dstfreq) {
- for(var i=0, frame_i=0 ; frame_i < requestedFrameCount ; ++frame_i) {
- for(var chan=0 ; chan < c.buffers.length ; ++chan, ++i) {
+ if (srcfreq == dstfreq) {
+ for (var i=0, frame_i=0 ; frame_i < requestedFrameCount ; ++frame_i) {
+ for (var chan=0 ; chan < c.buffers.length ; ++chan, ++i) {
var src_i = (frame_i + c.capturePlayhead) % c.capturedFrameCount;
setSample(i, c.buffers[chan][src_i]);
}
@@ -1915,14 +1915,14 @@ var LibraryOpenAL = {
return (1 - progress) * from + progress * to;
}
- for(var i=0, frame_i=0 ; frame_i < requestedFrameCount ; ++frame_i) {
+ for (var i=0, frame_i=0 ; frame_i < requestedFrameCount ; ++frame_i) {
var t = frame_i / dstfreq; // Most exact time for the current output sample
var src_i = (Math.floor(t*srcfreq) + c.capturePlayhead) % c.capturedFrameCount;
var src_next_i = (src_i+1) % c.capturedFrameCount;
var between = t*srcfreq - src_i; //(t - src_i/srcfreq) / ((src_i+1)/srcfreq - src_i/srcfreq);
- for(var chan=0 ; chan < c.buffers.length ; ++chan, ++i) {
+ for (var chan=0 ; chan < c.buffers.length ; ++chan, ++i) {
var cb = c.buffers[chan];
var sample = lerp(cb[src_i], cb[src_next_i], between);
setSample(i, sample);
@@ -2303,11 +2303,11 @@ var LibraryOpenAL = {
ret = AL.CAPTURE_DEVICE_NAME;
break;
case 0x310 /* ALC_CAPTURE_DEVICE_SPECIFIER */:
- if(deviceId === 0)
+ if (deviceId === 0)
ret = AL.CAPTURE_DEVICE_NAME.concat('\0');
else {
var c = AL.requireValidCaptureDevice(deviceId, "alcGetString");
- if(!c)
+ if (!c)
return 0;
ret = c.deviceName;
}
@@ -2431,7 +2431,7 @@ var LibraryOpenAL = {
{{{ makeSetValue("pValues", "0", "1", "i32") }}};
case 0x312 /* ALC_CAPTURE_SAMPLES */:
var c = AL.requireValidCaptureDevice(deviceId, "alcGetIntegerv");
- if(!c)
+ if (!c)
return;
var n = c.capturedFrameCount;
var dstfreq = c.requestedSampleRate;
--
2.14.1
From 9f167685801f69aed792f3a8a6b93d16181a3ca0 Mon Sep 17 00:00:00 2001
From: yoanlcq <yoanlecoq.io@gmail.com>
Date: Mon, 10 Jul 2017 20:36:44 +0200
Subject: [PATCH 10/23] Second style fix pass
---
src/library_openal.js | 53 ++++++++++++++++++++++++---------------------------
1 file changed, 25 insertions(+), 28 deletions(-)
diff --git a/src/library_openal.js b/src/library_openal.js
index 9cbab90b3..e676ced4a 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -1659,7 +1659,7 @@ var LibraryOpenAL = {
var buffers = [];
try {
- for (var chan=0 ; chan < outputChannelCount ; ++chan)
+ for (var chan=0; chan < outputChannelCount; ++chan)
buffers[chan] = newSampleArray(bufferFrameCapacity);
} catch(e) {
#if OPENAL_DEBUG
@@ -1722,8 +1722,9 @@ var LibraryOpenAL = {
newCapture.inputChannelCount = inputChannelCount;
#if OPENAL_DEBUG
- if (inputChannelCount > 2 || outputChannelCount > 2)
+ if (inputChannelCount > 2 || outputChannelCount > 2) {
console.warn("The number of input or output channels is too high, capture might not work as expected!");
+ }
#endif
// Have to pick a size from 256, 512, 1024, 2048, 4096, 8192, 16384.
@@ -1751,14 +1752,15 @@ var LibraryOpenAL = {
newCapture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {
- if (!newCapture.isCapturing)
+ if (!newCapture.isCapturing) {
return;
+ }
var srcBuf = audioProcessingEvent.inputBuffer;
var c = newCapture;
- for (var chan=0 ; chan < srcBuf.numberOfChannels ; ++chan) {
+ for (var chan = 0; chan < srcBuf.numberOfChannels; ++chan) {
var srcArray = srcBuf.getChannelData(chan);
- for (var i=0 ; i<srcArray.length ; ++i) {
+ for (var i = 0 ; i < srcArray.length; ++i) {
var wi = (c.capturePlayhead + i) % c.bufferFrameCapacity;
c.buffers[chan][wi] = c.f32ToSampleFormat(srcArray[i]);
}
@@ -1787,8 +1789,7 @@ var LibraryOpenAL = {
alcCaptureCloseDevice: function(deviceId) {
var c = AL.requireValidCaptureDevice(deviceId, "alcCaptureCloseDevice");
- if (!c)
- return false;
+ if (!c) return false;
delete AL.captures[deviceId];
AL.freeIds.push(deviceId);
@@ -1796,15 +1797,11 @@ var LibraryOpenAL = {
// This clean-up might be unnecessary (paranoid) ?
// May happen if user hasn't decided to grant or deny input
- if (c.mediaStreamSourceNode)
- c.mediaStreamSourceNode.disconnect();
- if (c.mergerNode)
- c.mergerNode.disconnect();
- if (c.splitterNode)
- c.splitterNode.disconnect();
+ if (c.mediaStreamSourceNode) c.mediaStreamSourceNode.disconnect();
+ if (c.mergerNode) c.mergerNode.disconnect();
+ if (c.splitterNode) c.splitterNode.disconnect();
// May happen if user hasn't decided to grant or deny input
- if (c.scriptProcessorNode)
- c.scriptProcessorNode.disconnect();
+ if (c.scriptProcessorNode) c.scriptProcessorNode.disconnect();
delete c.buffers;
@@ -1816,8 +1813,7 @@ var LibraryOpenAL = {
alcCaptureStart: function(deviceId) {
var c = AL.requireValidCaptureDevice(deviceId, "alcCaptureStart");
- if (!c)
- return;
+ if (!c) return;
if (c.isCapturing) {
#if OPENAL_DEBUG
@@ -1836,12 +1832,12 @@ var LibraryOpenAL = {
alcCaptureStop: function(deviceId) {
var c = AL.requireValidCaptureDevice(deviceId, "alcCaptureStop");
- if (!c)
- return;
+ if (!c) return;
#if OPENAL_DEBUG
- if (!c.isCapturing)
+ if (!c.isCapturing) {
console.warn("Redundant call to alcCaptureStop()");
+ }
#endif
c.isCapturing = false;
},
@@ -1853,8 +1849,7 @@ var LibraryOpenAL = {
// renamed accordingly here
alcCaptureSamples: function(deviceId, pFrames, requestedFrameCount) {
var c = AL.requireValidCaptureDevice(deviceId, "alcCaptureSamples");
- if (!c)
- return;
+ if (!c) return;
// ALCsizei is actually 32-bit signed int, so could be negative
// Also, spec says :
@@ -1897,8 +1892,8 @@ var LibraryOpenAL = {
var srcfreq = c.audioCtx.sampleRate;
if (srcfreq == dstfreq) {
- for (var i=0, frame_i=0 ; frame_i < requestedFrameCount ; ++frame_i) {
- for (var chan=0 ; chan < c.buffers.length ; ++chan, ++i) {
+ for (var i = 0, frame_i = 0; frame_i < requestedFrameCount; ++frame_i) {
+ for (var chan = 0; chan < c.buffers.length; ++chan, ++i) {
var src_i = (frame_i + c.capturePlayhead) % c.capturedFrameCount;
setSample(i, c.buffers[chan][src_i]);
}
@@ -1915,14 +1910,14 @@ var LibraryOpenAL = {
return (1 - progress) * from + progress * to;
}
- for (var i=0, frame_i=0 ; frame_i < requestedFrameCount ; ++frame_i) {
+ for (var i = 0, frame_i = 0; frame_i < requestedFrameCount; ++frame_i) {
var t = frame_i / dstfreq; // Most exact time for the current output sample
var src_i = (Math.floor(t*srcfreq) + c.capturePlayhead) % c.capturedFrameCount;
var src_next_i = (src_i+1) % c.capturedFrameCount;
var between = t*srcfreq - src_i; //(t - src_i/srcfreq) / ((src_i+1)/srcfreq - src_i/srcfreq);
- for (var chan=0 ; chan < c.buffers.length ; ++chan, ++i) {
+ for (var chan = 0; chan < c.buffers.length; ++chan, ++i) {
var cb = c.buffers[chan];
var sample = lerp(cb[src_i], cb[src_next_i], between);
setSample(i, sample);
@@ -2307,8 +2302,9 @@ var LibraryOpenAL = {
ret = AL.CAPTURE_DEVICE_NAME.concat('\0');
else {
var c = AL.requireValidCaptureDevice(deviceId, "alcGetString");
- if (!c)
+ if (!c) {
return 0;
+ }
ret = c.deviceName;
}
break;