File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,25 @@ const makeAudioContext = () => {
4242 if ( ! AudioContext ) {
4343 throw new Error ( 'Browser does not support AudioContext' ) ;
4444 }
45- return new AudioContext ( ) ;
45+
46+ const audioContextWithDefaultRate = new AudioContext ( ) ;
47+
48+ // By default, browsers will use the sample rate of the output device. For people who have this
49+ // configured very high, this can result in extreme increases in memory usage because we
50+ // pre-decode all sounds into buffers at this sample rate.
51+ if ( audioContextWithDefaultRate . sampleRate > 48000 ) {
52+ try {
53+ return new AudioContext ( {
54+ sampleRate : 48000
55+ } ) ;
56+ } catch ( e ) {
57+ // If browser can't support our requested rate, we'll have to continue with whatever
58+ // rate we got earlier, even if it's not going to be ideal.
59+ return audioContextWithDefaultRate ;
60+ }
61+ }
62+
63+ return audioContextWithDefaultRate ;
4664} ;
4765
4866/**
You can’t perform that action at this time.
0 commit comments