summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/lib/fixedpoint.h52
-rw-r--r--firmware/include/fixedpoint.h (renamed from apps/fixedpoint.h)54
-rw-r--r--lib/rbcodec/codecs/lib/fixedpoint.h29
3 files changed, 53 insertions, 82 deletions
diff --git a/apps/plugins/lib/fixedpoint.h b/apps/plugins/lib/fixedpoint.h
index 1631f8d6d8..811a1d9b81 100644
--- a/apps/plugins/lib/fixedpoint.h
+++ b/apps/plugins/lib/fixedpoint.h
@@ -20,55 +20,7 @@
20 * KIND, either express or implied. 20 * KIND, either express or implied.
21 * 21 *
22 ****************************************************************************/ 22 ****************************************************************************/
23
24/** PLUGINS - FIXED POINT MATH ROUTINES - USAGE
25 *
26 * - x and y arguments are fixed point integers
27 * - fracbits is the number of fractional bits in the argument(s)
28 * - functions return long fixed point integers with the specified number
29 * of fractional bits unless otherwise specified
30 *
31 * Calculate sin and cos of an angle:
32 * fp_sincos(phase, *cos)
33 * where phase is a 32 bit unsigned integer with 0 representing 0
34 * and 0xFFFFFFFF representing 2*pi, and *cos is the address to
35 * a long signed integer. Value returned is a long signed integer
36 * from -0x80000000 to 0x7fffffff, representing -1 to 1 respectively.
37 * That is, value is a fixed point integer with 31 fractional bits.
38 *
39 * Take square root of a fixed point number:
40 * fp_sqrt(x, fracbits)
41 *
42 * Calculate sin or cos of an angle (very fast, from a table):
43 * fp14_sin(angle)
44 * fp14_cos(angle)
45 * where angle is a non-fixed point integer in degrees. Value
46 * returned is a fixed point integer with 14 fractional bits.
47 *
48 * Calculate the natural log of a positive fixed point integer
49 * fp16_log(x)
50 * where x and the value returned are fixed point integers
51 * with 16 fractional bits.
52 */
53
54#ifndef _FIXEDPOINT_H_PLUGINS 23#ifndef _FIXEDPOINT_H_PLUGINS
55#define _FIXEDPOINT_H_PLUGINS 24#define _FIXEDPOINT_H_PLUGINS
56 25#include "../../../firmware/include/fixedpoint.h"
57long fp_sincos(unsigned long phase, long *cos); 26#endif /* _FIXEDPOINT_H_PLUGINS */
58long fp_sqrt(long a, unsigned int fracbits);
59long fp14_cos(int val);
60long fp14_sin(int val);
61long fp16_log(int x);
62long fp16_exp(int x);
63
64unsigned long isqrt(unsigned long x);
65
66/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
67 * whichever is faster for the architecture) */
68#ifdef CPU_ARM
69#define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
70#else /* SH1, coldfire */
71#define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
72#endif
73
74#endif
diff --git a/apps/fixedpoint.h b/firmware/include/fixedpoint.h
index 6670e597fb..3e14bdd68e 100644
--- a/apps/fixedpoint.h
+++ b/firmware/include/fixedpoint.h
@@ -21,7 +21,7 @@
21 * 21 *
22 ****************************************************************************/ 22 ****************************************************************************/
23 23
24/** APPS - FIXED POINT MATH ROUTINES - USAGE 24/** FIXED POINT MATH ROUTINES - USAGE
25 * 25 *
26 * - x and y arguments are fixed point integers 26 * - x and y arguments are fixed point integers
27 * - fracbits is the number of fractional bits in the argument(s) 27 * - fracbits is the number of fractional bits in the argument(s)
@@ -34,6 +34,36 @@
34 * Divide two fixed point numbers: 34 * Divide two fixed point numbers:
35 * fp_div(x, y, fracbits) 35 * fp_div(x, y, fracbits)
36 * 36 *
37 * Calculate sin and cos of an angle:
38 * fp_sincos(phase, *cos)
39 * where phase is a 32 bit unsigned integer with 0 representing 0
40 * and 0xFFFFFFFF representing 2*pi, and *cos is the address to
41 * a long signed integer. Value returned is a long signed integer
42 * from -0x80000000 to 0x7fffffff, representing -1 to 1 respectively.
43 * That is, value is a fixed point integer with 31 fractional bits.
44 *
45 * Take square root of a fixed point number:
46 * fp_sqrt(x, fracbits)
47 *
48 * Take the square root of an integer:
49 * isqrt(x)
50 *
51 * Calculate sin or cos of an angle (very fast, from a table):
52 * fp14_sin(angle)
53 * fp14_cos(angle)
54 * where angle is a non-fixed point integer in degrees. Value
55 * returned is a fixed point integer with 14 fractional bits.
56 *
57 * Calculate the exponential of a fixed point integer
58 * fp16_exp(x)
59 * where x and the value returned are fixed point integers
60 * with 16 fractional bits.
61 *
62 * Calculate the natural log of a positive fixed point integer
63 * fp16_log(x)
64 * where x and the value returned are fixed point integers
65 * with 16 fractional bits.
66 *
37 * Calculate decibel equivalent of a gain factor: 67 * Calculate decibel equivalent of a gain factor:
38 * fp_decibels(factor, fracbits) 68 * fp_decibels(factor, fracbits)
39 * where fracbits is in the range 12 to 22 (higher is better), 69 * where fracbits is in the range 12 to 22 (higher is better),
@@ -45,16 +75,28 @@
45 * and decibels is a fixed point integer. 75 * and decibels is a fixed point integer.
46 */ 76 */
47 77
48#ifndef _FIXEDPOINT_H_APPS 78#ifndef FIXEDPOINT_H
49#define _FIXEDPOINT_H_APPS 79#define FIXEDPOINT_H
50 80
51#define fp_mul(x, y, z) (long)((((long long)(x)) * ((long long)(y))) >> (z)) 81#define fp_mul(x, y, z) (long)((((long long)(x)) * ((long long)(y))) >> (z))
52#define fp_div(x, y, z) (long)((((long long)(x)) << (z)) / ((long long)(y))) 82#define fp_div(x, y, z) (long)((((long long)(x)) << (z)) / ((long long)(y)))
53 83
54
55/** TAKEN FROM ORIGINAL fixedpoint.h */
56long fp_sincos(unsigned long phase, long *cos); 84long fp_sincos(unsigned long phase, long *cos);
85long fp_sqrt(long a, unsigned int fracbits);
86long fp14_cos(int val);
87long fp14_sin(int val);
88long fp16_log(int x);
89long fp16_exp(int x);
57 90
91unsigned long isqrt(unsigned long x);
92
93/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
94 * whichever is faster for the architecture) */
95#ifdef CPU_ARM
96#define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
97#else /* SH1, coldfire */
98#define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
99#endif
58 100
59/** MODIFIED FROM replaygain.c */ 101/** MODIFIED FROM replaygain.c */
60#define FP_INF (0x7fffffff) 102#define FP_INF (0x7fffffff)
@@ -66,4 +108,4 @@ long fp_sincos(unsigned long phase, long *cos);
66/* long fp_decibels(unsigned long factor, unsigned int fracbits); */ 108/* long fp_decibels(unsigned long factor, unsigned int fracbits); */
67long fp_factor(long decibels, unsigned int fracbits); 109long fp_factor(long decibels, unsigned int fracbits);
68 110
69#endif 111#endif /* FIXEDPOINT_H */
diff --git a/lib/rbcodec/codecs/lib/fixedpoint.h b/lib/rbcodec/codecs/lib/fixedpoint.h
index 1cbd1573bb..3d8e77cd89 100644
--- a/lib/rbcodec/codecs/lib/fixedpoint.h
+++ b/lib/rbcodec/codecs/lib/fixedpoint.h
@@ -9,7 +9,7 @@
9 * 9 *
10 * Copyright (C) 2006 Jens Arnold 10 * Copyright (C) 2006 Jens Arnold
11 * 11 *
12 * Fixed point library for plugins 12 * Fixed point library for codecs
13 * 13 *
14 * This program is free software; you can redistribute it and/or 14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License 15 * modify it under the terms of the GNU General Public License
@@ -20,30 +20,7 @@
20 * KIND, either express or implied. 20 * KIND, either express or implied.
21 * 21 *
22 ****************************************************************************/ 22 ****************************************************************************/
23
24 /** CODECS - FIXED POINT MATH ROUTINES - USAGE
25 *
26 * - x and y arguments are fixed point integers
27 * - fracbits is the number of fractional bits in the argument(s)
28 * - functions return long fixed point integers with the specified number
29 * of fractional bits unless otherwise specified
30 *
31 * Calculate sin and cos of an angle:
32 * fp_sincos(phase, *cos)
33 * where phase is a 32 bit unsigned integer with 0 representing 0
34 * and 0xFFFFFFFF representing 2*pi, and *cos is the address to
35 * a long signed integer. Value returned is a long signed integer
36 * from -0x80000000 to 0x7fffffff, representing -1 to 1 respectively.
37 * That is, value is a fixed point integer with 31 fractional bits.
38 *
39 * Take square root of a fixed point number:
40 * fp_sqrt(x, fracbits)
41 *
42 */
43#ifndef _FIXEDPOINT_H_CODECS 23#ifndef _FIXEDPOINT_H_CODECS
44#define _FIXEDPOINT_H_CODECS 24#define _FIXEDPOINT_H_CODECS
45 25#include "../../../../firmware/include/fixedpoint.h"
46long fp_sincos(unsigned long phase, long *cos); 26#endif /* _FIXEDPOINT_H_CODECS */
47long fp_sqrt(long a, unsigned int fracbits);
48
49#endif