Mozzi  version v2.0
sound synthesis library for Arduino
Fast integer based fixed-point arithmetic

Detailed Description

Note
For new sketches it is recommended to utitlize the FixMath library with its typesafe classes UFix and SFix, instead of these typedefs! See https://github.com/tomcombriat/FixMath . These are provided for backwards compatibility, only.

Fixed point fractional number types and conversion routines. Fixed point is often best for fast audio code for Arduino, and these can ease some of the pain.

Note

Take care when converting that the important bits of your numbers will fit in the types you choose!

Timing: converting between fixed and float 10-12us, converting between fixed types about 1us.

Functions

Q7n8 Q7n8_mult (Q7n8 a, Q7n8 b)
 Fast fixed point multiply for Q7n8 fractional numbers. More...
 
typedef int8_t Q0n7
 signed fractional number using 7 fractional bits, represents -0.5 to 0.496
 
typedef int8_t Q7n0
 ordinary old signed Q7n0 int8_t with 0 fractional bits, represents -128 to 127
 
typedef uint8_t Q0n8
 unsigned fractional number using 8 fractional bits, represents 0.0 to 0.996
 
typedef uint8_t Q8n0
 normal uint8_t with 0 fractional bits, represents 0.0 to 255.0
 
typedef uint16_t Q0n16
 unsigned fractional number using 16 fractional bits, represents 0.0 to 0.999
 
typedef uint32_t Q0n31
 signed number using 0 integer bits and 31 fractional bits, represents -0.2147483648 to 0.2147483647
 
typedef int16_t Q7n8
 signed fractional number using 7 integer bits and 8 fractional bits, represents -127.996 to 127.996
 
typedef uint16_t Q3n13
 unsigned fractional number using 3 integer bits and 13 fractional bits, represents 0 to 7.999
 
typedef int16_t Q1n14
 signed fractional number using 1 integer bit and 14 fractional bits, represents -1.999 to 1.999
 
typedef int16_t Q15n0
 signed number using 15 integer bits and 0 fractional bits, represents -32768 to 32767
 
typedef uint16_t Q8n8
 unsigned fractional number using 8 integer bits and 8 fractional bits, represents 0 to 255.996
 
typedef int16_t Q0n15
 signed fractional number using 0 integer bits and 15 fractional bits, represents -0.32768 to 0.32767
 
typedef uint16_t Q1n15
 unsigned fractional number using 1 integer bit and 15 fractional bits, represents 0 to 1.999
 
typedef uint16_t Q16n0
 unsigned number using 16 integer bits and 0 fractional bits, represents 0 to 65536.0
 
typedef int32_t Q23n8
 signed fractional number using 23 integer bits and 8 fractional bits, represents -8388607.996 to 8388607.996
 
typedef int32_t Q15n16
 signed fractional number using 15 integer bits and 16 fractional bits, represents -32767.999 to 32767.999
 
typedef int32_t Q31n0
 signed (normal int32_t int16_t) number using 31 integer bits and 0 fractional bits, represents -2147483648 to 2147483647
 
typedef uint32_t Q32n0
 unsigned (normal uint32_t int16_t) number using 32 integer bits and 0 fractional bits, represents 0 to 4294967295
 
typedef uint32_t Q0n32
 unsigned fractional number using 0 integer bits and 32 fractional bits, represents 0 to 0.999999999767169
 
typedef uint32_t Q8n24
 signed fractional number using 8 integer bits and 24 fractional bits, represents 0 to 255.999
 
typedef uint32_t Q24n8
 unsigned fractional number using 24 integer bits and 8 fractional bits, represents 0 to 16777215
 
typedef uint32_t Q16n16
 unsigned fractional number using 16 integer bits and 16 fractional bits, represents 0 to 65535.999
 
uint8_t uint8_tMod (uint8_t n, uint8_t d)
 fast uint8_t modulus More...
 
uint8_t uint8_tDiv (uint8_t n, uint8_t d)
 Fast uint8_t division. More...
 
uint8_t uint8_tRnd (uint8_t min, uint8_t max)
 
int ipow (int base, int exp)
 
Q16n16 Q16n16_pow2 (Q8n8 exponent)
 fast replacement for pow(2,x), where x is a Q8n8 fractional fixed-point exponent. More...
 
uint32_t isqrt32 (uint32_t n)
 
uint16_t isqrt16 (uint16_t n)
 
