From 5ea2124e91600377ca936b575ed9e7b3f2c50479 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 18 Aug 2022 20:46:42 +0200 Subject: [PATCH] webaudio error handling --- packages/webaudio/webaudio.mjs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/webaudio/webaudio.mjs b/packages/webaudio/webaudio.mjs index 2652286d..0d683e9c 100644 --- a/packages/webaudio/webaudio.mjs +++ b/packages/webaudio/webaudio.mjs @@ -95,7 +95,7 @@ const getSampleBufferSource = async (s, n, note) => { } const bank = samples?.[s]; if (!bank) { - throw new Error('sample not found:', s, 'try one of ' + Object.keys(samples)); + throw new Error(`sample not found: "${s}", try one of ${Object.keys(samples).join(', ')}`); } if (typeof bank !== 'object') { throw new Error('wrong format for sample bank:', s); @@ -142,6 +142,11 @@ const splitSN = (s, n) => { export const webaudioOutput = async (hap, deadline, hapDuration) => { try { const ac = getAudioContext(); + if (typeof hap.value !== 'object') { + throw new Error( + `hap.value ${hap.value} is not supported by webaudio output. Hint: append .note() or .s() to the end`, + ); + } // calculate correct time (tone.js workaround) const t = ac.currentTime + deadline; // destructure value