Skip to content
Open
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
34 changes: 21 additions & 13 deletions src/lib/libopenal.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ var LibraryOpenAL = {
QUEUE_INTERVAL: 25,
QUEUE_LOOKAHEAD: 100.0 / 1000.0,

#if MIN_SAFARI_VERSION < 140500

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MDN suggests 14.1, not 14.5?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its 14.1 for Safari and maybe 14.5 for mobile safari? This is why we use 140500 elsewhere (e.g. libwebaudio.js).

AI seems to agree: Safari 14.1+ (Desktop) and iOS Safari 14.5+: Switched to standard window.AudioContext

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified 14.1/14.5 is on MDN.

AudioContext: globalThis.AudioContext ?? globalThis.webkitAudioContext,
#else
AudioContext: globalThis.AudioContext,
#endif

DEVICE_NAME: 'Emscripten OpenAL',
CAPTURE_DEVICE_NAME: 'Emscripten OpenAL capture',

Expand Down Expand Up @@ -1650,7 +1656,11 @@ var LibraryOpenAL = {
return 0;
}

var AudioContext = window.AudioContext || window.webkitAudioContext;
#if MIN_SAFARI_VERSION < 140500
// We depend on the global AudioContext for modern browser, but
// old older safari versions we may still need to use webkitAudioContext.
var AudioContext = AL.AudioContext;
#endif

if (!AL.sharedCaptureAudioCtx) {
try {
Expand Down Expand Up @@ -2048,7 +2058,7 @@ var LibraryOpenAL = {
}
}

if (globalThis.AudioContext || globalThis.webkitAudioContext) {
if (AL.getAudioContext) {
var deviceId = AL.newId();
AL.deviceRefCounts[deviceId] = 0;
return deviceId;
Expand Down Expand Up @@ -2078,7 +2088,7 @@ var LibraryOpenAL = {
return 0;
}

var options = null;
var options;
var attrs = [];
var hrtf = null;
pAttrList >>= 2;
Expand Down Expand Up @@ -2143,15 +2153,13 @@ var LibraryOpenAL = {
}
}

var AudioContext = window.AudioContext || window.webkitAudioContext;
var ac = null;
#if MIN_SAFARI_VERSION < 140500
var AudioContext = window.AudioContext ?? window.webkitAudioContext;
#endif

var ac;
try {
// Only try to pass options if there are any, for compat with browsers that don't support this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which browser versions was this an issue for?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its really hard to know for sure but some ancient version of webkitAudioContext didn't not support options passed to it.

However, since we already don't have this change in libwebaudio.js I figure it much be at least as old as 14.5

if (options) {
ac = new AudioContext(options);
} else {
ac = new AudioContext();
}
ac = new AudioContext(options);
} catch (e) {
if (e.name === 'NotSupportedError') {
#if OPENAL_DEBUG
Expand Down Expand Up @@ -2382,14 +2390,14 @@ var LibraryOpenAL = {
ret = 'Out of Memory';
break;
case 0x1004 /* ALC_DEFAULT_DEVICE_SPECIFIER */:
if (globalThis.AudioContext || globalThis.webkitAudioContext) {
if (AL.AudioContext) {
ret = AL.DEVICE_NAME;
} else {
return 0;
}
break;
case 0x1005 /* ALC_DEVICE_SPECIFIER */:
if (globalThis.AudioContext || globalThis.webkitAudioContext) {
if (AL.AudioContext) {
ret = AL.DEVICE_NAME + '\0';
} else {
ret = '\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": 268229,
"a.out.js": 267924,
"a.out.nodebug.wasm": 588309,
"total": 856538,
"total": 856233,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down