Q0n7 float_to_Q0n7 (float a)
 Convert float to Q0n7 fix. More...
 
Q0n8 float_to_Q0n8 (float a)
 Convert float to Q0n8 fix. More...
 
Q7n8 float_to_Q7n8 (float a)
 Convert float to Q7n8 fix. More...
 
Q8n8 float_to_Q8n8 (float a)
 Convert float to Q8n8 fix. More...
 
Q1n14 float_to_Q1n14 (float a)
 Convert float to Q1n14 fix. More...
 
Q1n15 float_to_Q1n15 (float a)
 Convert float to Q1n15 fix. More...
 
Q8n24 float_to_Q8n24 (float a)
 Convert float to Q8n24 fix. More...
 
Q23n8 float_to_Q23n8 (float a)
 Convert float to Q23n8 fix. More...
 
Q24n8 float_to_Q24n8 (float a)
 Convert float to Q24n8 fix. More...
 
Q16n16 float_to_Q16n16 (float a)
 Convert float to Q16n16 fix. More...
 
Q0n16 float_to_Q0n16 (float a)
 Convert float to Q0n16 fix. More...
 
Q15n16 float_to_Q15n16 (float a)
 Convert float to Q15n16 fix. More...
 
Q1n14 Q0n7_to_Q1n14 (Q0n7 a)
 Convert Q0n7 int8_t to Q1n14 fix. More...
 
Q15n16 Q0n7_to_Q15n16 (Q0n7 a)
 Convert Q0n7 signed int8_t to Q15n16 fix. More...
 
float Q0n7_to_float (Q0n7 a)
 Convert Q0n7 fix to float. More...
 
Q1n15 Q0n8_to_Q1n15 (Q0n8 a)
 Convert Q0n8 uint8_t to Q1n15 fix. More...
 
Q8n8 Q0n8_to_Q8n8 (Q0n8 a)
 Convert Q0n8 uint8_t to Q8n8 fix. More...
 
Q8n24 Q0n8_to_Q8n24 (Q0n8 a)
 Convert Q0n8 uint8_t to Q8n24 fix. More...
 
Q24n8 Q0n8_to_Q24n8 (Q0n8 a)
 Convert Q0n8 uint8_t to Q24n8 fix. More...
 
Q15n16 Q0n8_to_Q15n16 (Q0n8 a)
 Convert Q0n8 uint8_t to Q15n16 fix. More...
 
Q16n16 Q0n8_to_Q16n16 (Q0n8 a)
 Convert Q0n8 uint8_t to Q16n16 fix. More...
 
float Q0n8_to_float (Q0n8 a)
 Convert Q0n8 fix to float. More...
 
Q7n8 Q7n0_to_Q7n8 (Q7n0 a)
 Convert Q7n0 int8_t to Q7n8 fix. More...
 
Q15n16 Q7n0_to_Q15n16 (Q7n0 a)
 Convert Q7n0 int8_t to Q15n16 fix. More...
 
Q7n8 Q8n0_to_Q7n8 (Q8n0 a)
 Convert Q8n0 uint8_t to Q7n8 fix. More...
 
Q8n8 Q8n0_to_Q8n8 (Q8n0 a)
 Convert uint8_t to Q8n8 fix. More...
 
Q15n16 Q8n0_to_Q15n16 (Q8n0 a)
 Convert Q8n0 uint8_t to Q15n16 fix. More...
 
Q16n16 Q8n0_to_Q16n16 (Q8n0 a)
 Convert Q8n0 uint8_t to Q16n16 fix. More...
 
Q7n0 Q7n8_to_Q7n0 (Q7n8 a)
 Convert Q7n8 fix to Q7n0. More...
 
Q15n16 Q7n8_to_Q15n16 (Q7n8 a)
 Convert Q7n8 fix to Q15n16. More...
 
float Q7n8_to_float (Q7n8 a)
 Convert Q7n8 fix to float. More...
 
Q8n0 Q8n8_to_Q8n0 (Q8n8 a)
 Convert Q8n8 fix to Q8n0 uint8_t. More...
 
Q16n16 Q8n8_to_Q16n16 (Q8n8 a)
 Convert Q8n8 fix to Q16n16 uint32_t. More...
 
float Q8n8_to_float (Q8n8 a)
 Convert Q8n8 fix to float. More...
 
Q0n7 Q1n14_to_Q0n7 (Q1n14 a)
 Convert Q1n14 fixed to Q0n7 int8_t. More...
 
