~ubuntu-branches/ubuntu/hardy/lmms/hardy

« back to all changes in this revision

Viewing changes to plugins/ladspa_effect/caps/dsp/White.h

  • Committer: Bazaar Package Importer
  • Author(s): Tobias Doerffel
  • Date: 2007-09-17 15:00:24 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070917150024-mo0zk4ks81jawqii
Tags: 0.3.0-1ubuntu1
* Resynchronized with Debian (LP: #139759, LP: #90806, LP: #102639,
  LP: #113447, LP: #121172, LP: #124890)
* reverted changes from 0.2.1-1.1ubuntu1 as upstream merged/included them

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  dsp/White.h
 
3
 
 
4
        Copyright 2004 Tim Goetze <tim@quitte.de>
 
5
 
 
6
        simple white noise generator, based on Jon Dattorro's 3/2002 JAES 
 
7
        paper. quite an elegant design; consumes next to no CPU on a processor
 
8
        providing a decent binary shift operator. most of all, no random() calls.
 
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_WHITE_H_
 
29
#define _DSP_WHITE_H_
 
30
 
 
31
namespace DSP {
 
32
 
 
33
/* after initializing, call either get() or get_31() to get a sample, don't
 
34
 * mix them. (get_31 output goes out of range if called after get()).
 
35
 */
 
36
class White
 
37
{
 
38
        public:
 
39
                uint32 b;
 
40
 
 
41
                White()
 
42
                        {
 
43
                                b = 0x1fff7777;
 
44
                        }
 
45
 
 
46
                void init (float f)
 
47
                        {
 
48
                                b = (uint32) (f * (float) 0x1fff7777);
 
49
                        }
 
50
                
 
51
                d_sample abs()
 
52
                        {
 
53
                                return fabs (get());
 
54
                        }
 
55
 
 
56
                /* 32-bit version */
 
57
                d_sample get()
 
58
                        {
 
59
#                               define BIT(y) ((b << (31 - y)) & 0x80000000)
 
60
 
 
61
                                b = ((BIT (28) ^ BIT (27) ^ BIT (1) ^ BIT (0))) | (b >> 1);
 
62
                                return (4.6566128730773926e-10 * (d_sample) b) - 1;
 
63
 
 
64
#                               undef BIT
 
65
                        }
 
66
 
 
67
                /* 31-bit version, at least 6 instructions less / sample. probably only
 
68
                 * pays off on a processor not providing a decent binary shift. */
 
69
                d_sample get_31()
 
70
                        {
 
71
#                               define BIT(y) ((b << (30 - y)) & 0x40000000)
 
72
 
 
73
                                b = ((BIT (3) ^ BIT (0))) | (b >> 1);
 
74
                                return (9.3132257461547852e-10 * (d_sample) b) - 1;
 
75
 
 
76
#                               undef BIT
 
77
                        }
 
78
};
 
79
 
 
80
} /* namespace DSP */
 
81
 
 
82
#endif /* _DSP_WHITE_H_ */