| 1 | /* @title: Scaled parameters */ |
| 2 | #pragma once |
| 3 | #include <math/fixed.h> |
| 4 | #include <stddef.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | enum scale_curve : uint8_t { |
| 8 | SCALE_NONE = 0, |
| 9 | SCALE_PIECEWISE_LOG, |
| 10 | SCALE_PIECEWISE_LINEAR, |
| 11 | SCALE_CORE_MULTIPLIER, |
| 12 | SCALE_CUSTOM, |
| 13 | SCALE_CURVE_MAX, |
| 14 | }; |
| 15 | |
| 16 | typedef size_t (*scaling_fn_t)(fx32_32_t value, size_t min_val, size_t def_val, |
| 17 | size_t max_val); |
| 18 | |
| 19 | typedef size_t (*scaled_param_print_fn_t)(fx32_32_t value, size_t scaled_val, |
| 20 | char *buf, size_t cap); |
| 21 | |
| 22 | struct scaled_param { |
| 23 | enum scale_curve curve; |
| 24 | size_t min_val; |
| 25 | size_t def_val; |
| 26 | size_t max_val; |
| 27 | const char *unit; |
| 28 | |
| 29 | scaling_fn_t custom_scale; |
| 30 | scaled_param_print_fn_t custom_print; |
| 31 | }; |
| 32 | |
| 33 | size_t scaled_param_eval(const struct scaled_param *desc, fx32_32_t value); |
| 34 | size_t scaled_param_format(const struct scaled_param *desc, fx32_32_t value, |
| 35 | size_t scaled_val, char *buf, size_t cap); |
| 36 | |