float Q1n14_to_float (Q1n14 a)
 Convert fix to float. More...
 
Q0n8 Q1n15_to_Q0n8 (Q1n15 a)
 Convert Q1n15 fixed to Q0n8 uint8_t. More...
 
float Q1n15_to_float (Q1n15 a)
 Convert fix to float. More...
 
float Q0n16_to_float (Q0n16 a)
 Convert fix to float. More...
 
Q15n16 Q15n0_to_Q15n16 (Q15n0 a)
 Convert Q15n0 int16_t to Q15n16 fix. More...
 
Q15n16 Q16n0_to_Q15n16 (Q16n0 a)
 Convert Q16n0 uint16_t to Q15n16 fix. More...
 
Q23n8 Q16n0_to_Q23n8 (Q16n0 a)
 Convert Q16n0 uint16_t to Q23n8 fixed point signed int32_t. More...
 
Q24n8 Q16n0_to_Q24n8 (Q16n0 a)
 Convert Q16n0 uint16_t to Q24n8 fixed point uint32_t. More...
 
Q16n16 Q16n0_to_Q16n16 (Q16n0 a)
 Convert Q16n0 uint16_t to Q16n16 fixed point uint32_t. More...
 
float Q16n0_to_float (Q16n0 a)
 Convert Q16n0 uint16_t to float. More...
 
Q0n8 Q8n24_to_Q0n8 (Q8n24 a)
 Convert Q8n24 fixed to Q0n8 uint8_t. More...
 
float Q8n24_to_float (Q8n24 a)
 Convert fix to float. More...
 
Q31n0 Q23n8_to_Q31n0 (Q23n8 a)
 Convert Q23n8 fixed to Q31n0 int32_t. More...
 
Q16n0 Q23n8_to_Q16n0 (Q23n8 a)
 Convert Q23n8 fixed to Q16n0 uint16_t. More...
 
Q15n0 Q23n8_to_Q15n0 (Q23n8 a)
 Convert Q23n8 fixed to Q15n0 signed int16_t. More...
 
Q7n8 Q23n8_to_Q7n8 (Q23n8 a)
 Convert Q23n8 fixed to Q7n8 signed int16_t, losing most significant bits. More...
 
float Q23n8_to_float (Q23n8 a)
 Convert fix to float. More...
 
Q0n8 Q24n8_to_Q0n8 (Q24n8 a)
 Convert Q24n8 fixed to Q0n8 uint8_t. More...
 
Q16n16 Q24n8_to_Q16n0 (Q24n8 a)
 Convert Q24n8 fixed to Q16n0 uint16_t. More...
 
Q32n0 Q24n8_to_Q32n0 (Q24n8 a)
 Convert Q24n8 fixed to Q32n0 uint32_t. More...
 
Q16n16 Q24n8_to_Q16n16 (Q24n8 a)
 Convert Q24n8 fixed to Q16n16 uint32_t. More...
 
float Q24n8_to_float (Q24n8 a)
 Convert fix to float. More...
 
Q0n8 Q15n16_to_Q0n8 (Q15n16 a)
 Convert Q15n16 fixed to Q0n8 uint8_t. More...
 
Q8n0 Q15n16_to_Q8n0 (Q15n16 a)
 Convert Q15n16 fixed to Q8n0 uint8_t. More...
 
Q15n0 Q15n16_to_Q15n0 (Q15n16 a)
 Convert Q15n16 fixed to Q15n0 signed int16_t. More...
 
Q7n8 Q15n16_to_Q7n8 (Q15n16 a)
 Convert Q15n16 fixed to Q7n8 signed int16_t, keeping middle bits only. More...
 
Q8n8 Q15n16_to_Q8n8 (Q15n16 a)
 Convert Q15n16 fixed to Q8n8 signed int16_t, keeping middle bits only. More...
 
Q23n8 Q15n16_to_Q23n8 (Q15n16 a)
 Convert Q15n16 fixed to Q23n8 signed int32_t. More...
 
float Q15n16_to_float (Q15n16 a)
 Convert fix to float. More...
 
Q0n8 Q16n16_to_Q0n8 (Q16n16 a)
 Convert Q16n16 fixed to Q0n8 uint8_t. More...
 
Q8n8 Q16n16_to_Q8n8 (Q8n8 a)
 Convert Q16n16 fixed to Q8n8 uint16_t. More...
 
