add disableWorklets option to initAudio

This commit is contained in:
Felix Roos 2023-08-11 12:35:00 +02:00
parent 7d0fb0de83
commit c6095fd92a

View File

@ -62,21 +62,24 @@ function getWorklet(ac, processor, params) {
} }
// this function should be called on first user interaction (to avoid console warning) // this function should be called on first user interaction (to avoid console warning)
export async function initAudio() { export async function initAudio(options = {}) {
const { disableWorklets = false } = options;
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
try { await getAudioContext().resume();
await getAudioContext().resume(); if (!disableWorklets) {
await loadWorklets(); await loadWorklets().catch((err) => {
} catch (err) { console.warn('could not load AudioWorklet effects coarse, crush and shape', err);
console.warn('could not load AudioWorklet effects coarse, crush and shape', err); });
} else {
console.log('disableWorklets: AudioWorklet effects coarse, crush and shape are skipped!');
} }
} }
} }
export async function initAudioOnFirstClick() { export async function initAudioOnFirstClick(options) {
return new Promise((resolve) => { return new Promise((resolve) => {
document.addEventListener('click', async function listener() { document.addEventListener('click', async function listener() {
await initAudio(); await initAudio(options);
resolve(); resolve();
document.removeEventListener('click', listener); document.removeEventListener('click', listener);
}); });