|
PebbleOS
|
Signed fixed-point types and a generic recursive filter. More...
Data Structures | |
| union | Fixed_S16_3 |
| Fixed-point number with 1 sign bit, 12 integer bits and 3 fraction bits. More... | |
| union | Fixed_S32_16 |
| Fixed-point number with 1 sign bit, 15 integer bits and 16 fraction bits. More... | |
| union | Fixed_S64_32 |
| Fixed-point number with 1 sign bit, 31 integer bits and 32 fraction bits. More... | |
| struct | Fixed_S16_3.__unnamed102__ |
| struct | Fixed_S32_16.__unnamed104__ |
| struct | Fixed_S64_32.__unnamed106__ |
Macros | |
| #define | Fixed_S16_3(raw) ((Fixed_S16_3){.raw_value = (raw)}) |
| Make a Fixed_S16_3 from its raw value. | |
| #define | FIXED_S16_3_PRECISION 3 |
| Number of fraction bits of Fixed_S16_3. | |
| #define | FIXED_S16_3_FACTOR (1 << FIXED_S16_3_PRECISION) |
| Scale factor of Fixed_S16_3. | |
| #define | FIXED_S16_3_ZERO ((Fixed_S16_3){.integer = 0, .fraction = 0}) |
| Fixed_S16_3 zero. | |
| #define | FIXED_S16_3_ONE ((Fixed_S16_3){.integer = 1, .fraction = 0}) |
| Fixed_S16_3 one. | |
| #define | FIXED_S16_3_HALF ((Fixed_S16_3){.raw_value = FIXED_S16_3_ONE.raw_value / 2}) |
| Fixed_S16_3 one half. | |
| #define | Fixed_S32_16(raw) ((Fixed_S32_16){.raw_value = (raw)}) |
| Make a Fixed_S32_16 from its raw value. | |
| #define | FIXED_S32_16_PRECISION 16 |
| Number of fraction bits of Fixed_S32_16. | |
| #define | FIXED_S32_16_ONE ((Fixed_S32_16){.integer = 1, .fraction = 0}) |
| Fixed_S32_16 one. | |
| #define | FIXED_S32_16_ZERO ((Fixed_S32_16){.integer = 0, .fraction = 0}) |
| Fixed_S32_16 zero. | |
| #define | FIXED_S64_32_PRECISION 32 |
| Number of fraction bits of Fixed_S64_32. | |
| #define | FIXED_S64_32_ONE ((Fixed_S64_32){.integer = 1, .fraction = 0}) |
| Fixed_S64_32 one. | |
| #define | FIXED_S64_32_ZERO ((Fixed_S64_32){.integer = 0, .fraction = 0}) |
| Fixed_S64_32 zero. | |
| #define | FIXED_S64_32_FROM_RAW(raw) ((Fixed_S64_32){.raw_value = (raw)}) |
| Make a Fixed_S64_32 from its raw value. | |
| #define | FIXED_S64_32_FROM_INT(x) ((Fixed_S64_32){.integer = x, .fraction = 0}) |
| Make a Fixed_S64_32 from an integer. | |
| #define | FIXED_S64_32_TO_INT(x) (x.integer) |
| Get the integer part of a Fixed_S64_32, rounded towards negative infinity. | |
Typedefs | |
| typedef Fixed_S32_16 | Fixed_S32_16Return |
| Alias of Fixed_S32_16 for function return types. | |
Signed fixed-point types and a generic recursive filter.
In every type the fraction is unsigned and adds to the integer part, so -1.125 in Fixed_S16_3 is stored as integer -2 and fraction 7 (-2 + 7 * 0.125), and 1.125 as integer 1 and fraction 1. This keeps raw_value a plain two's complement number, so values can be added and multiplied directly.
| union Fixed_S16_3 |
Fixed-point number with 1 sign bit, 12 integer bits and 3 fraction bits.
| Data Fields | ||
|---|---|---|
| struct Fixed_S16_3.__unnamed102__ | __unnamed__ | |
| int16_t | raw_value | Value scaled by 8. |
| union Fixed_S32_16 |
Fixed-point number with 1 sign bit, 15 integer bits and 16 fraction bits.
| Data Fields | ||
|---|---|---|
| struct Fixed_S32_16.__unnamed104__ | __unnamed__ | |
| int32_t | raw_value | Value scaled by 65536. |
| union Fixed_S64_32 |
Fixed-point number with 1 sign bit, 31 integer bits and 32 fraction bits.
| Data Fields | ||
|---|---|---|
| struct Fixed_S64_32.__unnamed106__ | __unnamed__ | |
| int64_t | raw_value | Value scaled by 2^32. |
| struct Fixed_S16_3.__unnamed102__ |
| struct Fixed_S32_16.__unnamed104__ |
| struct Fixed_S64_32.__unnamed106__ |
| #define Fixed_S16_3 | ( | raw | ) | ((Fixed_S16_3){.raw_value = (raw)}) |
Make a Fixed_S16_3 from its raw value.
| raw | Value scaled by 8. |
| #define FIXED_S16_3_FACTOR (1 << FIXED_S16_3_PRECISION) |
Scale factor of Fixed_S16_3.
| #define FIXED_S16_3_HALF ((Fixed_S16_3){.raw_value = FIXED_S16_3_ONE.raw_value / 2}) |
Fixed_S16_3 one half.
| #define FIXED_S16_3_ONE ((Fixed_S16_3){.integer = 1, .fraction = 0}) |
Fixed_S16_3 one.
| #define FIXED_S16_3_PRECISION 3 |
Number of fraction bits of Fixed_S16_3.
| #define FIXED_S16_3_ZERO ((Fixed_S16_3){.integer = 0, .fraction = 0}) |
Fixed_S16_3 zero.
| #define Fixed_S32_16 | ( | raw | ) | ((Fixed_S32_16){.raw_value = (raw)}) |
Make a Fixed_S32_16 from its raw value.
| raw | Value scaled by 65536. |
| #define FIXED_S32_16_ONE ((Fixed_S32_16){.integer = 1, .fraction = 0}) |
Fixed_S32_16 one.
| #define FIXED_S32_16_PRECISION 16 |
Number of fraction bits of Fixed_S32_16.
| #define FIXED_S32_16_ZERO ((Fixed_S32_16){.integer = 0, .fraction = 0}) |
Fixed_S32_16 zero.
| #define FIXED_S64_32_FROM_INT | ( | x | ) | ((Fixed_S64_32){.integer = x, .fraction = 0}) |
Make a Fixed_S64_32 from an integer.
| x | Integer. |
| #define FIXED_S64_32_FROM_RAW | ( | raw | ) | ((Fixed_S64_32){.raw_value = (raw)}) |
Make a Fixed_S64_32 from its raw value.
| raw | Value scaled by 2^32. |
| #define FIXED_S64_32_ONE ((Fixed_S64_32){.integer = 1, .fraction = 0}) |
Fixed_S64_32 one.
| #define FIXED_S64_32_PRECISION 32 |
Number of fraction bits of Fixed_S64_32.
| #define FIXED_S64_32_TO_INT | ( | x | ) | (x.integer) |
Get the integer part of a Fixed_S64_32, rounded towards negative infinity.
| x | Value. |
| #define FIXED_S64_32_ZERO ((Fixed_S64_32){.integer = 0, .fraction = 0}) |
Fixed_S64_32 zero.
| typedef Fixed_S32_16 Fixed_S32_16Return |
Alias of Fixed_S32_16 for function return types.
Avoids the function-like Fixed_S32_16() macro expanding in function pointer declarations.
|
static |
Add two Fixed_S16_3 values.
| a | First term. |
| b | Second term. |
References Fixed_S16_3, and Fixed_S16_3::raw_value.
|
static |
Add three Fixed_S16_3 values.
| a | First term. |
| b | Second term. |
| c | Third term. |
References Fixed_S16_3, and Fixed_S16_3::raw_value.
|
static |
Compare two Fixed_S16_3 values.
| a | First value. |
| b | Second value. |
References Fixed_S16_3::raw_value.
|
static |
Multiply two Fixed_S16_3 values.
| a | First factor. |
| b | Second factor. |
References Fixed_S16_3, FIXED_S16_3_PRECISION, and Fixed_S16_3::raw_value.
|
static |
Round a Fixed_S16_3 value to the nearest integer, halves away from zero.
| a | Value. |
References FIXED_S16_3_FACTOR, FIXED_S16_3_HALF, and Fixed_S16_3::raw_value.
|
static |
Multiply a Fixed_S16_3 by a Fixed_S32_16.
| a | First factor. |
| b | Second factor. |
References Fixed_S16_3, FIXED_S32_16_PRECISION, Fixed_S16_3::raw_value, and Fixed_S32_16::raw_value.
|
static |
Subtract two Fixed_S16_3 values.
| a | Minuend. |
| b | Subtrahend. |
a - b. References Fixed_S16_3, and Fixed_S16_3::raw_value.
|
static |
Add two Fixed_S32_16 values.
| a | First term. |
| b | Second term. |
References Fixed_S32_16, and Fixed_S32_16::raw_value.
|
static |
Add three Fixed_S32_16 values.
| a | First term. |
| b | Second term. |
| c | Third term. |
References Fixed_S32_16, and Fixed_S32_16::raw_value.
|
static |
Multiply two Fixed_S32_16 values.
| a | First factor. |
| b | Second factor. |
References FIXED_S32_16_PRECISION, and Fixed_S32_16::raw_value.
|
static |
Subtract two Fixed_S32_16 values.
| a | Minuend. |
| b | Subtrahend. |
a - b. References Fixed_S32_16, and Fixed_S32_16::raw_value.
|
static |
Add two Fixed_S64_32 values.
| a | First term. |
| b | Second term. |
References FIXED_S64_32_FROM_RAW, and Fixed_S64_32::raw_value.
|
static |
Add three Fixed_S64_32 values.
| a | First term. |
| b | Second term. |
| c | Third term. |
References FIXED_S64_32_FROM_RAW, and Fixed_S64_32::raw_value.
|
static |
Multiply two Fixed_S64_32 values.
| a | First factor. |
| b | Second factor. |
References Fixed_S64_32::raw_value.
|
static |
Subtract two Fixed_S64_32 values.
| a | Minuend. |
| b | Subtrahend. |
a - b. References FIXED_S64_32_FROM_RAW, and Fixed_S64_32::raw_value.
| Fixed_S64_32 math_fixed_recursive_filter | ( | Fixed_S64_32 | x, |
| int | num_input_coefficients, | ||
| int | num_output_coefficients, | ||
| const Fixed_S64_32 * | cb, | ||
| const Fixed_S64_32 * | ca, | ||
| Fixed_S64_32 * | state_x, | ||
| Fixed_S64_32 * | state_y | ||
| ) |
Run a value through an Nth order linear recursive (IIR) filter.
Computes y[n] = sum(cb[i] * x[n - i]) - sum(ca[i] * y[n - 1 - i]), a generalization of the digital biquad filter.
| x | Next input value, x[n]. | |
| num_input_coefficients | Number of input taps, at least 1. | |
| num_output_coefficients | Number of output taps. | |
| cb | Input coefficients, num_input_coefficients entries. | |
| ca | Output coefficients, num_output_coefficients entries. | |
| [in,out] | state_x | History of x, num_input_coefficients entries, kept between calls. |
| [in,out] | state_y | History of y, num_output_coefficients entries, kept between calls. |