Q16n0 Q16n16_to_Q16n0 (Q16n16 a)
 Convert Q16n16 fixed to Q16n0 uint16_t. More...
 
Q24n8 Q16n16_to_Q24n8 (Q16n16 a)
 Convert Q16n16 fixed to Q24n8 uint32_t. More...
 
float Q16n16_to_float (Q16n16 a)
 Convert fix to float. More...
 
#define Q0n7_FIX1
 0.992 in Q0n7 format
 
#define Q7n8_FIX1
 1 in Q7n8 format
 
#define Q8n8_FIX1
 1 in Q8n8 format
 
#define Q23n8_FIX1
 1 in Q23n8 format
 
#define Q1n14_FIX1
 1 in Q1n14 format
 
#define Q1n15_FIX1
 1 in Q1n15 format
 
#define Q16n16_FIX1
 1 in Q16n16 format
 
#define Q0n15_FIX1
 0.999 in Q0n15 format
 
#define Q0n16_FIX1
 0.999 in Q0n16 format
 
#define Q15n0_FIX1
 1 in Q15n0 format
 
#define Q15n16_FIX1
 1 in Q15n16 format
 
#define Q8n24_FIX1
 1 in Q8n24 format
 
#define Q0n32_FIX1
 0.999999999767169 in Q0n32 format
 
#define Q16n16_PI
 PI in Q16n16 format.
 
#define Q3n13_2PI
 2*PI in Q3n13 format
 
#define Q16n16_2PI
 2*PI in Q16n16 format
 
#define low15bits
 Useful for keeping the lower 15 bits of a Q1n15 number, using &.
 

Function Documentation

◆ float_to_Q0n16()

Q0n16 float_to_Q0n16 ( float  a)
inline

Convert float to Q0n16 fix.

Parameters
ais a float

Definition at line 130 of file mozzi_fixmath.h.

◆ float_to_Q0n7()

Q0n7 float_to_Q0n7 ( float  a)
inline

Convert float to Q0n7 fix.

Parameters
ais a float

Definition at line 100 of file mozzi_fixmath.h.

◆ float_to_Q0n8()

Q0n8 float_to_Q0n8 ( float  a)
inline

Convert float to Q0n8 fix.

Parameters
ais a float

Definition at line 103 of file mozzi_fixmath.h.

◆ float_to_Q15n16()

Q15n16 float_to_Q15n16 ( float  a)
inline

Convert float to Q15n16 fix.

Parameters
ais a float

Definition at line 133 of file mozzi_fixmath.h.

◆ float_to_Q16n16()

Q16n16 float_to_Q16n16 ( float  a)
inline

Convert float to Q16n16 fix.

Parameters
ais a float

Definition at line 127 of file mozzi_fixmath.h.

◆ float_to_Q1n14()

Q1n14 float_to_Q1n14 ( float  a)
inline

Convert float to Q1n14 fix.

Parameters
ais a float

Definition at line 112 of file mozzi_fixmath.h.

◆ float_to_Q1n15()

Q1n15 float_to_Q1n15 ( float  a)
inline

Convert float to Q1n15 fix.

Parameters
ais a float

Definition at line 115 of file mozzi_fixmath.h.

◆ float_to_Q23n8()

Q23n8 float_to_Q23n8 ( float  a)
inline

Convert float to Q23n8 fix.

Parameters
ais a float

Definition at line 121 of file mozzi_fixmath.h.

◆ float_to_Q24n8()

Q24n8 float_to_Q24n8 ( float  a)
inline

Convert float to Q24n8 fix.

Parameters
ais a float

Definition at line 124 of file mozzi_fixmath.h.

◆ float_to_Q7n8()

Q7n8 float_to_Q7n8 ( float  a)
inline

Convert float to Q7n8 fix.

Parameters
ais a float

Definition at line 106 of file mozzi_fixmath.h.

◆ float_to_Q8n24()

Q8n24 float_to_Q8n24 ( float  a)
inline

Convert float to Q8n24 fix.

Parameters
ais a float

Definition at line 118 of file mozzi_fixmath.h.

◆ float_to_Q8n8()

Q8n8 float_to_Q8n8 ( float  a)
inline

Convert float to Q8n8 fix.

Parameters
ais a float

Definition at line 109 of file mozzi_fixmath.h.

◆ Q0n16_to_float()

float Q0n16_to_float ( Q0n16  a)
inline

Convert fix to float.

Parameters
ais a Q0n16 uint16_t

Definition at line 214 of file mozzi_fixmath.h.

