aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2003-06-18 13:56:34 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2003-06-18 13:56:34 +0000
commit24de4c622b68ceff0f8da103948f1e92eeff8fee (patch)
treee93f35f3115845b08efa8642def8044339371147 /src
parentae98aa5052110ad7de12f5f1c0ef6a3aab1a1ba4 (diff)
don't know (new indentation)
svn path=/trunk/externals/zexy/; revision=710
Diffstat (limited to 'src')
-rw-r--r--src/z_noise.c425
1 files changed, 201 insertions, 224 deletions
diff --git a/src/z_noise.c b/src/z_noise.c
index 8e73d44..9d555bd 100644
--- a/src/z_noise.c
+++ b/src/z_noise.c
@@ -1,22 +1,20 @@
/*
- 30041999
+ 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
- puredata for further (c)-information
+ 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
+ puredata for further (c)-information
- forum für umläute 1999
+ forum für umläute 1999
- this is in fact the very same as the late "NOISE.C", except that I tried to optimize the code a little
- bit(by partially removing those very expensive if..then's in about 15 minutes, so there are thousands of
- new bugs very likely
+ this is in fact the very same as the late "NOISE.C", except that I tried to optimize the code a little bit
+ (by partially removing those very expensive if..then's in about 15 minutes, so there are thousands of new bugs very likely)
- 14071999
- finally added changing seeds, this is to prevent to noise~-units to output the very same, something quite
- unnatural even for pseudo-random-noise
+ 14071999
+ finally added changing seeds, this is to prevent to noise~-units to output the very same, something quite unnatural even for pseudo-random-noise
*/
#include "zexy.h"
@@ -29,23 +27,23 @@
typedef struct _nois
{
- t_object x_obj;
- int val;
- t_float current;
- t_float decrement;
- t_float updater;
- t_float to_go;
+ t_object x_obj;
+ int val;
+ t_float current;
+ t_float decrement;
+ t_float updater;
+ t_float to_go;
} t_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;
- }
- x->to_go = 0;
+ x->updater = (freq > 0) ? sys_getsr() / freq : 1;
+ if (x->updater < 1)
+ {
+ x->updater = 1;
+ }
+ x->to_go = 0;
}
@@ -55,79 +53,79 @@ static t_class *noish_class;
static t_int *noish_perform(t_int *w)
{
- t_nois *x = (t_nois *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- int n = (int)(w[3]);
+ t_nois *x = (t_nois *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ int n = (int)(w[3]);
- int *vp = (int *)(&x->val);
- int i_value = *vp;
- t_float f_value = ((float)((i_value & 0x7fffffff) - 0x40000000)) *
- (float)(1.0 / 0x40000000);
- t_float all_to_go = x->updater;
- t_float 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--)
+ int *vp = (int *)(&x->val);
+ int i_value = *vp;
+ t_float f_value = ((float)((i_value & 0x7fffffff) - 0x40000000)) *
+ (float)(1.0 / 0x40000000);
+ t_float all_to_go = x->updater;
+ t_float 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++ = ((float)((i_value & 0x7fffffff) - 0x40000000)) * (float)(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 = ( (float)((i_value & 0x7fffffff) - 0x40000000) ) * (float)(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 */
{
- i_value *= 435898247;
- i_value += 382842987;
- *out++ = ((float)((i_value & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000);
+ still_to_go += all_to_go;
+
+ i_value *= 435898247;
+ i_value += 382842987;
+
+ f_value = ( (float)((i_value & 0x7fffffff) - 0x40000000) ) * (float)(1.0 / 0x40000000);
}
+ *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
- 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 = ( (float)((i_value & 0x7fffffff) - 0x40000000) ) * (float)(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 = ( (float)((i_value & 0x7fffffff) - 0x40000000) ) * (float)(1.0 / 0x40000000);
- }
- *out++ = f_value;
- }
- }
- *vp = i_value;
- x->updater = all_to_go;
- x->to_go = still_to_go;
+ *vp = i_value;
+ x->updater = all_to_go;
+ x->to_go = still_to_go;
- return (w+4);
+ return (w+4);
}
static void noish_dsp(t_nois *x, t_signal **sp)
@@ -138,39 +136,39 @@ static void noish_dsp(t_nois *x, t_signal **sp)
static void noish_helper(void)
{
- post("\n%c noish~\t:: a bandlimited pseudo-noise generator", HEARTSYMBOL);
- post("<freq>\t : sampling-frequency (in Hz)\n"
- "'help'\t : view this");
- post("creation : \"noish~ [<freq>]\"\t: ('0'(default) will produce 'white' noise)\n");
- post("note\t : the seed of the pseudo-noise generator changes from\n"
- "\t instance to instance, so two noish~-objects created at the\n"
- "\t same time will produce dífferent signals, something the original\n"
- "\t noise~-object misses\n");
- post("for further details see DODGE/JERSE \"computer music\" c3.9\n");
+ post("\n%c noish~\t:: a bandlimited pseudo-noise generator", HEARTSYMBOL);
+ post("<freq>\t : sampling-frequency (in Hz)\n"
+ "'help'\t : view this");
+ post("creation : \"noish~ [<freq>]\"\t: ('0'(default) will produce 'white' noise)\n");
+ post("note\t : the seed of the pseudo-noise generator changes from\n"
+ "\t instance to instance, so two noish~-objects created at the\n"
+ "\t same time will produce dífferent signals, something the original\n"
+ "\t noise~-object misses\n");
+ post("for further details see DODGE/JERSE \"computer music\" c3.9\n");
}
static void *noish_new(t_floatarg f)
{
- t_nois *x = (t_nois *)pd_new(noish_class);
+ t_nois *x = (t_nois *)pd_new(noish_class);
- static int init = 307;
- x->val = (init *= 13);
+ static int init = 307;
+ x->val = (init *= 13);
- set_freq(x, f);
+ set_freq(x, f);
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
}
void noish_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_addfloat(noish_class, set_freq);
+ class_addmethod(noish_class, (t_method)noish_dsp, gensym("dsp"), 0);
- class_addmethod(noish_class, (t_method)noish_helper, gensym("help"), 0);
- class_sethelpsymbol(noish_class, gensym("zexy/noish~"));
+ class_addmethod(noish_class, (t_method)noish_helper, gensym("help"), 0);
+ class_sethelpsymbol(noish_class, gensym("zexy/noish~"));
}
@@ -179,134 +177,113 @@ void noish_setup(void)
static t_class *noisi_class;
-static t_int *noisi_perform(t_int *w)
-{
- t_nois *x = (t_nois *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- int n = (int)(w[3]);
-
- int *vp = (int *)(&x->val); /* what the ... */
- int i_value = *vp;
- t_float f_value = x->current;
- t_float decrement = x->decrement;
- t_float all_to_go = x->updater;
- t_float 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++ = ((float)((i_value & 0x7fffffff) - 0x40000000)) * (float)(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 -= decrement);
- }
- }
- 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 -= decrement);
- }
-
-
- still_to_go += all_to_go + 1;
-
- decrement = (
- (f_value = ((float)((i_value & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000)) -
- ((float)(((i_value = i_value * 435898247 + 382842987) & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000)
- ) / all_to_go;
-
-
- while (n--)
- {
- still_to_go--;
- *out++ = (f_value -= decrement);
- }
- }
- else
- { /* anything else */
- while (n--)
- {
- if (still_to_go-- <= 0) /* update only if all time has elapsed */
- {
- still_to_go += all_to_go;
-
- decrement = (
- (f_value = ((float)((i_value & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000)) -
- ((float)(((i_value = i_value * 435898247 + 382842987) & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000)
- ) / all_to_go;
- }
- *out++ = (f_value -= decrement);
- }
- }
-
- *vp = i_value;
- x->current = f_value;
- x->decrement = decrement;
- x->to_go = still_to_go;
-
- return (w+4);
+static t_int *noisi_perform(t_int *w){
+ t_nois *x = (t_nois *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ int n = (int)(w[3]);
+
+ int *vp = (int *)(&x->val); /* what the ... */
+ int i_value = *vp;
+ t_float f_value = x->current;
+ t_float decrement = x->decrement;
+ t_float all_to_go = x->updater;
+ t_float 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);
+ }
+ } else if (n < still_to_go) {
+ /* signal won't change for the next 64 samples */
+ still_to_go -= n;
+ while (n--){
+ *out++ = (f_value -= decrement);
+ }
+ } 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 -= decrement);
+ }
+ still_to_go += all_to_go + 1;
+ decrement = (
+ (f_value =
+ ((t_sample)((i_value & 0x7fffffff)-0x40000000))*(t_sample)(1.0 / 0x40000000)) -
+ ((t_sample)(((i_value = i_value * 435898247 + 382842987) & 0x7fffffff)
+ - 0x40000000)) * (t_sample)(1.0 / 0x40000000)
+ ) / all_to_go;
+
+ while (n--) {
+ still_to_go--;
+ *out++ = (f_value -= decrement);
+ }
+ } else {
+ /* anything else */
+ while (n--) {
+ if (still_to_go-- <= 0) { /* update only if all time has elapsed */
+ still_to_go += all_to_go;
+ decrement = (
+ (f_value = ((t_sample)((i_value & 0x7fffffff) - 0x40000000)) * (t_sample)(1.0 / 0x40000000)) -
+ ((t_sample)(((i_value = i_value * 435898247 + 382842987) & 0x7fffffff) - 0x40000000)) * (t_sample)(1.0 / 0x40000000)
+ ) / all_to_go;
+ }
+ *out++ = (f_value -= decrement);
+ }
+ }
+
+ *vp = i_value;
+ x->current = f_value;
+ x->decrement = decrement;
+ x->to_go = still_to_go;
+
+ return (w+4);
}
-static void noisi_dsp(t_nois *x, t_signal **sp)
-{
- dsp_add(noisi_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+static void noisi_dsp(t_nois *x, t_signal **sp){
+ dsp_add(noisi_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
}
-static void noisi_helper(void)
-{
- post("\n%c noisi~\t:: a bandlimited interpolating pseudo-noise generator", HEARTSYMBOL);
- post("<freq>\t : sampling-frequency (in Hz)\n"
- "'help'\t : view this");
- post("creation : \"noisi~ [<freq>]\"\t: ('0'(default) will produce 'white' noise)\n");
- post("note\t : the seed of the pseudo-noise generator changes from\n"
- "\t instance to instance, so two noisi~-objects created at the\n"
- "\t same time will produce different signals, something the original\n"
- "\t noise~-object misses\n");
- post("for further details see DODGE/JERSE \"computer music\" c3.9\n");
+static void noisi_helper(void){
+ post("\n%c noisi~\t:: a bandlimited interpolating pseudo-noise generator", HEARTSYMBOL);
+ post("<freq>\t : sampling-frequency (in Hz)\n"
+ "'help'\t : view this");
+ post("creation : \"noisi~ [<freq>]\"\t: ('0'(default) will produce 'white' noise)\n");
+ post("note\t : the seed of the pseudo-noise generator changes from\n"
+ "\t instance to instance, so two noisi~-objects created at the\n"
+ "\t same time will produce different signals, something the original\n"
+ "\t noise~-object misses\n");
+ post("for further details see DODGE/JERSE \"computer music\" c3.9\n");
}
-static void *noisi_new(t_floatarg f)
-{
- t_nois *x = (t_nois *)pd_new(noisi_class);
-
- static int init = 4259;
- x->val = (init *= 17);
-
- set_freq (x, f);
+static void *noisi_new(t_floatarg f){
+ t_nois *x = (t_nois *)pd_new(noisi_class);
+
+ static int init = 4259;
+ x->val = (init *= 17);
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
+ set_freq (x, f);
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
}
-void noisi_setup(void)
-{
- noisi_class = class_new(gensym("noisi~"), (t_newmethod)noisi_new, 0, sizeof(t_nois), 0, A_DEFFLOAT, 0);
+void noisi_setup(void){
+ noisi_class = class_new(gensym("noisi~"), (t_newmethod)noisi_new, 0, sizeof(t_nois), 0, A_DEFFLOAT, 0);
- class_addfloat(noisi_class, set_freq);
- class_addmethod(noisi_class, (t_method)noisi_dsp, gensym("dsp"), 0);
+ class_addfloat(noisi_class, set_freq);
+ class_addmethod(noisi_class, (t_method)noisi_dsp, gensym("dsp"), 0);
- class_addmethod(noisi_class, (t_method)noisi_helper, gensym("help"), 0);
- class_sethelpsymbol(noisi_class, gensym("zexy/noisi~"));
+ class_addmethod(noisi_class, (t_method)noisi_helper, gensym("help"), 0);
+ class_sethelpsymbol(noisi_class, gensym("zexy/noisi~"));
}
/* global setup routine */
-void z_noise_setup(void)
-{
- noish_setup();
- noisi_setup();
+void z_noise_setup(void){
+ noish_setup();
+ noisi_setup();
}