aboutsummaryrefslogtreecommitdiff
path: root/src/noish~.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/noish~.c')
-rw-r--r--src/noish~.c136
1 files changed, 64 insertions, 72 deletions
diff --git a/src/noish~.c b/src/noish~.c
index 8d5c875..b4b7829 100644
--- a/src/noish~.c
+++ b/src/noish~.c
@@ -1,4 +1,4 @@
-/*
+/*
* noish~: bandlimited noise generator
*
* (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem)
@@ -7,12 +7,12 @@
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -21,11 +21,11 @@
/*
30041999
- two bandlimited noise gnerators based on DODGE/JERSE "computer music" c3.9 : RANDI & RANDH
-
+ two bandlimited noise gnerators based on DODGE/JERSE "computer music" c3.9 : RANDI & RANDH
+
I do not care for copyrights
- (all in all, the used noise~-code (in fact, the pseude-random-code) is from Miller Puckette
- and I made only very few modifications so look out for the LICENSE.TXT delivered with
+ (all in all, the used noise~-code (in fact, the pseude-random-code) is from Miller Puckette
+ and I made only very few modifications so look out for the LICENSE.TXT delivered with
puredata for further (c)-information
forum für umläute 1999
@@ -41,13 +41,12 @@
/* general */
-typedef struct _nois
-{
+typedef struct _nois {
t_object x_obj;
int val;
t_sample current;
t_sample decrement;
- t_sample updater;
+ t_sample updater;
t_sample to_go;
} t_nois;
@@ -55,10 +54,9 @@ typedef struct _nois
static void set_freq(t_nois *x, t_floatarg freq)
{
x->updater = (freq > 0) ? sys_getsr() / freq : 1;
- if (x->updater < 1)
- {
- x->updater = 1;
- }
+ if (x->updater < 1) {
+ x->updater = 1;
+ }
x->to_go = 0;
}
@@ -68,7 +66,7 @@ static void set_noisseed(t_nois *x, t_floatarg seed)
x->val = seed;
}
-/* ------------------------ noish~ ----------------------------- */
+/* ------------------------ noish~ ----------------------------- */
static t_class *noish_class;
@@ -77,69 +75,61 @@ static t_int *noish_perform(t_int *w)
t_nois *x = (t_nois *)(w[1]);
t_sample *out = (t_sample *)(w[2]);
int n = (int)(w[3]);
-
+
int *vp = (int *)(&x->val);
int i_value = *vp;
t_sample f_value = ((t_sample)((i_value & 0x7fffffff) - 0x40000000)) *
- (t_sample)(1.0 / 0x40000000);
+ (t_sample)(1.0 / 0x40000000);
t_sample all_to_go = x->updater;
t_sample still_to_go = x->to_go;
- if (all_to_go == 1)
- { /* this is "pure white" noise, so we have to calculate each sample */
- while (n--)
- {
- i_value *= 435898247;
- i_value += 382842987;
- *out++ = ((t_sample)((i_value & 0x7fffffff) - 0x40000000)) * (t_sample)(1.0 / 0x40000000);
- }
+ if (all_to_go == 1) {
+ /* this is "pure white" noise, so we have to calculate each sample */
+ while (n--) {
+ i_value *= 435898247;
+ i_value += 382842987;
+ *out++ = ((t_sample)((i_value & 0x7fffffff) - 0x40000000)) * (t_sample)(
+ 1.0 / 0x40000000);
+ }
+ } else if (n < still_to_go) {
+ /* signal won't change for the next 64 samples */
+ still_to_go -= n;
+ while (n--) {
+ *out++ = f_value;
+ }
+ } else if (all_to_go + still_to_go > n) {
+ /* only one update calculation necessary for 64 samples !!! */
+ while (still_to_go-- > 0) {
+ n--;
+ *out++ = f_value;
+ }
+
+ still_to_go += all_to_go + 1;
+
+ i_value *= 435898247;
+ i_value += 382842987;
+ f_value = ( (t_sample)((i_value & 0x7fffffff) - 0x40000000) ) * (t_sample)(
+ 1.0 / 0x40000000);
+
+ while (n--) {
+ still_to_go--;
+ *out++ = f_value;
}
- else
- if (n < still_to_go)
- { /* signal won't change for the next 64 samples */
- still_to_go -= n;
- while (n--)
- {
- *out++ = f_value;
- }
+ } else {
+ /* anything else */
+ while (n--) {
+ if (still_to_go-- <= 0) { /* update only if all time has elapsed */
+ still_to_go += all_to_go;
+
+ i_value *= 435898247;
+ i_value += 382842987;
+
+ f_value = ( (t_sample)((i_value & 0x7fffffff) - 0x40000000) ) * (t_sample)(
+ 1.0 / 0x40000000);
}
- else
- if (all_to_go + still_to_go > n)
- { /* only one update calculation necessary for 64 samples !!! */
- while (still_to_go-- > 0)
- {
- n--;
- *out++ = f_value;
- }
-
- still_to_go += all_to_go + 1;
-
- i_value *= 435898247;
- i_value += 382842987;
- f_value = ( (t_sample)((i_value & 0x7fffffff) - 0x40000000) ) * (t_sample)(1.0 / 0x40000000);
-
- while (n--)
- {
- still_to_go--;
- *out++ = f_value;
- }
- }
- else
- { /* anything else */
- while (n--)
- {
- if (still_to_go-- <= 0) /* update only if all time has elapsed */
- {
- still_to_go += all_to_go;
-
- i_value *= 435898247;
- i_value += 382842987;
-
- f_value = ( (t_sample)((i_value & 0x7fffffff) - 0x40000000) ) * (t_sample)(1.0 / 0x40000000);
- }
- *out++ = f_value;
- }
- }
+ *out++ = f_value;
+ }
+ }
*vp = i_value;
@@ -182,12 +172,14 @@ static void *noish_new(t_floatarg f)
void noish_tilde_setup(void)
{
- noish_class = class_new(gensym("noish~"), (t_newmethod)noish_new, 0, sizeof(t_nois), 0, A_DEFFLOAT, 0);
+ noish_class = class_new(gensym("noish~"), (t_newmethod)noish_new, 0,
+ sizeof(t_nois), 0, A_DEFFLOAT, 0);
class_addfloat(noish_class, set_freq);
class_addmethod(noish_class, (t_method)noish_dsp, gensym("dsp"), 0);
- class_addmethod(noish_class, (t_method)set_noisseed, gensym("seed"), A_FLOAT, 0);
+ class_addmethod(noish_class, (t_method)set_noisseed, gensym("seed"),
+ A_FLOAT, 0);
class_addmethod(noish_class, (t_method)noish_helper, gensym("help"), 0);
zexy_register("noish~");