◆ Q0n7_to_float()

float Q0n7_to_float ( Q0n7  a)
inline

Convert Q0n7 fix to float.

Parameters
ais a Q0n7 int8_t

Definition at line 142 of file mozzi_fixmath.h.

◆ Q0n7_to_Q15n16()

Q15n16 Q0n7_to_Q15n16 ( Q0n7  a)
inline

Convert Q0n7 signed int8_t to Q15n16 fix.

Parameters
ais a Q0n7 signed int8_t

Definition at line 139 of file mozzi_fixmath.h.

◆ Q0n7_to_Q1n14()

Q1n14 Q0n7_to_Q1n14 ( Q0n7  a)
inline

Convert Q0n7 int8_t to Q1n14 fix.

Parameters
ais a Q0n7 int8_t

Definition at line 136 of file mozzi_fixmath.h.

◆ Q0n8_to_float()

float Q0n8_to_float ( Q0n8  a)
inline

Convert Q0n8 fix to float.

Parameters
ais a Q0n8 uint8_t

Definition at line 163 of file mozzi_fixmath.h.

◆ Q0n8_to_Q15n16()

Q15n16 Q0n8_to_Q15n16 ( Q0n8  a)
inline

Convert Q0n8 uint8_t to Q15n16 fix.

Parameters
ais a Q0n8 uint8_t

Definition at line 157 of file mozzi_fixmath.h.

◆ Q0n8_to_Q16n16()

Q16n16 Q0n8_to_Q16n16 ( Q0n8  a)
inline

Convert Q0n8 uint8_t to Q16n16 fix.

Parameters
ais a Q0n8 uint8_t

Definition at line 160 of file mozzi_fixmath.h.

◆ Q0n8_to_Q1n15()

Q1n15 Q0n8_to_Q1n15 ( Q0n8  a)
inline

Convert Q0n8 uint8_t to Q1n15 fix.

Parameters
ais a Q0n8 uint8_t

Definition at line 145 of file mozzi_fixmath.h.

◆ Q0n8_to_Q24n8()

Q24n8 Q0n8_to_Q24n8 ( Q0n8  a)
inline

Convert Q0n8 uint8_t to Q24n8 fix.

Parameters
ais a Q0n8 uint8_t

Definition at line 154 of file mozzi_fixmath.h.

◆ Q0n8_to_Q8n24()

Q8n24 Q0n8_to_Q8n24 ( Q0n8  a)
inline

Convert Q0n8 uint8_t to Q8n24 fix.

Parameters
ais a Q0n8 uint8_t

Definition at line 151 of file mozzi_fixmath.h.

◆ Q0n8_to_Q8n8()

Q8n8 Q0n8_to_Q8n8 ( Q0n8  a)
inline

Convert Q0n8 uint8_t to Q8n8 fix.

Parameters
ais a Q0n8 uint8_t

Definition at line 148 of file mozzi_fixmath.h.

◆ Q15n0_to_Q15n16()

Q15n16 Q15n0_to_Q15n16 ( Q15n0  a)
inline

Convert Q15n0 int16_t to Q15n16 fix.

Parameters
ais a Q15n0 int16_t

Definition at line 217 of file mozzi_fixmath.h.

◆ Q15n16_to_float()

float Q15n16_to_float ( Q15n16  a)
inline

Convert fix to float.

Parameters
ais a Q15n16 signed int32_t

Definition at line 291 of file mozzi_fixmath.h.

◆ Q15n16_to_Q0n8()

Q0n8 Q15n16_to_Q0n8 ( Q15n16  a)
inline

Convert Q15n16 fixed to Q0n8 uint8_t.

Only for positive values!

Parameters
ais a Q15n16 signed int32_t

Definition at line 273 of file mozzi_fixmath.h.

◆ Q15n16_to_Q15n0()

Q15n0 Q15n16_to_Q15n0 ( Q15n16  a)
inline

Convert Q15n16 fixed to Q15n0 signed int16_t.

Parameters
ais a Q15n16 signed int32_t

Definition at line 279 of file mozzi_fixmath.h.

◆ Q15n16_to_Q23n8()

Q23n8 Q15n16_to_Q23n8 ( Q15n16  a)
inline

Convert Q15n16 fixed to Q23n8 signed int32_t.

Parameters
ais a Q15n16 signed int32_t.

Definition at line 288 of file mozzi_fixmath.h.

◆ Q15n16_to_Q7n8()

