File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,24 @@ 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 48000 is not supported then we take whatever we can get.
58+ return audioContextWithDefaultRate ;
59+ }
60+ }
61+
62+ return audioContextWithDefaultRate ;
4663} ;
4764
4865/**
You can’t perform that action at this time.
0 commit comments