LMMS
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1/*
2 dsp/util.h
3
4 Copyright 2002-4 Tim Goetze <tim@quitte.de>
5
6 http://quitte.de/dsp/
7
8 Common math utility functions.
9
10*/
11/*
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA or point your web browser to http://www.gnu.org.
26*/
27
28#ifndef _DSP_UTIL_H_
29#define _DSP_UTIL_H_
30
31namespace DSP {
32
33inline int next_power_of_2 (int n)
34{
35 assert (n <= 0x40000000);
36
37 int m = 1;
38
39 while (m < n)
40 m <<= 1;
41
42 return m;
43}
44
45inline bool
47{
48 if (v <= 3)
49 return true;
50
51 if (!(v & 1))
52 return false;
53
54 for (int i = 3; i < (int) sqrt (v) + 1; i += 2)
55 if ((v % i) == 0)
56 return false;
57
58 return true;
59}
60
61inline double
62db2lin (double db)
63{
64 return pow (10., db * .05);
65}
66
67inline double
68lin2db (double lin)
69{
70 return 20. * log10 (lin);
71}
72
73} /* namespace DSP */
74
75#endif /* _DSP_UTIL_H_ */
assert(0)
unsigned * m
Definition inflate.c:1559
unsigned v[N_MAX]
Definition inflate.c:1584
register unsigned i
Definition inflate.c:1575
#define lin2db(a)
Definition db.h:27
#define db2lin(a)
Definition db.h:26
Definition BiQuad.h:31
int next_power_of_2(int n)
Definition util.h:33
bool isprime(int v)
Definition util.h:46
int n
Definition crypt.c:458
typedef int(UZ_EXP MsgFn)()