Q7n8 Q15n16_to_Q7n8 ( Q15n16  a)
inline

Convert Q15n16 fixed to Q7n8 signed int16_t, keeping middle bits only.

Parameters
ais a Q15n16 signed int32_t.

Definition at line 282 of file mozzi_fixmath.h.

◆ Q15n16_to_Q8n0()

Q8n0 Q15n16_to_Q8n0 ( Q15n16  a)
inline

Convert Q15n16 fixed to Q8n0 uint8_t.

Only for positive values!

Parameters
ais a Q15n16 signed int32_t

Definition at line 276 of file mozzi_fixmath.h.

◆ Q15n16_to_Q8n8()

Q8n8 Q15n16_to_Q8n8 ( Q15n16  a)
inline

Convert Q15n16 fixed to Q8n8 signed int16_t, keeping middle bits only.

Parameters
ais a Q15n16 signed int32_t.

Definition at line 285 of file mozzi_fixmath.h.

◆ Q16n0_to_float()

float Q16n0_to_float ( Q16n0  a)
inline

Convert Q16n0 uint16_t to float.

Parameters
ais a Q16n0 uint16_t

Definition at line 232 of file mozzi_fixmath.h.

◆ Q16n0_to_Q15n16()

Q15n16 Q16n0_to_Q15n16 ( Q16n0  a)
inline

Convert Q16n0 uint16_t to Q15n16 fix.

Parameters
ais a Q16n0 uint16_t

Definition at line 220 of file mozzi_fixmath.h.

◆ Q16n0_to_Q16n16()

Q16n16 Q16n0_to_Q16n16 ( Q16n0  a)
inline

Convert Q16n0 uint16_t to Q16n16 fixed point uint32_t.

Parameters
ais a Q16n0 uint16_t

Definition at line 229 of file mozzi_fixmath.h.

◆ Q16n0_to_Q23n8()

Q23n8 Q16n0_to_Q23n8 ( Q16n0  a)
inline

Convert Q16n0 uint16_t to Q23n8 fixed point signed int32_t.

Parameters
ais a Q16n0 uint16_t

Definition at line 223 of file mozzi_fixmath.h.

◆ Q16n0_to_Q24n8()

Q24n8 Q16n0_to_Q24n8 ( Q16n0  a)
inline

Convert Q16n0 uint16_t to Q24n8 fixed point uint32_t.

Parameters
ais a Q16n0 uint16_t

Definition at line 226 of file mozzi_fixmath.h.

◆ Q16n16_pow2()

Q16n16 Q16n16_pow2 ( Q8n8  exponent)

fast replacement for pow(2,x), where x is a Q8n8 fractional fixed-point exponent.

It's less accurate than pow(2,x), but useful where a tradeoff between accuracy and speed is required to keep audio from glitching.

Parameters
exponentin Q8n8 format.
Returns
pow(2,x) in Q16n16 format.

Definition at line 116 of file mozzi_fixmath.cpp.

◆ Q16n16_to_float()

float Q16n16_to_float ( Q16n16  a)
inline

Convert fix to float.

Parameters
ais a Q16n16 uint32_t

Definition at line 306 of file mozzi_fixmath.h.

◆ Q16n16_to_Q0n8()

Q0n8 Q16n16_to_Q0n8 ( Q16n16  a)
inline

Convert Q16n16 fixed to Q0n8 uint8_t.

Parameters
ais a Q16n16 uint32_t

Definition at line 294 of file mozzi_fixmath.h.

◆ Q16n16_to_Q16n0()

Q16n0 Q16n16_to_Q16n0 ( Q16n16  a)
inline

Convert Q16n16 fixed to Q16n0 uint16_t.

Parameters
ais a Q16n16 uint32_t

Definition at line 300 of file mozzi_fixmath.h.

◆ Q16n16_to_Q24n8()

Q24n8 Q16n16_to_Q24n8 ( Q16n16  a)
inline

Convert Q16n16 fixed to Q24n8 uint32_t.

Parameters
ais a Q16n16 uint32_t

Definition at line 303 of file mozzi_fixmath.h.

◆ Q16n16_to_Q8n8()

Q8n8 Q16n16_to_Q8n8 ( Q8n8  a)
inline

Convert Q16n16 fixed to Q8n8 uint16_t.

Parameters
ais a Q16n16 uint32_t

Definition at line 297 of file mozzi_fixmath.h.

◆ Q1n14_to_float()

