35 #define FIXED_POINT 16 137 if (value & 0x00008000) {
143 return (uint16_t) value;
static fixed_t fixed_from_int(const uint16_t value)
Converts an integer to a fixed point number.
Definition: math.h:89
static uint16_t fixed_to_int(fixed_t value)
Converts fixed point number to an integer.
Definition: math.h:134
uint8_t midi_value_t
Type for valid MIDI values [0..127].
Definition: midi.h:56
uint16_t to
The highest input (linear_to_midi) / output (linear_from_midi) value.
Definition: math.h:49
static fixed_t fixed_mpy(const fixed_t a, const fixed_t b)
Multiplies two fixed point numbers.
Definition: math.h:122
MIDI message transceiver.
void init_linear_to_midi(struct linear_range *config)
Initializes a linear function to map from an arbitrary integer range to MIDI values.
Definition: math.c:44
static fixed_t fixed_div(const fixed_t a, const fixed_t b)
Performs a division of two fixed point numbers.
Definition: math.h:105
Configuration for a linear scaling function.
Definition: math.h:46
fixed_t slope
The slope of the linear function (computed in init_linear_...())
Definition: math.h:50
#define FIXED_POINT
Width of the fractional part of fixed point numbers.
Definition: math.h:35
midi_value_t linear_to_midi(const struct linear_range *config, uint16_t input)
Yields the MIDI value [0,127] from a given integer in the configured range.
Definition: math.c:55
uint64_t fixed_accu_t
Datatype for accumulators in fixed point number arithmetic functions.
Definition: math.h:43
uint16_t linear_from_midi(const struct linear_range *config, midi_value_t midi_value)
Yields an integer in the configured range that corresponds to the given MIDI value.
Definition: math.c:50
uint32_t fixed_t
Datatype for fixed point numbers.
Definition: math.h:40
void init_linear_from_midi(struct linear_range *config)
Initializes a linear function to map from MIDI values to an arbitrary integer range.
Definition: math.c:38
uint16_t from
The lowest input (linear_to_midi) / output (linear_from_midi) value.
Definition: math.h:48