From 5c1a4bfa086ab04361262c019b231c4cc9f25ed4 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Fri, 12 Jul 2024 02:35:05 +0300 Subject: [PATCH] bytebeat-render.js: correct incorrect samples --- js-programming/bytebeat-render.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js-programming/bytebeat-render.js b/js-programming/bytebeat-render.js index 47ffe59..2e24d54 100644 --- a/js-programming/bytebeat-render.js +++ b/js-programming/bytebeat-render.js @@ -61,7 +61,14 @@ const generateAudio = t => { return t&t>>8 } +let lastCorrectSample = 127 // FIXME: guessed value + const constrainValue = sample => { + if (isNaN(sample) || sample < 0) + sample = lastCorrectSample + else + lastCorrectSample = sample + switch (SELECTED_TYPE) { case TYPE_BYTEBEAT: return sample & 255