Mozzi  version v2.0
sound synthesis library for Arduino
mozzi_fixmath.h
1 /*
2  * mozzi_fixmath.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2012-2024 Tim Barrass and the Mozzi Team
7  *
8  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
9  *
10  */
11 
12 #ifndef FIXEDMATH_H_
13 #define FIXEDMATH_H_
14 
15 #include <Arduino.h>
16 
30 // types
31 typedef int8_t Q0n7;
32 typedef int8_t Q7n0;
33 typedef uint8_t Q0n8;
34 typedef uint8_t Q8n0;
35 typedef uint16_t Q0n16;
36 typedef uint32_t Q0n31;
37 typedef int16_t Q7n8;
38 typedef uint16_t Q3n13;
39 typedef int16_t Q1n14;
40 typedef int16_t Q15n0;
41 typedef uint16_t Q8n8;
42 typedef int16_t Q0n15;
43 typedef uint16_t Q1n15;
44 typedef uint16_t Q16n0;
45 typedef int32_t Q23n8;
46 typedef int32_t Q15n16;
47 typedef int32_t Q31n0;
48 typedef uint32_t Q32n0;
49 typedef uint32_t Q0n32;
50 typedef uint32_t Q8n24;
51 typedef uint32_t Q24n8;
52 typedef uint32_t Q16n16;
58 // macros to save runtime calculations for representations of 1
59 #define Q0n7_FIX1 ((Q0n7) 127)
60 #define Q7n8_FIX1 ((Q7n8) 256)
61 #define Q8n8_FIX1 ((Q8n8) 256)
62 #define Q23n8_FIX1 ((Q23n8) 256)
63 #define Q1n14_FIX1 ((Q1n14) 16384)
64 #define Q1n15_FIX1 ((Q1n15) 32768)
65 #define Q16n16_FIX1 ((Q16n16) 65536)
66 #define Q0n15_FIX1 ((Q0n15) 32767)
67 #define Q0n16_FIX1 ((Q0n16) 65535)
68 #define Q15n0_FIX1 ((Q15n0) 16384)
69 #define Q15n16_FIX1 ((Q15n16) 65536)
70 #define Q8n24_FIX1 ((Q8n24) 16777216)
71 #define Q0n32_FIX1 ((Q0n32) 4294967295)
73 #define Q16n16_PI ((Q16n16) 205887)
74 #define Q3n13_2PI ((Q3n13) 411775)
75 #define Q16n16_2PI ((Q16n16) 411775)
77 #define low15bits ((Q1n15) 32767)
81 /*
82 Type conversions: Float to Q
83 
84 To convert a number from floating point to Qm.n format:
85 
86  Multiply the floating point number by 2^n
87  Round to the nearest integer
88 
89 Q to float
90 
91 To convert a number from Qm.n format to floating point:
92 
93  Convert the number to floating point as if it were an integer
94  Multiply by 2^-n
95 */
99 inline
100 Q0n7 float_to_Q0n7(float a) { return static_cast<Q0n7>(a*256); }
102 inline
103 Q0n8 float_to_Q0n8(float a) { return static_cast<Q0n8>(a*256); }
105 inline
106 Q7n8 float_to_Q7n8(float a) { return static_cast<Q7n8>(a*256); }
108 inline
109 Q8n8 float_to_Q8n8(float a) { return static_cast<Q8n8>(a*256); }
111 inline
112 Q1n14 float_to_Q1n14(float a) { return static_cast<Q1n14>(a*16384); }
114 inline
115 Q1n15 float_to_Q1n15(float a) { return static_cast<Q1n15>(a*32768); }
117 inline
118 Q8n24 float_to_Q8n24(float a) { return static_cast<Q8n24>(a*16777216); }
120 inline
121 Q23n8 float_to_Q23n8(float a) { return static_cast<Q23n8>(a*256); }
123 inline
124 Q24n8 float_to_Q24n8(float a) { return static_cast<Q24n8>(a*256); }
126 inline
127 Q16n16 float_to_Q16n16(float a) { return static_cast<Q16n16>(a*65536); }
129 inline
130 Q0n16 float_to_Q0n16(float a) { return static_cast<Q0n16>(a*65536); }
132 inline
133 Q15n16 float_to_Q15n16(float a) { return static_cast<Q15n16>(a*65536); }
135 inline
136 Q1n14 Q0n7_to_Q1n14(Q0n7 a) { return (static_cast<Q1n14>(a))<<7; }
138 inline
139 Q15n16 Q0n7_to_Q15n16(Q0n7 a) { return (static_cast<Q15n16>(a))<<8; }
141 inline
142 float Q0n7_to_float(Q0n7 a) { return (static_cast<float>(a))/256; }
144 inline
145 Q1n15 Q0n8_to_Q1n15(Q0n8 a) { return (static_cast<Q1n15>(a))<<7; }
147 inline
148 Q8n8 Q0n8_to_Q8n8(Q0n8 a) { return (static_cast<Q8n8>(a))<<8; }
150 inline
151 Q8n24 Q0n8_to_Q8n24(Q0n8 a) { return (static_cast<Q8n24>(a))<<16; }
153 inline
154 Q24n8 Q0n8_to_Q24n8(Q0n8 a) { return (static_cast<Q24n8>(a))<<8; }
156 inline
157 Q15n16 Q0n8_to_Q15n16(Q0n8 a) { return (static_cast<Q15n16>(a))<<8; }
159 inline
160 Q16n16 Q0n8_to_Q16n16(Q0n8 a) { return (static_cast<Q16n16>(a))<<8; }
162 inline
163 float Q0n8_to_float(Q0n8 a) { return (static_cast<float>(a))/256; }
165 inline
166 Q7n8 Q7n0_to_Q7n8(Q7n0 a) { return (static_cast<Q7n8>(a))<<8; }
168 inline
169 Q15n16 Q7n0_to_Q15n16(Q7n0 a) { return (static_cast<Q15n16>(a))<<16; }
171 inline
172 Q7n8 Q8n0_to_Q7n8(Q8n0 a) { return (static_cast<Q7n8>(a))<<8; }
174 inline
175 Q8n8 Q8n0_to_Q8n8(Q8n0 a) { return (static_cast<Q8n8>(a))<<8; }
177 inline
178 Q15n16 Q8n0_to_Q15n16(Q8n0 a) { return (static_cast<Q15n16>(a))<<16; }
180 inline
181 Q16n16 Q8n0_to_Q16n16(Q8n0 a) { return (static_cast<Q16n16>(a))<<16; }
183 inline
184 Q7n0 Q7n8_to_Q7n0(Q7n8 a) { return static_cast<Q7n0>((Q7n8)a>>8); }
186 inline
187 Q15n16 Q7n8_to_Q15n16(Q7n8 a) { return (static_cast<Q15n16>(a))<<8; }
189 inline
190 float Q7n8_to_float(Q7n8 a) { return (static_cast<float>(a))/256; }
192 inline
193 Q8n0 Q8n8_to_Q8n0(Q8n8 a) { return static_cast<Q8n0>((Q8n8)a>>8); }
195 inline
196 Q16n16 Q8n8_to_Q16n16(Q8n8 a) { return (static_cast<Q16n16>(a))<<8; }
198 inline
199 float Q8n8_to_float(Q8n8 a) { return (static_cast<float>(a))/256; }
201 inline
202 Q0n7 Q1n14_to_Q0n7(Q1n14 a) { return static_cast<Q0n7>((Q1n14)a>>7); }
204 inline
205 float Q1n14_to_float(Q1n14 a) { return (static_cast<float>(a))/16384; }
207 inline
208 Q0n8 Q1n15_to_Q0n8(Q1n15 a) { return static_cast<Q0n8>((Q1n15)a>>7); }
210 inline
211 float Q1n15_to_float(Q1n15 a) { return (static_cast<float>(a))/32768; }
213 inline
214 float Q0n16_to_float(Q0n16 a) { return (static_cast<float>(a))/65536; }
216 inline
217 Q15n16 Q15n0_to_Q15n16(Q15n0 a) { return (static_cast<Q15n16>(a))<<16; }
219 inline
220 Q15n16 Q16n0_to_Q15n16(Q16n0 a) { return (static_cast<Q15n16>(a))<<16; }
222 inline
223 Q23n8 Q16n0_to_Q23n8(Q16n0 a) { return (static_cast<Q23n8>(a))<<8; }
225 inline
226 Q24n8 Q16n0_to_Q24n8(Q16n0 a) { return (static_cast<Q24n8>(a))<<8; }
228 inline
229 Q16n16 Q16n0_to_Q16n16(Q16n0 a) { return (static_cast<Q16n16>(a))<<16; }
231 inline
232 float Q16n0_to_float(Q16n0 a) { return (static_cast<float>(a)); }
234 inline
235 Q0n8 Q8n24_to_Q0n8(Q8n24 a) { return static_cast<Q0n8>((Q8n24)a>>16); }
237 inline
238 float Q8n24_to_float(Q8n24 a) { return (static_cast<float>(a))/16777216; }
241 inline
242 Q31n0 Q23n8_to_Q31n0(Q23n8 a) { return static_cast<Q31n0>((Q23n8)a>>8); }
244 inline
245 Q16n0 Q23n8_to_Q16n0(Q23n8 a) { return static_cast<Q16n0>((Q23n8)a>>8); }
247 inline
248 Q15n0 Q23n8_to_Q15n0(Q23n8 a) { return static_cast<Q15n0>((Q23n8)a>>8); }
250 inline
251 Q7n8 Q23n8_to_Q7n8(Q23n8 a) { return static_cast<Q7n8>(a); }
254 inline
255 float Q23n8_to_float(Q23n8 a) { return (static_cast<float>(a))/256; }
257 inline
258 Q0n8 Q24n8_to_Q0n8(Q24n8 a) { return static_cast<Q0n8>(a); }
260 inline
261 Q16n16 Q24n8_to_Q16n0(Q24n8 a) { return (static_cast<Q16n0>((Q24n8)a))>>8; }
263 inline
264 Q32n0 Q24n8_to_Q32n0(Q24n8 a) { return static_cast<Q32n0>((Q24n8)a>>8); }
266 inline
267 Q16n16 Q24n8_to_Q16n16(Q24n8 a) { return (static_cast<Q16n16>(a))<<8; }
269 inline
270 float Q24n8_to_float(Q24n8 a) { return (static_cast<float>(a))/256; }
272 inline
273 Q0n8 Q15n16_to_Q0n8(Q15n16 a) { return static_cast<Q0n8>((Q15n16)a>>8); }
275 inline
276 Q8n0 Q15n16_to_Q8n0(Q15n16 a) { return static_cast<Q8n0>((Q15n16)a>>16); }
278 inline
279 Q15n0 Q15n16_to_Q15n0(Q15n16 a) { return static_cast<Q15n0>((Q15n16)a>>16); }
281 inline
282 Q7n8 Q15n16_to_Q7n8(Q15n16 a) { return static_cast<Q7n8>((Q15n16)a>>8); }
284 inline
285 Q8n8 Q15n16_to_Q8n8(Q15n16 a) { return static_cast<Q8n8>((Q15n16)a>>8); }
287 inline
288 Q23n8 Q15n16_to_Q23n8(Q15n16 a) { return static_cast<Q23n8>((Q15n16)a>>8); }
290 inline
291 float Q15n16_to_float(Q15n16 a) { return (static_cast<float>(a))/65536; }
293 inline
294 Q0n8 Q16n16_to_Q0n8(Q16n16 a) { return static_cast<Q0n8>((Q16n16)a>>8); }
296 inline
297 Q8n8 Q16n16_to_Q8n8(Q8n8 a) { return static_cast<Q8n8>((Q16n16)a>>16); }
299 inline
300 Q16n0 Q16n16_to_Q16n0(Q16n16 a) { return static_cast<Q16n0>((Q16n16)a>>16); }
302 inline
303 Q24n8 Q16n16_to_Q24n8(Q16n16 a) { return static_cast<Q24n8>((Q16n16)a>>8); }
305 inline
306 float Q16n16_to_float(Q16n16 a) { return (static_cast<float>(a))/65536; }
309 /* @ingroup fixmath
310 Fast (?) fixed point multiply for Q7n8 fractional numbers.
311 The c version below is 3 times faster, and not subject to the same overflow limitations (+-3.99, or +-2048)
312 @param a Q7n8 format multiplicand
313 @param b Q7n8 format multiplier
314 @return a Q7n8 format product
315 */
316 /*
317 #define Q7n8_mult(a,b) \
318 ({ \
319 int16_t prod, val1=a, val2=b ; \
320 __asm__ __volatile__ ( \
321  "muls %B1, %B2 \n\t" \
322  "mov %B0, r0 \n\t" \
323  "mul %A1, %A2\n\t" \
324  "mov %A0, r1 \n\t" \
325  "mulsu %B1, %A2 \n\t" \
326  "add %A0, r0 \n\t" \
327  "adc %B0, r1 \n\t" \
328  "mulsu %B2, %A1 \n\t" \
329  "add %A0, r0 \n\t" \
330  "adc %B0, r1 \n\t" \
331  "clr r1 \n\t" \
332  : "=&d" (prod) \
333  : "a" (val1), "a" (val2) \
334  ); \
335  prod; \
336 })
337 */
338 
345 inline
347  return ((int16_t)((((int32_t)(a))*(b))>>8));
348 }
349 
350 
351 /*
352 #define FMULS8(v1, v2) \
353 ({ \
354  uint8_t res; \
355  uint8_t val1 = v1; \
356  uint8_t val2 = v2; \
357  __asm__ __volatile__ \
358  ( \
359  "fmuls $1, $2" "\n\t" \
360  "mov $0, r1" "\n\t" \
361  "clr r1" "\n\t" \
362  : "=&d" (res) \
363  : "a" (val1), "a" (val2) \
364  ); \
365  res; \
366 }) */
367 
368 
369 /*
370 // from octosynth, Joe Marshall 2011:
371 
372  // multiply 2 16 bit numbers together and shift 8 without precision loss
373  // requires assembler really
374  volatile uint8_t zeroReg=0;
375  volatile uint16_t multipliedCounter=oscillators[c].phaseStep;
376  asm volatile
377  (
378  // high uint8_ts mult together = high uint8_t
379  "ldi %A[outVal],0" "\n\t"
380  "mul %B[phaseStep],%B[pitchB}]" "\n\t"
381  "mov %B[outVal],r0" "\n\t"
382  // ignore overflow into r1 (should never overflow)
383  // low uint8_t * high uint8_t -> both uint8_ts
384  "mul %A[phaseStep],%B[pitchB}]" "\n\t"
385  "add %A[outVal],r0" "\n\t"
386  // carry into high uint8_t
387  "adc %B[outVal],r1" "\n\t"
388  // high uint8_t* low uint8_t -> both uint8_ts
389  "mul %B[phaseStep],%A[pitchB}]" "\n\t"
390  "add %A[outVal],r0" "\n\t"
391  // carry into high uint8_t
392  "adc %B[outVal],r1" "\n\t"
393  // low uint8_t * low uint8_t -> round
394  "mul %A[phaseStep],%A[pitchB}]" "\n\t"
395  // the adc below is to round up based on high bit of low*low:
396  "adc %A[outVal],r1" "\n\t"
397  "adc %B[outVal],%[ZERO]" "\n\t"
398  "clr r1" "\n\t"
399  :[outVal] "=&d" (multipliedCounter)
400  :[phaseStep] "d" (oscillators[c].phaseStep),[pitchB}] "d"( pitchB}Multiplier),[ZERO] "d" (zeroReg)
401  :"r1","r0"
402  );
403  oscillators[c].phaseStep=multipliedCounter;
404 
405  */
406 
407 
408 
409 int16_t ipow(int16_t base, int16_t exp);
411 Q16n16 Q16n16_pow2(Q8n8 exponent);
412 
413 uint8_t uint8_tMod(uint8_t n, uint8_t d);
414 uint8_t uint8_tDiv(uint8_t n, uint8_t d);
415 uint8_t uint8_tRnd(uint8_t min, uint8_t max);
416 uint16_t isqrt16(uint16_t n);
417 uint32_t isqrt32(uint32_t n);
418 
419 #endif /* FIXEDMATH_H_ */
Q0n8 float_to_Q0n8(float a)
Convert float to Q0n8 fix.
Q16n16 float_to_Q16n16(float a)
Convert float to Q16n16 fix.
float Q0n16_to_float(Q0n16 a)
Convert fix to float.
Q8n8 Q0n8_to_Q8n8(Q0n8 a)
Convert Q0n8 uint8_t to Q8n8 fix.
Q0n8 Q8n24_to_Q0n8(Q8n24 a)
Convert Q8n24 fixed to Q0n8 uint8_t.
uint8_t uint8_tMod(uint8_t n, uint8_t d)
fast uint8_t modulus
Q15n16 float_to_Q15n16(float a)
Convert float to Q15n16 fix.
Q0n8 Q16n16_to_Q0n8(Q16n16 a)
Convert Q16n16 fixed to Q0n8 uint8_t.
Q8n0 Q15n16_to_Q8n0(Q15n16 a)
Convert Q15n16 fixed to Q8n0 uint8_t.
uint8_t uint8_tDiv(uint8_t n, uint8_t d)
Fast uint8_t division.
Q24n8 Q16n16_to_Q24n8(Q16n16 a)
Convert Q16n16 fixed to Q24n8 uint32_t.
Q1n14 float_to_Q1n14(float a)
Convert float to Q1n14 fix.
Q15n0 Q23n8_to_Q15n0(Q23n8 a)
Convert Q23n8 fixed to Q15n0 signed int16_t.
Q0n7 float_to_Q0n7(float a)
Convert float to Q0n7 fix.
Q7n8 Q15n16_to_Q7n8(Q15n16 a)
Convert Q15n16 fixed to Q7n8 signed int16_t, keeping middle bits only.
Q7n8 float_to_Q7n8(float a)
Convert float to Q7n8 fix.
Q16n16 Q24n8_to_Q16n16(Q24n8 a)
Convert Q24n8 fixed to Q16n16 uint32_t.
uint16_t Q3n13
unsigned fractional number using 3 integer bits and 13 fractional bits, represents 0 to 7....
Definition: mozzi_fixmath.h:38
Q23n8 float_to_Q23n8(float a)
Convert float to Q23n8 fix.
Q16n16 Q16n16_pow2(Q8n8 exponent)
fast replacement for pow(2,x), where x is a Q8n8 fractional fixed-point exponent.
Q7n8 Q7n8_mult(Q7n8 a, Q7n8 b)
Fast fixed point multiply for Q7n8 fractional numbers.
Q8n24 float_to_Q8n24(float a)
Convert float to Q8n24 fix.
Q8n8 float_to_Q8n8(float a)
Convert float to Q8n8 fix.
uint8_t Q0n8
unsigned fractional number using 8 fractional bits, represents 0.0 to 0.996
Definition: mozzi_fixmath.h:33
uint16_t Q0n16
unsigned fractional number using 16 fractional bits, represents 0.0 to 0.999
Definition: mozzi_fixmath.h:35
int32_t Q15n16
signed fractional number using 15 integer bits and 16 fractional bits, represents -32767....
Definition: mozzi_fixmath.h:46
float Q15n16_to_float(Q15n16 a)
Convert fix to float.
Q1n15 float_to_Q1n15(float a)
Convert float to Q1n15 fix.
Q1n14 Q0n7_to_Q1n14(Q0n7 a)
Convert Q0n7 int8_t to Q1n14 fix.
float Q23n8_to_float(Q23n8 a)
Convert fix to float.
Q7n8 Q8n0_to_Q7n8(Q8n0 a)
Convert Q8n0 uint8_t to Q7n8 fix.
Q0n16 float_to_Q0n16(float a)
Convert float to Q0n16 fix.
uint16_t Q16n0
unsigned number using 16 integer bits and 0 fractional bits, represents 0 to 65536....
Definition: mozzi_fixmath.h:44
Q16n16 Q8n0_to_Q16n16(Q8n0 a)
Convert Q8n0 uint8_t to Q16n16 fix.
int32_t Q31n0
signed (normal int32_t int16_t) number using 31 integer bits and 0 fractional bits,...
Definition: mozzi_fixmath.h:47
uint32_t Q8n24
signed fractional number using 8 integer bits and 24 fractional bits, represents 0 to 255....
Definition: mozzi_fixmath.h:50
Q0n7 Q1n14_to_Q0n7(Q1n14 a)
Convert Q1n14 fixed to Q0n7 int8_t.
Q15n16 Q7n0_to_Q15n16(Q7n0 a)
Convert Q7n0 int8_t to Q15n16 fix.
int16_t Q7n8
signed fractional number using 7 integer bits and 8 fractional bits, represents -127....
Definition: mozzi_fixmath.h:37
Q23n8 Q15n16_to_Q23n8(Q15n16 a)
Convert Q15n16 fixed to Q23n8 signed int32_t.
Q0n8 Q1n15_to_Q0n8(Q1n15 a)
Convert Q1n15 fixed to Q0n8 uint8_t.
float Q8n24_to_float(Q8n24 a)
Convert fix to float.
Q15n16 Q16n0_to_Q15n16(Q16n0 a)
Convert Q16n0 uint16_t to Q15n16 fix.
Q24n8 Q16n0_to_Q24n8(Q16n0 a)
Convert Q16n0 uint16_t to Q24n8 fixed point uint32_t.
Q24n8 Q0n8_to_Q24n8(Q0n8 a)
Convert Q0n8 uint8_t to Q24n8 fix.
int16_t Q0n15
signed fractional number using 0 integer bits and 15 fractional bits, represents -0....
Definition: mozzi_fixmath.h:42
Q7n8 Q7n0_to_Q7n8(Q7n0 a)
Convert Q7n0 int8_t to Q7n8 fix.
int16_t Q1n14
signed fractional number using 1 integer bit and 14 fractional bits, represents -1....
Definition: mozzi_fixmath.h:39
Q16n0 Q16n16_to_Q16n0(Q16n16 a)
Convert Q16n16 fixed to Q16n0 uint16_t.
float Q0n7_to_float(Q0n7 a)
Convert Q0n7 fix to float.
uint16_t Q8n8
unsigned fractional number using 8 integer bits and 8 fractional bits, represents 0 to 255....
Definition: mozzi_fixmath.h:41
Q15n16 Q15n0_to_Q15n16(Q15n0 a)
Convert Q15n0 int16_t to Q15n16 fix.
Q31n0 Q23n8_to_Q31n0(Q23n8 a)
Convert Q23n8 fixed to Q31n0 int32_t.
uint32_t Q0n31
signed number using 0 integer bits and 31 fractional bits, represents -0.2147483648 to 0....
Definition: mozzi_fixmath.h:36
Q8n8 Q8n0_to_Q8n8(Q8n0 a)
Convert uint8_t to Q8n8 fix.
uint32_t Q24n8
unsigned fractional number using 24 integer bits and 8 fractional bits, represents 0 to 16777215
Definition: mozzi_fixmath.h:51
Q0n8 Q24n8_to_Q0n8(Q24n8 a)
Convert Q24n8 fixed to Q0n8 uint8_t.
Q15n16 Q7n8_to_Q15n16(Q7n8 a)
Convert Q7n8 fix to Q15n16.
int16_t Q15n0
signed number using 15 integer bits and 0 fractional bits, represents -32768 to 32767
Definition: mozzi_fixmath.h:40
float Q16n0_to_float(Q16n0 a)
Convert Q16n0 uint16_t to float.
int8_t Q0n7
signed fractional number using 7 fractional bits, represents -0.5 to 0.496
Definition: mozzi_fixmath.h:31
float Q1n15_to_float(Q1n15 a)
Convert fix to float.
Q32n0 Q24n8_to_Q32n0(Q24n8 a)
Convert Q24n8 fixed to Q32n0 uint32_t.
Q15n0 Q15n16_to_Q15n0(Q15n16 a)
Convert Q15n16 fixed to Q15n0 signed int16_t.
int32_t Q23n8
signed fractional number using 23 integer bits and 8 fractional bits, represents -8388607....
Definition: mozzi_fixmath.h:45
Q16n0 Q23n8_to_Q16n0(Q23n8 a)
Convert Q23n8 fixed to Q16n0 uint16_t.
Q7n0 Q7n8_to_Q7n0(Q7n8 a)
Convert Q7n8 fix to Q7n0.
Q1n15 Q0n8_to_Q1n15(Q0n8 a)
Convert Q0n8 uint8_t to Q1n15 fix.
Q23n8 Q16n0_to_Q23n8(Q16n0 a)
Convert Q16n0 uint16_t to Q23n8 fixed point signed int32_t.
float Q7n8_to_float(Q7n8 a)
Convert Q7n8 fix to float.
Q16n16 Q0n8_to_Q16n16(Q0n8 a)
Convert Q0n8 uint8_t to Q16n16 fix.
uint32_t Q16n16
unsigned fractional number using 16 integer bits and 16 fractional bits, represents 0 to 65535....
Definition: mozzi_fixmath.h:52
float Q24n8_to_float(Q24n8 a)
Convert fix to float.
Q16n16 Q8n8_to_Q16n16(Q8n8 a)
Convert Q8n8 fix to Q16n16 uint32_t.
int8_t Q7n0
ordinary old signed Q7n0 int8_t with 0 fractional bits, represents -128 to 127
Definition: mozzi_fixmath.h:32
float Q8n8_to_float(Q8n8 a)
Convert Q8n8 fix to float.
Q15n16 Q8n0_to_Q15n16(Q8n0 a)
Convert Q8n0 uint8_t to Q15n16 fix.
Q16n16 Q16n0_to_Q16n16(Q16n0 a)
Convert Q16n0 uint16_t to Q16n16 fixed point uint32_t.
Q7n8 Q23n8_to_Q7n8(Q23n8 a)
Convert Q23n8 fixed to Q7n8 signed int16_t, losing most significant bits.
Q8n24 Q0n8_to_Q8n24(Q0n8 a)
Convert Q0n8 uint8_t to Q8n24 fix.
Q15n16 Q0n7_to_Q15n16(Q0n7 a)
Convert Q0n7 signed int8_t to Q15n16 fix.
Q15n16 Q0n8_to_Q15n16(Q0n8 a)
Convert Q0n8 uint8_t to Q15n16 fix.
float Q1n14_to_float(Q1n14 a)
Convert fix to float.
Q8n0 Q8n8_to_Q8n0(Q8n8 a)
Convert Q8n8 fix to Q8n0 uint8_t.
float Q0n8_to_float(Q0n8 a)
Convert Q0n8 fix to float.
uint8_t Q8n0
normal uint8_t with 0 fractional bits, represents 0.0 to 255.0
Definition: mozzi_fixmath.h:34
uint16_t Q1n15
unsigned fractional number using 1 integer bit and 15 fractional bits, represents 0 to 1....
Definition: mozzi_fixmath.h:43
uint32_t Q0n32
unsigned fractional number using 0 integer bits and 32 fractional bits, represents 0 to 0....
Definition: mozzi_fixmath.h:49
Q8n8 Q16n16_to_Q8n8(Q8n8 a)
Convert Q16n16 fixed to Q8n8 uint16_t.
Q16n16 Q24n8_to_Q16n0(Q24n8 a)
Convert Q24n8 fixed to Q16n0 uint16_t.
Q8n8 Q15n16_to_Q8n8(Q15n16 a)
Convert Q15n16 fixed to Q8n8 signed int16_t, keeping middle bits only.
Q0n8 Q15n16_to_Q0n8(Q15n16 a)
Convert Q15n16 fixed to Q0n8 uint8_t.
Q24n8 float_to_Q24n8(float a)
Convert float to Q24n8 fix.
uint32_t Q32n0
unsigned (normal uint32_t int16_t) number using 32 integer bits and 0 fractional bits,...
Definition: mozzi_fixmath.h:48
float Q16n16_to_float(Q16n16 a)
Convert fix to float.