Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / apps / plugins / lib / fixedpoint.h
blobef50dd00850df760c5a792a49fd10e8139ccdb28
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Jens Arnold
12 * Fixed point library for plugins
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 /** PLUGINS - FIXED POINT MATH ROUTINES - USAGE
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
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 LONG_MIN to LONG_MAX, representing -1 to 1 respectively.
37 * That is, value is a fixed point integer with 31 fractional bits.
39 * Take square root of a fixed point number:
40 * fp_sqrt(x, fracbits)
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.
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.
54 #ifndef _FIXEDPOINT_H_PLUGINS
55 #define _FIXEDPOINT_H_PLUGINS
57 long fp_sincos(unsigned long phase, long *cos);
58 long fp_sqrt(long a, unsigned int fracbits);
59 long fp14_cos(int val);
60 long fp14_sin(int val);
61 long fp16_log(int x);
63 /* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
64 * whichever is faster for the architecture) */
65 #ifdef CPU_ARM
66 #define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
67 #else /* SH1, coldfire */
68 #define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
69 #endif
71 #endif