diff options
Diffstat (limited to 'include/byte_math.h')
-rw-r--r-- | include/byte_math.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/byte_math.h b/include/byte_math.h index 79f93b8..9be4b67 100644 --- a/include/byte_math.h +++ b/include/byte_math.h @@ -13,3 +13,24 @@ static inline uint8_t byte_sin(uint8_t n) } uint8_t calc_w(uint8_t n); + +static inline uint8_t byte_scale(uint8_t v, uint8_t scale) +{ + uint16_t acc = v; + return (acc * scale) >> 8; +} + +static inline uint8_t clip(int x) +{ + if (x > 240) { + return 240; + } + + if (x < 0) { + return 0; + } + + return (uint8_t)x; +} + +#define AS_BYTE(n) ((n) * 256) |