Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 51 additions & 63 deletions src/lib/libopenal.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var LibraryOpenAL = {

var buf = src.bufQueue[bufCursor % src.bufQueue.length];
// If the buffer contains no data, skip it
if (buf.length === 0) {
if (!buf.length) {
skipCount++;
// If we've gone through the whole queue and everything is 0 length, just give up
if (skipCount === src.bufQueue.length) {
Expand Down Expand Up @@ -249,7 +249,7 @@ var LibraryOpenAL = {
} else if (src.type === {{{ cDefs.AL_STATIC }}} && src.looping) {
// If the source is a looping static buffer, determine the buffer offset based on the loop points
var buf = src.bufQueue[0];
if (buf.length === 0) {
if (!buf.length) {
src.bufOffset = 0.0;
} else {
var delta = (currentTime - src.bufStartTime) * src.playbackRate;
Expand Down Expand Up @@ -331,8 +331,8 @@ var LibraryOpenAL = {
},

stopSourceAudio: (src) => {
for (var i = 0; i < src.audioQueue.length; i++) {
src.audioQueue[i].stop();
for (var audioSrc of src.audioQueue) {
audioSrc.stop();
}
src.audioQueue.length = 0;
},
Expand Down Expand Up @@ -399,9 +399,9 @@ var LibraryOpenAL = {

// 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];
for (var buf of src.bufQueue) {
if (buf.id) {
templateBuf = buf;
break;
}
}
Expand Down Expand Up @@ -697,9 +697,8 @@ var LibraryOpenAL = {

sourceDuration: (src) => {
var length = 0.0;
for (var i = 0; i < src.bufQueue.length; i++) {
var audioBuf = src.bufQueue[i].audioBuf;
length += audioBuf ? audioBuf.duration : 0.0;
for (var buf of src.bufQueue) {
length += buf.audioBuf?.duration ?? 0.0;
}
return length;
},
Expand All @@ -709,9 +708,7 @@ var LibraryOpenAL = {

var offset = 0.0;
for (var i = 0; i < src.bufsProcessed; i++) {
if (src.bufQueue[i].audioBuf) {
offset += src.bufQueue[i].audioBuf.duration;
}
offset += src.bufQueue[i].audioBuf?.duration ?? 0.0;
}
offset += src.bufOffset;

Expand Down Expand Up @@ -947,7 +944,7 @@ var LibraryOpenAL = {
return;
}
var buf = AL.buffers[bufferId];
if (!buf || bufferId === 0) {
if (!buf || !bufferId) {
#if OPENAL_DEBUG
dbg(`${funcname}() called with an invalid buffer`);
#endif
Expand All @@ -965,7 +962,7 @@ var LibraryOpenAL = {
case 0x2004 /* AL_SIZE */:
return buf.length * buf.bytesPerSample * buf.channels;
case 0x2015 /* AL_LOOP_POINTS_SOFT */:
if (buf.length === 0) {
if (!buf.length) {
return [0, 0];
}
return [
Expand All @@ -989,7 +986,7 @@ var LibraryOpenAL = {
return;
}
var buf = AL.buffers[bufferId];
if (!buf || bufferId === 0) {
if (!buf || !bufferId) {
#if OPENAL_DEBUG
dbg(`${funcname}() called with an invalid buffer`);
#endif
Expand All @@ -1006,7 +1003,7 @@ var LibraryOpenAL = {

switch (param) {
case 0x2004 /* AL_SIZE */:
if (value !== 0) {
if (value) {
#if OPENAL_DEBUG
dbg(`${funcname}() param AL_SIZE value ${value} is out of range`);
#endif
Expand Down Expand Up @@ -1093,12 +1090,12 @@ var LibraryOpenAL = {
case 0x1010 /* AL_SOURCE_STATE */:
return src.state;
case 0x1015 /* AL_BUFFERS_QUEUED */:
if (src.bufQueue.length === 1 && src.bufQueue[0].id === 0) {
if (src.bufQueue.length === 1 && !src.bufQueue[0].id) {
return 0;
}
return src.bufQueue.length;
case 0x1016 /* AL_BUFFERS_PROCESSED */:
if ((src.bufQueue.length === 1 && src.bufQueue[0].id === 0) || src.looping) {
if ((src.bufQueue.length === 1 && !src.bufQueue[0].id) || src.looping) {
return 0;
}
return src.bufsProcessed;
Expand Down Expand Up @@ -1131,17 +1128,17 @@ var LibraryOpenAL = {
case 0x2009 /* AL_BYTE_LENGTH_SOFT */:
var length = 0;
var bytesPerFrame = 0;
for (var i = 0; i < src.bufQueue.length; i++) {
length += src.bufQueue[i].length;
if (src.bufQueue[i].id !== 0) {
bytesPerFrame = src.bufQueue[i].bytesPerSample * src.bufQueue[i].channels;
for (var buf of src.bufQueue) {
length += buf.length;
if (buf.id) {
bytesPerFrame = buf.bytesPerSample * buf.channels;
}
}
return length * bytesPerFrame;
case 0x200A /* AL_SAMPLE_LENGTH_SOFT */:
var length = 0;
for (var i = 0; i < src.bufQueue.length; i++) {
length += src.bufQueue[i].length;
for (var buf of src.bufQueue) {
length += buf.length;
}
return length;
case 0x200B /* AL_SEC_LENGTH_SOFT */:
Expand Down Expand Up @@ -1318,8 +1315,8 @@ var LibraryOpenAL = {
}

if (value === 0) {
for (var i in src.bufQueue) {
src.bufQueue[i].refCount--;
for (var b of src.bufQueue) {
b.refCount--;
}
src.bufQueue.length = 1;
src.bufQueue[0] = AL.buffers[0];
Expand All @@ -1336,8 +1333,8 @@ var LibraryOpenAL = {
return;
}

for (var i in src.bufQueue) {
src.bufQueue[i].refCount--;
for (var b of src.bufQueue) {
b.refCount--;
}
src.bufQueue.length = 0;

Expand Down Expand Up @@ -1454,7 +1451,7 @@ var LibraryOpenAL = {
if (srcLen > 0.0) {
var frequency;
for (var buf of src.bufQueue) {
if (buf.id !== 0) {
if (buf.id) {
frequency = buf.frequency;
break;
}
Expand All @@ -1476,7 +1473,7 @@ var LibraryOpenAL = {
if (srcLen > 0.0) {
var bytesPerSec;
for (var buf of src.bufQueue) {
if (buf.id !== 0) {
if (buf.id) {
bytesPerSec = buf.frequency * buf.bytesPerSample * buf.channels;
break;
}
Expand Down Expand Up @@ -1561,7 +1558,7 @@ var LibraryOpenAL = {
// people might assume that most alcCapture functions
// accept NULL as a 'use the default' device.
requireValidCaptureDevice: (deviceId, funcname) => {
if (deviceId === 0) {
if (!deviceId) {
#if OPENAL_DEBUG
dbg(`${funcname}() on a NULL device is an error`);
#endif
Expand Down Expand Up @@ -1616,7 +1613,7 @@ var LibraryOpenAL = {
var resolvedDeviceName = AL.CAPTURE_DEVICE_NAME;

// NULL is a valid device name here (resolves to default);
if (pDeviceName !== 0) {
if (pDeviceName) {
resolvedDeviceName = UTF8ToString(pDeviceName);
if (resolvedDeviceName !== AL.CAPTURE_DEVICE_NAME) {
#if OPENAL_DEBUG
Expand Down Expand Up @@ -2088,7 +2085,7 @@ var LibraryOpenAL = {
while (true) {
attr = HEAP32[pAttrList++];
attrs.push(attr);
if (attr === 0) {
if (!attr) {
break;
}
val = HEAP32[pAttrList++];
Expand Down Expand Up @@ -2125,7 +2122,7 @@ var LibraryOpenAL = {
}
break;
case 0x1996 /* ALC_HRTF_ID_SOFT */:
if (val !== 0) {
if (val) {
#if OPENAL_DEBUG
dbg(`Invalid ALC_HRTF_ID_SOFT index ${val}`);
#endif
Expand Down Expand Up @@ -2254,20 +2251,11 @@ var LibraryOpenAL = {
},

alcGetCurrentContext__proxy: 'sync',
alcGetCurrentContext: () => {
if (AL.currentCtx !== null) {
return AL.currentCtx.id;
}
return 0;
},
alcGetCurrentContext: () => AL.currentCtx ? AL.currentCtx.id : 0,

alcMakeContextCurrent__proxy: 'sync',
alcMakeContextCurrent: (contextId) => {
if (contextId === 0) {
AL.currentCtx = null;
} else {
AL.currentCtx = AL.contexts[contextId];
}
AL.currentCtx = AL.contexts[contextId];
Comment thread
sbc100 marked this conversation as resolved.
return {{{ cDefs.ALC_TRUE }}};
},

Expand Down Expand Up @@ -2295,7 +2283,7 @@ var LibraryOpenAL = {
// Spec says :
// Using a NULL handle is legal, but only the
// tokens defined by the AL core are guaranteed.
if (deviceId !== 0 && !(deviceId in AL.deviceRefCounts)) {
if (deviceId && !(deviceId in AL.deviceRefCounts)) {
#if OPENAL_DEBUG
dbg('alcGetEnumValue() called with an invalid device');
#endif
Expand Down Expand Up @@ -2399,7 +2387,7 @@ var LibraryOpenAL = {
ret = AL.CAPTURE_DEVICE_NAME;
break;
case 0x310 /* ALC_CAPTURE_DEVICE_SPECIFIER */:
if (deviceId === 0) {
if (!deviceId) {
ret = AL.CAPTURE_DEVICE_NAME + '\0';
} else {
var c = AL.requireValidCaptureDevice(deviceId, 'alcGetString');
Expand Down Expand Up @@ -2429,7 +2417,7 @@ var LibraryOpenAL = {

alcGetIntegerv__proxy: 'sync',
alcGetIntegerv: (deviceId, param, size, pValues) => {
if (size === 0 || !pValues) {
if (!size || !pValues) {
// Ignore the query, per the spec
return;
}
Expand Down Expand Up @@ -2620,7 +2608,7 @@ var LibraryOpenAL = {
var ret;
switch (param) {
case 0x1995 /* ALC_HRTF_SPECIFIER_SOFT */:
if (index === 0) {
if (!index) {
ret = 'Web Audio HRTF';
} else {
#if OPENAL_DEBUG
Expand All @@ -2631,7 +2619,7 @@ var LibraryOpenAL = {
}
break;
default:
if (index !== 0) {
if (index) {
#if OPENAL_DEBUG
dbg(`alcGetStringiSOFT() with param ${ptrToString(param)} not implemented yet`);
#endif
Expand Down Expand Up @@ -2664,7 +2652,7 @@ var LibraryOpenAL = {
var val = 0;
while (true) {
attr = HEAP32[pAttrList++];
if (attr === 0) {
if (!attr) {
break;
}
val = HEAP32[pAttrList++];
Expand Down Expand Up @@ -2740,8 +2728,8 @@ var LibraryOpenAL = {

for (var i = 0; i < count; ++i) {
var bufId = {{{ makeGetValue('pBufferIds', 'i*4', 'i32') }}};
/// Deleting the zero buffer is a legal NOP, so ignore it
if (bufId === 0) {
// Deleting the zero buffer is a legal NOP, so ignore it
if (!bufId) {
continue;
}

Expand All @@ -2766,7 +2754,7 @@ var LibraryOpenAL = {

for (var i = 0; i < count; ++i) {
var bufId = {{{ makeGetValue('pBufferIds', 'i*4', 'i32') }}};
if (bufId === 0) {
if (!bufId) {
continue;
}

Expand Down Expand Up @@ -3250,7 +3238,7 @@ var LibraryOpenAL = {
case {{{ cDefs.AL_DOPPLER_FACTOR }}}:
case {{{ cDefs.AL_SPEED_OF_SOUND }}}:
case {{{ cDefs.AL_DISTANCE_MODEL }}}:
return val !== 0 ? {{{ cDefs.AL_TRUE }}} : {{{ cDefs.AL_FALSE }}};
return val ? {{{ cDefs.AL_TRUE }}} : {{{ cDefs.AL_FALSE }}};
default:
#if OPENAL_DEBUG
dbg(`alGetBoolean(): param ${ptrToString(param)} has wrong signature`);
Expand Down Expand Up @@ -4032,14 +4020,14 @@ var LibraryOpenAL = {
return;
}

if (count === 0) {
if (!count) {
return;
}

// Find the first non-zero buffer in the queue to determine the proper format
var templateBuf = AL.buffers[0];
for (var buf of src.bufQueue) {
if (buf.id !== 0) {
if (buf.id) {
templateBuf = buf;
break;
}
Expand All @@ -4057,7 +4045,7 @@ var LibraryOpenAL = {
}

// Check that the added buffer has the correct format. If the template is the zero buffer, any format is valid.
if (templateBuf.id !== 0 && (
if (templateBuf.id && (
buf.frequency !== templateBuf.frequency
|| buf.bytesPerSample !== templateBuf.bytesPerSample
|| buf.channels !== templateBuf.channels)
Expand All @@ -4070,7 +4058,7 @@ var LibraryOpenAL = {
}

// If the only buffer in the queue is the zero buffer, clear the queue before we add anything.
if (src.bufQueue.length === 1 && src.bufQueue[0].id === 0) {
if (src.bufQueue.length === 1 && !src.bufQueue[0].id) {
src.bufQueue.length = 0;
}

Expand Down Expand Up @@ -4107,12 +4095,12 @@ var LibraryOpenAL = {
AL.currentCtx.err = {{{ cDefs.AL_INVALID_NAME }}};
return;
}
if (count > (src.bufQueue.length === 1 && src.bufQueue[0].id === 0 ? 0 : src.bufsProcessed)) {
if (count > (src.bufQueue.length === 1 && !src.bufQueue[0].id ? 0 : src.bufsProcessed)) {
AL.currentCtx.err = {{{ cDefs.AL_INVALID_VALUE }}};
return;
}

if (count === 0) {
if (!count) {
return;
}

Expand All @@ -4125,7 +4113,7 @@ var LibraryOpenAL = {
}

/// If the queue is empty, put the zero buffer back in
if (src.bufQueue.length === 0) {
if (!src.bufQueue.length) {
src.bufQueue.push(AL.buffers[0]);
}

Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 268215,
"a.out.js": 267949,
"a.out.nodebug.wasm": 588309,
"total": 856524,
"total": 856258,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
2 changes: 1 addition & 1 deletion tools/maint/sync_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def sync_repo(name, repo_dir, revision, url):
return

if is_dirty(repo_dir):
utils.exit_with_error("Directory for {name} is dirty: '{repo_dir}'")
utils.exit_with_error(f"Directory for {name} is dirty: '{repo_dir}'")

if not has_revision(repo_dir, revision):
print(' Fetching revision')
Expand Down
Loading