float Q1n14_to_float ( Q1n14  a)
inline

Convert fix to float.

Parameters
ais an int16_t

Definition at line 205 of file mozzi_fixmath.h.

◆ Q1n14_to_Q0n7()

Q0n7 Q1n14_to_Q0n7 ( Q1n14  a)
inline

Convert Q1n14 fixed to Q0n7 int8_t.

Parameters
ais a Q1n14 int16_t

Definition at line 202 of file mozzi_fixmath.h.

◆ Q1n15_to_float()

float Q1n15_to_float ( Q1n15  a)
inline

Convert fix to float.

Parameters
ais a Q1n15 uint16_t

Definition at line 211 of file mozzi_fixmath.h.

◆ Q1n15_to_Q0n8()

Q0n8 Q1n15_to_Q0n8 ( Q1n15  a)
inline

Convert Q1n15 fixed to Q0n8 uint8_t.

Only for positive values!

Parameters
ais a Q1n15 uint16_t

Definition at line 208 of file mozzi_fixmath.h.

◆ Q23n8_to_float()

float Q23n8_to_float ( Q23n8  a)
inline

Convert fix to float.

Parameters
ais a Q23n8 signed int32_t

Definition at line 255 of file mozzi_fixmath.h.

◆ Q23n8_to_Q15n0()

Q15n0 Q23n8_to_Q15n0 ( Q23n8  a)
inline

Convert Q23n8 fixed to Q15n0 signed int16_t.

Parameters
ais a Q23n8 int32_t

Definition at line 248 of file mozzi_fixmath.h.

◆ Q23n8_to_Q16n0()

Q16n0 Q23n8_to_Q16n0 ( Q23n8  a)
inline

Convert Q23n8 fixed to Q16n0 uint16_t.

Positive values only.

Parameters
ais a Q23n8 int32_t

Definition at line 245 of file mozzi_fixmath.h.

◆ Q23n8_to_Q31n0()

Q31n0 Q23n8_to_Q31n0 ( Q23n8  a)
inline

Convert Q23n8 fixed to Q31n0 int32_t.

Parameters
ais a Q23n8 int32_t

Definition at line 242 of file mozzi_fixmath.h.

◆ Q23n8_to_Q7n8()

Q7n8 Q23n8_to_Q7n8 ( Q23n8  a)
inline

Convert Q23n8 fixed to Q7n8 signed int16_t, losing most significant bits.

Parameters
ais a Q23n8 signed int32_t.

Definition at line 251 of file mozzi_fixmath.h.

◆ Q24n8_to_float()

float Q24n8_to_float ( Q24n8  a)
inline

Convert fix to float.

Parameters
ais a Q24n8 uint32_t

Definition at line 270 of file mozzi_fixmath.h.

◆ Q24n8_to_Q0n8()

Q0n8 Q24n8_to_Q0n8 ( Q24n8  a)
inline

Convert Q24n8 fixed to Q0n8 uint8_t.

Parameters
ais a Q24n8 uint32_t

Definition at line 258 of file mozzi_fixmath.h.

◆ Q24n8_to_Q16n0()

Q16n16 Q24n8_to_Q16n0 ( Q24n8  a)
inline

Convert Q24n8 fixed to Q16n0 uint16_t.

Parameters
ais a Q24n8 uint32_t

Definition at line 261 of file mozzi_fixmath.h.

◆ Q24n8_to_Q16n16()

Q16n16 Q24n8_to_Q16n16 ( Q24n8  a)
inline

Convert Q24n8 fixed to Q16n16 uint32_t.

Parameters
ais a Q24n8 uint32_t

Definition at line 267 of file mozzi_fixmath.h.

◆ Q24n8_to_Q32n0()

Q32n0 Q24n8_to_Q32n0 ( Q24n8  a)
inline

Convert Q24n8 fixed to Q32n0 uint32_t.

Parameters
ais a Q24n8 uint32_t

Definition at line 264 of file mozzi_fixmath.h.

◆ Q7n0_to_Q15n16()

Q15n16 Q7n0_to_Q15n16 ( Q7n0  a)
inline

Convert Q7n0 int8_t to Q15n16 fix.

Parameters
ais a int8_t

Definition at line 169 of file mozzi_fixmath.h.

◆ Q7n0_to_Q7n8()

Q7n8 Q7n0_to_Q7n8 ( Q7n0  a)
inline

Convert Q7n0 int8_t to Q7n8 fix.

