diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
commit | 526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch) | |
tree | 22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/intern/sqrt~.c | |
parent | 4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff) | |
download | rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.tar.gz rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.zip |
Cut the files in half and it might work better (note to self: check your tree is really clean before patching)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21070 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/sqrt~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/sqrt~.c | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/sqrt~.c b/apps/plugins/pdbox/PDa/intern/sqrt~.c index 5e4b649f8e..f5362f094f 100644 --- a/apps/plugins/pdbox/PDa/intern/sqrt~.c +++ b/apps/plugins/pdbox/PDa/intern/sqrt~.c | |||
@@ -75,80 +75,3 @@ void sqrt_tilde_setup(void) | |||
75 | class_addmethod(sigsqrt_class, (t_method)sigsqrt_dsp, gensym("dsp"), 0); | 75 | class_addmethod(sigsqrt_class, (t_method)sigsqrt_dsp, gensym("dsp"), 0); |
76 | } | 76 | } |
77 | 77 | ||
78 | #define DUMTAB1SIZE 256 | ||
79 | #define DUMTAB2SIZE 1024 | ||
80 | |||
81 | #include<m_pd.h> | ||
82 | #include<m_fixed.h> | ||
83 | |||
84 | /* sigsqrt - square root good to 8 mantissa bits */ | ||
85 | |||
86 | static float rsqrt_exptab[DUMTAB1SIZE], rsqrt_mantissatab[DUMTAB2SIZE]; | ||
87 | |||
88 | static void init_rsqrt(void) | ||
89 | { | ||
90 | int i; | ||
91 | for (i = 0; i < DUMTAB1SIZE; i++) | ||
92 | { | ||
93 | float f; | ||
94 | long l = (i ? (i == DUMTAB1SIZE-1 ? DUMTAB1SIZE-2 : i) : 1)<< 23; | ||
95 | *(long *)(&f) = l; | ||
96 | rsqrt_exptab[i] = 1./sqrt(f); | ||
97 | } | ||
98 | for (i = 0; i < DUMTAB2SIZE; i++) | ||
99 | { | ||
100 | float f = 1 + (1./DUMTAB2SIZE) * i; | ||
101 | rsqrt_mantissatab[i] = 1./sqrt(f); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | typedef struct sigsqrt | ||
106 | { | ||
107 | t_object x_obj; | ||
108 | float x_f; | ||
109 | } t_sigsqrt; | ||
110 | |||
111 | static t_class *sigsqrt_class; | ||
112 | |||
113 | static void *sigsqrt_new(void) | ||
114 | { | ||
115 | t_sigsqrt *x = (t_sigsqrt *)pd_new(sigsqrt_class); | ||
116 | outlet_new(&x->x_obj, gensym("signal")); | ||
117 | x->x_f = 0; | ||
118 | return (x); | ||
119 | } | ||
120 | |||
121 | t_int *sigsqrt_perform(t_int *w) /* not static; also used in d_fft.c */ | ||
122 | { | ||
123 | float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2); | ||
124 | t_int n = *(t_int *)(w+3); | ||
125 | while (n--) | ||
126 | { | ||
127 | float f = *in; | ||
128 | long l = *(long *)(in++); | ||
129 | if (f < 0) *out++ = 0; | ||
130 | else | ||
131 | { | ||
132 | float g = rsqrt_exptab[(l >> 23) & 0xff] * | ||
133 | rsqrt_mantissatab[(l >> 13) & 0x3ff]; | ||
134 | *out++ = f * (1.5 * g - 0.5 * g * g * g * f); | ||
135 | } | ||
136 | } | ||
137 | return (w + 4); | ||
138 | } | ||
139 | |||
140 | static void sigsqrt_dsp(t_sigsqrt *x, t_signal **sp) | ||
141 | { | ||
142 | dsp_add(sigsqrt_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
143 | } | ||
144 | |||
145 | void sqrt_tilde_setup(void) | ||
146 | { | ||
147 | init_rsqrt(); | ||
148 | sigsqrt_class = class_new(gensym("sqrt~"), (t_newmethod)sigsqrt_new, 0, | ||
149 | sizeof(t_sigsqrt), 0, 0); | ||
150 | class_addcreator(sigsqrt_new, gensym("q8_sqrt~"), 0); /* old name */ | ||
151 | CLASS_MAINSIGNALIN(sigsqrt_class, t_sigsqrt, x_f); | ||
152 | class_addmethod(sigsqrt_class, (t_method)sigsqrt_dsp, gensym("dsp"), 0); | ||
153 | } | ||
154 | |||