summaryrefslogtreecommitdiff
path: root/apps/fixedpoint.h
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-07-05 18:06:07 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-07-05 18:06:07 +0000
commit802743a061e01150db544c8e072cd794731b18a7 (patch)
tree311abcc9e51973907899a4585dd0e3a2a31572eb /apps/fixedpoint.h
parent427bf0b8936f2654fe79e8c5864918530b8838dd (diff)
downloadrockbox-802743a061e01150db544c8e072cd794731b18a7.tar.gz
rockbox-802743a061e01150db544c8e072cd794731b18a7.zip
Take 2 at 'Consolidate all fixed point math routines in one library' (FS#10400) by Jeffrey Goode
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21664 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/fixedpoint.h')
-rw-r--r--apps/fixedpoint.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/apps/fixedpoint.h b/apps/fixedpoint.h
new file mode 100644
index 0000000000..49292f3417
--- /dev/null
+++ b/apps/fixedpoint.h
@@ -0,0 +1,69 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: fixedpoint.h -1 $
9 *
10 * Copyright (C) 2006 Jens Arnold
11 *
12 * Fixed point library for plugins
13 *
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.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24/** APPS - 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 * Multiply two fixed point numbers:
32 * fp_mul(x, y, fracbits)
33 *
34 * Divide two fixed point numbers:
35 * fp_div(x, y, fracbits)
36 *
37 * Calculate decibel equivalent of a gain factor:
38 * fp_decibels(factor, fracbits)
39 * where fracbits is in the range 12 to 22 (higher is better),
40 * and factor is a positive fixed point integer.
41 *
42 * Calculate factor equivalent of a decibel value:
43 * fp_factor(decibels, fracbits)
44 * where fracbits is in the range 12 to 22 (lower is better),
45 * and decibels is a fixed point integer.
46 */
47
48#ifndef _FIXEDPOINT_H_APPS
49#define _FIXEDPOINT_H_APPS
50
51#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)))
53
54
55/** TAKEN FROM ORIGINAL fixedpoint.h */
56long fp_sincos(unsigned long phase, long *cos);
57
58
59/** MODIFIED FROM replaygain.c */
60#define FP_INF (0x7fffffff)
61#define FP_NEGINF -(0x7fffffff)
62
63/* fracbits in range 12 - 22 work well. Higher is better for
64 * calculating dB, lower is better for calculating ratio.
65 */
66/* long fp_decibels(unsigned long factor, unsigned int fracbits); */
67long fp_factor(long decibels, unsigned int fracbits);
68
69#endif