This commit is contained in:
Jade (Rose) Rowland 2023-12-23 12:30:55 -05:00
parent 466574a856
commit 3776791239
3 changed files with 17 additions and 7 deletions

View file

@ -61,3 +61,10 @@ export function nanFallback(value, fallback) {
}
return value;
}
// modulo that works with negative numbers e.g. _mod(-1, 3) = 2. Works on numbers (rather than patterns of numbers, as @mod@ from pattern.mjs does)
export const _mod = (n, m) => ((n % m) + m) % m;
// round to nearest int, negative numbers will output a subtracted index
export const getSoundIndex = (n, numSounds) => {
return _mod(Math.round(nanFallback(n, 0)), numSounds);
};