Parameters
ais a int8_t

Definition at line 166 of file mozzi_fixmath.h.

◆ Q7n8_mult()

Q7n8 Q7n8_mult ( Q7n8  a,
Q7n8  b 
)
inline

Fast fixed point multiply for Q7n8 fractional numbers.

Parameters
aQ7n8 format multiplicand
bQ7n8 format multiplier
Returns
a Q7n8 format product

Definition at line 346 of file mozzi_fixmath.h.

◆ Q7n8_to_float()

float Q7n8_to_float ( Q7n8  a)
inline

Convert Q7n8 fix to float.

Parameters
ais a Q7n8 int16_t

Definition at line 190 of file mozzi_fixmath.h.

◆ Q7n8_to_Q15n16()

Q15n16 Q7n8_to_Q15n16 ( Q7n8  a)
inline

Convert Q7n8 fix to Q15n16.

Parameters
ais a Q7n8 int16_t

Definition at line 187 of file mozzi_fixmath.h.

◆ Q7n8_to_Q7n0()

Q7n0 Q7n8_to_Q7n0 ( Q7n8  a)
inline

Convert Q7n8 fix to Q7n0.

Parameters
ais a Q7n8 int16_t

Definition at line 184 of file mozzi_fixmath.h.

◆ Q8n0_to_Q15n16()

Q15n16 Q8n0_to_Q15n16 ( Q8n0  a)
inline

Convert Q8n0 uint8_t to Q15n16 fix.

Parameters
ais a Q8n0 uint8_t

Definition at line 178 of file mozzi_fixmath.h.

◆ Q8n0_to_Q16n16()

Q16n16 Q8n0_to_Q16n16 ( Q8n0  a)
inline

Convert Q8n0 uint8_t to Q16n16 fix.

Parameters
ais a Q8n0 uint8_t

Definition at line 181 of file mozzi_fixmath.h.

◆ Q8n0_to_Q7n8()

Q7n8 Q8n0_to_Q7n8 ( Q8n0  a)
inline

Convert Q8n0 uint8_t to Q7n8 fix.

Parameters
ais a Q8n0 uint8_t*. Beware of overflow.

Definition at line 172 of file mozzi_fixmath.h.

◆ Q8n0_to_Q8n8()

Q8n8 Q8n0_to_Q8n8 ( Q8n0  a)
inline

Convert uint8_t to Q8n8 fix.

Parameters
ais a Q8n0 uint8_t

Definition at line 175 of file mozzi_fixmath.h.

◆ Q8n24_to_float()

float Q8n24_to_float ( Q8n24  a)
inline

Convert fix to float.

Parameters
ais a Q8n24 uint32_t

Definition at line 238 of file mozzi_fixmath.h.

◆ Q8n24_to_Q0n8()

Q0n8 Q8n24_to_Q0n8 ( Q8n24  a)
inline

Convert Q8n24 fixed to Q0n8 uint8_t.

Parameters
ais a Q8n24 uint32_t

Definition at line 235 of file mozzi_fixmath.h.

◆ Q8n8_to_float()

float Q8n8_to_float ( Q8n8  a)
inline

Convert Q8n8 fix to float.

Parameters
ais a Q8n8 uint16_t

Definition at line 199 of file mozzi_fixmath.h.

◆ Q8n8_to_Q16n16()

Q16n16 Q8n8_to_Q16n16 ( Q8n8  a)
inline

Convert Q8n8 fix to Q16n16 uint32_t.

Parameters
ais a Q8n8 uint16_t

Definition at line 196 of file mozzi_fixmath.h.

◆ Q8n8_to_Q8n0()

Q8n0 Q8n8_to_Q8n0 ( Q8n8  a)
inline

Convert Q8n8 fix to Q8n0 uint8_t.

Parameters
ais a Q8n8 uint16_t

Definition at line 193 of file mozzi_fixmath.h.

◆ uint8_tDiv()

uint8_t uint8_tDiv ( uint8_t  n,
uint8_t  d 
)

Fast uint8_t division.

Parameters
nnumerator
ddenominator
Returns
quotient

Definition at line 48 of file mozzi_fixmath.cpp.

◆ uint8_tMod()

uint8_t uint8_tMod ( uint8_t  n,
uint8_t  d 
)

fast uint8_t modulus

Parameters
nnumerator
ddenominator
Returns
modulus

Definition at line 36 of file mozzi_fixmath.cpp.