Skip to content

Commit 8ba7f51

Browse files
committed
Remove references to webkitAudioContext. NFC
We were only keeping this code around to support older safari versions. However the oldest safari version we currently support is 14.1, which is the first release to support the modern AudioContext object. There is some confusion only about Safari 14.1 was release as part of iOS 14.5. As far as I can tell Safari 14.1 is the version we should be caring about for AudioContext. See https://webkit.org/blog/11648/new-webkit-features-in-safari-14-1/
1 parent 306c32f commit 8ba7f51

8 files changed

Lines changed: 24 additions & 66 deletions

File tree

site/source/docs/porting/Audio.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ Right now though there's a quick and *de facto* reliable way to do this (C examp
110110
// Avoid calling this more than once! Caching the value is up to you.
111111
unsigned query_sample_rate_of_audiocontexts() {
112112
return EM_ASM_INT({
113-
var AudioContext = window.AudioContext || window.webkitAudioContext;
114113
var ctx = new AudioContext();
115114
var sr = ctx.sampleRate;
116115
ctx.close();

site/source/docs/porting/connecting_cpp_and_javascript/embind.rst

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,9 +1063,6 @@ First consider the JavaScript below, which shows how to use the API:
10631063

10641064
.. code-block:: javascript
10651065
1066-
// Get web audio api context
1067-
var AudioContext = window.AudioContext || window.webkitAudioContext;
1068-
10691066
// Got an AudioContext: Create context and OscillatorNode
10701067
var context = new AudioContext();
10711068
var oscillator = context.createOscillator();
@@ -1092,10 +1089,6 @@ The code can be transliterated to C++ using ``val``, as shown below:
10921089
10931090
int main() {
10941091
val AudioContext = val::global("AudioContext");
1095-
if (!AudioContext.as<bool>()) {
1096-
printf("No global AudioContext, trying webkitAudioContext\n");
1097-
AudioContext = val::global("webkitAudioContext");
1098-
}
10991092
11001093
printf("Got an AudioContext\n");
11011094
val context = AudioContext.new_();
@@ -1113,11 +1106,10 @@ The code can be transliterated to C++ using ``val``, as shown below:
11131106
}
11141107
11151108
First we use :cpp:func:`~emscripten::val::global` to get the symbol for
1116-
the global ``AudioContext`` object (or ``webkitAudioContext`` if that
1117-
does not exist). We then use :cpp:func:`~emscripten::val::new_` to create
1118-
the context, and from this context we can create an ``oscillator``,
1119-
:cpp:func:`~emscripten::val::set` its properties (again using ``val``)
1120-
and then play the tone.
1109+
the global ``AudioContext`` object. We then use
1110+
:cpp:func:`~emscripten::val::new_` to create the context, and from this context
1111+
we can create an ``oscillator``, :cpp:func:`~emscripten::val::set` its
1112+
properties (again using ``val``) and then play the tone.
11211113

11221114
The example can be compiled on the Linux/macOS terminal with::
11231115

src/lib/libopenal.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,8 +1649,6 @@ var LibraryOpenAL = {
16491649
return 0;
16501650
}
16511651
1652-
var AudioContext = window.AudioContext || window.webkitAudioContext;
1653-
16541652
if (!AL.sharedCaptureAudioCtx) {
16551653
try {
16561654
AL.sharedCaptureAudioCtx = new AudioContext();
@@ -2047,12 +2045,13 @@ var LibraryOpenAL = {
20472045
}
20482046
}
20492047
2050-
if (globalThis.AudioContext || globalThis.webkitAudioContext) {
2051-
var deviceId = AL.newId();
2052-
AL.deviceRefCounts[deviceId] = 0;
2053-
return deviceId;
2048+
if (!globalThis.AudioContext) {
2049+
return 0;
20542050
}
2055-
return 0;
2051+
2052+
var deviceId = AL.newId();
2053+
AL.deviceRefCounts[deviceId] = 0;
2054+
return deviceId;
20562055
},
20572056
20582057
alcCloseDevice__proxy: 'sync',
@@ -2077,7 +2076,7 @@ var LibraryOpenAL = {
20772076
return 0;
20782077
}
20792078
2080-
var options = null;
2079+
var options = {};
20812080
var attrs = [];
20822081
var hrtf = null;
20832082
pAttrList >>= 2;
@@ -2095,10 +2094,6 @@ var LibraryOpenAL = {
20952094
20962095
switch (attr) {
20972096
case 0x1007 /* ALC_FREQUENCY */:
2098-
if (!options) {
2099-
options = {};
2100-
}
2101-
21022097
options.sampleRate = val;
21032098
break;
21042099
case 0x1010 /* ALC_MONO_SOURCES */: // fallthrough
@@ -2142,15 +2137,9 @@ var LibraryOpenAL = {
21422137
}
21432138
}
21442139
2145-
var AudioContext = window.AudioContext || window.webkitAudioContext;
2146-
var ac = null;
2140+
var ac;
21472141
try {
2148-
// Only try to pass options if there are any, for compat with browsers that don't support this
2149-
if (options) {
2150-
ac = new AudioContext(options);
2151-
} else {
2152-
ac = new AudioContext();
2153-
}
2142+
ac = new AudioContext(options);
21542143
} catch (e) {
21552144
if (e.name === 'NotSupportedError') {
21562145
#if OPENAL_DEBUG
@@ -2372,14 +2361,14 @@ var LibraryOpenAL = {
23722361
ret = 'Out of Memory';
23732362
break;
23742363
case 0x1004 /* ALC_DEFAULT_DEVICE_SPECIFIER */:
2375-
if (globalThis.AudioContext || globalThis.webkitAudioContext) {
2364+
if (globalThis.AudioContext) {
23762365
ret = AL.DEVICE_NAME;
23772366
} else {
23782367
return 0;
23792368
}
23802369
break;
23812370
case 0x1005 /* ALC_DEVICE_SPECIFIER */:
2382-
if (globalThis.AudioContext || globalThis.webkitAudioContext) {
2371+
if (globalThis.AudioContext) {
23832372
ret = AL.DEVICE_NAME + '\0';
23842373
} else {
23852374
ret = '\0';

src/lib/libsdl.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,12 +1186,8 @@ var LibrarySDL = {
11861186
// initialize Web Audio context ever once on the web page, since
11871187
// initializing multiple times fails on Chrome saying 'audio resources
11881188
// have been exhausted'.
1189-
if (!SDL.audioContext) {
1190-
if (typeof AudioContext != 'undefined') {
1191-
SDL.audioContext = new AudioContext();
1192-
} else if (typeof webkitAudioContext != 'undefined') {
1193-
SDL.audioContext = new webkitAudioContext();
1194-
}
1189+
if (!SDL.audioContext && globalThis.AudioContext) {
1190+
SDL.audioContext = new AudioContext();
11951191
}
11961192
},
11971193

src/lib/libwebaudio.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var LibraryWebAudio = {
4545
$emAudioExpectContext: (handle, methodName) => {
4646
var obj = _emAudioExpectHandle(handle, methodName);
4747
#if ASSERTIONS
48-
assert(obj instanceof (window.AudioContext || window.webkitAudioContext), `${methodName}() called with ${handle} that is not an AudioContext, but of type ${typeof obj}`);
48+
assert(obj instanceof window.AudioContext, `${methodName}() called with ${handle} that is not an AudioContext, but of type ${typeof obj}`);
4949
#endif
5050
},
5151

@@ -61,7 +61,7 @@ var LibraryWebAudio = {
6161
$emAudioExpectNodeOrContext: (handle, methodName) => {
6262
var obj = _emAudioExpectHandle(handle, methodName);
6363
#if ASSERTIONS
64-
assert(obj instanceof window.AudioNode || obj instanceof (window.AudioContext || window.webkitAudioContext), `${methodName}() called with a handle ${handle} that is not an AudioContext or AudioNode, but of type ${typeof obj}`);
64+
assert(obj instanceof window.AudioNode || obj instanceof window.AudioContext, `${methodName}() called with a handle ${handle} that is not an AudioContext or AudioNode, but of type ${typeof obj}`);
6565
#endif
6666
},
6767
#endif
@@ -88,11 +88,8 @@ var LibraryWebAudio = {
8888
emscripten_create_audio_context__deps: ['$emscriptenRegisterAudioObject', '$emscriptenGetAudioObject'],
8989
emscripten_create_audio_context: (options) => {
9090
// Safari added unprefixed AudioContext support in Safari 14.5 on iOS: https://caniuse.com/audio-api
91-
#if MIN_SAFARI_VERSION < 140500 || ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
92-
var ctx = window.AudioContext || window.webkitAudioContext;
9391
#if ASSERTIONS
94-
if (!ctx) console.error('emscripten_create_audio_context failed! Web Audio is not supported.');
95-
#endif
92+
if (!globalThis.AudioContext) console.error('emscripten_create_audio_context failed! Web Audio is not supported.');
9693
#endif
9794

9895
// Converts AUDIO_CONTEXT_RENDER_SIZE_* into AudioContextRenderSizeCategory
@@ -111,12 +108,7 @@ var LibraryWebAudio = {
111108
console.dir(opts);
112109
#endif
113110

114-
#if MIN_SAFARI_VERSION < 140500 || ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
115-
return ctx && emscriptenRegisterAudioObject(new ctx(opts));
116-
#else
117-
// We are targeting an environment where we assume that AudioContext() API unconditionally exists.
118111
return emscriptenRegisterAudioObject(new AudioContext(opts));
119-
#endif
120112
},
121113

122114
emscripten_resume_audio_context_async: (contextHandle, callback, userData) => {

test/browser/test_sdl2_mixer_music.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ int main(int argc, char* argv[])
2727
}
2828

2929
frequency = EM_ASM_INT({
30-
var context;
31-
try {
32-
context = new AudioContext();
33-
} catch (e) {
34-
context = new webkitAudioContext(); // safari only
35-
}
30+
var context = new AudioContext();
3631
return context.sampleRate;
3732
});
3833

test/browser/test_sdl2_mixer_wav.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ int main(int argc, char* argv[]){
3131
return 100;
3232
}
3333
int const frequency = EM_ASM_INT({
34-
var context;
35-
try {
36-
context = new AudioContext();
37-
} catch (e) {
38-
context = new webkitAudioContext(); // safari only
39-
}
34+
var context = new AudioContext();
4035
return context.sampleRate;
4136
});
4237
if(Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 267788,
2+
"a.out.js": 267539,
33
"a.out.nodebug.wasm": 588309,
4-
"total": 856097,
4+
"total": 855848,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)