Compare commits

...

2 Commits

Author SHA1 Message Date
Jade (Rose) Rowland 5fbc073f9f fix sample prefetch 2026-05-25 14:05:55 +02:00
Jade (Rose) Rowland 262fe3b516 fix ir 2026-05-23 18:47:24 +02:00
2 changed files with 26 additions and 17 deletions
+24 -15
View File
@@ -9,7 +9,7 @@ import {
onceEnded, onceEnded,
releaseAudioNode, releaseAudioNode,
} from './helpers.mjs'; } from './helpers.mjs';
import { logger } from './logger.mjs'; import { errorLogger, logger } from './logger.mjs';
const bufferCache = {}; // string: Promise<ArrayBuffer> const bufferCache = {}; // string: Promise<ArrayBuffer>
const loadCache = {}; // string: Promise<ArrayBuffer> const loadCache = {}; // string: Promise<ArrayBuffer>
@@ -228,22 +228,31 @@ export async function fetchSampleMap(url) {
} }
url = `https://shabda.ndre.gr/speech/${words}.json?gender=${gender}&language=${language}&strudel=1'`; url = `https://shabda.ndre.gr/speech/${words}.json?gender=${gender}&language=${language}&strudel=1'`;
} }
if (typeof fetch !== 'function') {
// not a browser
return;
}
const base = getBaseURL(url); const base = getBaseURL(url);
if (typeof fetch === 'undefined') { if (typeof fetch !== 'function') {
// skip fetch when in node / testing errorLogger(new Error(`fetch is not supported in this environment. Skipping map load for: ${url}`), 'sampler.mjs')
return; return [{}, base || ''];
} }
const json = await fetch(url)
.then((res) => res.json())
.catch((error) => { try {
console.error(error); const res = await fetch(url);
throw new Error(`error loading "${url}"`); if (!res.ok) {
}); throw new Error(`HTTP error! status: ${res.status}`);
return [json, json._base || base]; }
const json = await res.json();
return [json, json._base || base];
} catch (error) {
// Catching the failure here prevents it from bubbling up and crashing upstream
errorLogger(new Error(`Failed to fetch or parse sample map at "${url}":`), "sampler.mjs");
// Return a safe fallback structure so destructuring (e.g., [json, base]) won't break
return [{}, base || ''];
}
} }
/** /**
+2 -2
View File
@@ -963,9 +963,9 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
let url; let url;
let sample = getSound(ir); let sample = getSound(ir);
if (Array.isArray(sample)) { if (Array.isArray(sample)) {
url = sample.data.samples[i % sample.data.samples.length]; url = sample.data.samples[i % sample.data.samples.length].url;
} else if (typeof sample === 'object') { } else if (typeof sample === 'object') {
url = Object.values(sample.data.samples).flat()[i % Object.values(sample.data.samples).length]; url = Object.values(sample.data.samples).flat()[i % Object.values(sample.data.samples).length].url;
} }
roomIR = await loadBuffer(url, ac, ir, 0); roomIR = await loadBuffer(url, ac, ir, 0);
} }