diff --git a/js-programming/bytebeat-render.js b/js-programming/bytebeat-render.js index c9c16bb..bb17d30 100644 --- a/js-programming/bytebeat-render.js +++ b/js-programming/bytebeat-render.js @@ -71,6 +71,8 @@ const generateAudio = t => { return t&t>>8 } +const clamp = (a, b, c) => max(min(a, c), b) + let lastCorrectSample = 127 // FIXME: guessed value const constrainValue = sample => { @@ -85,7 +87,9 @@ const constrainValue = sample => { case TYPE_SIGNED_BYTEBEAT: return ((sample + 127) & 255) - 128 case TYPE_FLOATBEAT: - return floor(sample * 127) + 127 + // NOTE: temporary fix copied from a code by lehandsomeguy, see https:// + // www.reddit.com/r/bytebeat/comments/48r00a/floatbeat_test/ + return floor((clamp(sample, -0.9999, 0.9999) * 128) + 128) } }