1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-08 18:02:23 +05:30

bytebeat-render.js: constrainValue: floatbeat: fix?

This commit is contained in:
Intel A80486DX2-66 2024-07-12 03:17:44 +03:00
parent 427cca3e4c
commit c989b8d2d9
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -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)
}
}