Skip to content
Open
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
20 changes: 19 additions & 1 deletion src/AudioEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,25 @@ const makeAudioContext = () => {
if (!AudioContext) {
throw new Error('Browser does not support AudioContext');
}
return new AudioContext();

const audioContextWithDefaultRate = new AudioContext();

// By default, browsers will use the sample rate of the output device. For people who have this
// configured very high, this can result in extreme increases in memory usage because we
// pre-decode all sounds into buffers at this sample rate.
if (audioContextWithDefaultRate.sampleRate > 48000) {
try {
return new AudioContext({
sampleRate: 48000
});
} catch (e) {
// If browser can't support our requested rate, we'll have to continue with whatever
// rate we got earlier, even if it's not going to be ideal.
return audioContextWithDefaultRate;
}
}

return audioContextWithDefaultRate;
};

/**
Expand Down