diff options
-rw-r--r-- | iemlib1/sin_freq~-help.pd | 47 | ||||
-rw-r--r-- | iemlib1/src/iemlib1.c | 4 | ||||
-rw-r--r-- | iemlib1/src/makefile_d_fat | 1 | ||||
-rw-r--r-- | iemlib1/src/makefile_linux | 1 | ||||
-rw-r--r-- | iemlib1/src/sin_freq~.c | 102 |
5 files changed, 154 insertions, 1 deletions
diff --git a/iemlib1/sin_freq~-help.pd b/iemlib1/sin_freq~-help.pd new file mode 100644 index 0000000..3324557 --- /dev/null +++ b/iemlib1/sin_freq~-help.pd @@ -0,0 +1,47 @@ +#N canvas 375 118 488 460 10; +#X text 28 48 dsp ON/OFF; +#X floatatom 155 63 3 15 133 0 - - -; +#X obj 155 81 mtof; +#X floatatom 155 102 9 0 22000 0 - - -; +#X text 224 100 Hz; +#X floatatom 11 88 5 0 0 0 - - -; +#X text 46 87 % cpu; +#X obj 11 68 dsp; +#X obj 11 48 tgl 15 0 empty empty empty 8 -8 0 10 -262144 -1 -1 1 1 +; +#X text 180 61 midi-pitch; +#X obj 336 305 unsig~; +#X text 149 400 IEM KUG; +#X text 126 388 musil; +#X text 163 388 @; +#X text 172 388 iem.at; +#X text 132 410 Graz \, Austria; +#X obj 154 241 sin_freq~; +#X obj 155 140 osc~ 440; +#X text 406 326 Hz; +#X text 84 377 (c) Thomas Musil 2000 - 2011; +#X text 10 7 sin_freq~; +#X text 105 8 calculate frequency of a; +#X text 105 20 sine-wave \, in Hz (signal-out); +#X floatatom 27 299 9 0 0 0 - - -; +#X floatatom 336 327 9 0 0 0 - - -; +#X obj 154 305 unsig~; +#X text 224 326 Hz; +#X floatatom 154 327 9 0 0 0 - - -; +#X obj 154 283 lp1~ 100; +#X obj 336 283 lp1_dp~ 10; +#X obj 27 276 unsig~ 10; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X connect 3 0 17 0; +#X connect 7 0 5 0; +#X connect 8 0 7 0; +#X connect 10 0 24 0; +#X connect 16 0 28 0; +#X connect 16 0 29 0; +#X connect 16 0 30 0; +#X connect 17 0 16 0; +#X connect 25 0 27 0; +#X connect 28 0 25 0; +#X connect 29 0 10 0; +#X connect 30 0 23 0; diff --git a/iemlib1/src/iemlib1.c b/iemlib1/src/iemlib1.c index fcc6615..dfa37af 100644 --- a/iemlib1/src/iemlib1.c +++ b/iemlib1/src/iemlib1.c @@ -36,6 +36,7 @@ void peakenv_hold_tilde_setup(void); void prvu_tilde_setup(void); void pvu_tilde_setup(void); void rvu_tilde_setup(void); +void sin_freq_tilde_setup(void); void sin_phase_tilde_setup(void); void sparse_FIR_tilde_setup(void); void soundfile_info_setup(void); @@ -70,6 +71,7 @@ void iemlib1_setup(void) prvu_tilde_setup(); pvu_tilde_setup(); rvu_tilde_setup(); + sin_freq_tilde_setup(); sin_phase_tilde_setup(); sparse_FIR_tilde_setup(); soundfile_info_setup(); @@ -77,6 +79,6 @@ void iemlib1_setup(void) v2db_setup(); vcf_filter_tilde_setup(); - post("iemlib1 (R-1.17) library loaded! (c) Thomas Musil 11.2010"); + post("iemlib1 (R-1.18) library loaded! (c) Thomas Musil 11.2011"); post(" musil%ciem.at iem KUG Graz Austria", '@'); } diff --git a/iemlib1/src/makefile_d_fat b/iemlib1/src/makefile_d_fat index 5933091..c997007 100644 --- a/iemlib1/src/makefile_d_fat +++ b/iemlib1/src/makefile_d_fat @@ -33,6 +33,7 @@ SRC = biquad_freq_resp.c \ prvu~.c \ pvu~.c \ rvu~.c \ + sin_freq~.c \ sin_phase~.c \ sparse_FIR~.c \ soundfile_info.c \ diff --git a/iemlib1/src/makefile_linux b/iemlib1/src/makefile_linux index 6eb4543..6e9f461 100644 --- a/iemlib1/src/makefile_linux +++ b/iemlib1/src/makefile_linux @@ -37,6 +37,7 @@ SRC = biquad_freq_resp.c \ prvu~.c \ pvu~.c \ rvu~.c \ + sin_freq~.c \ sin_phase~.c \ sparse_FIR~ \ soundfile_info.c \ diff --git a/iemlib1/src/sin_freq~.c b/iemlib1/src/sin_freq~.c new file mode 100644 index 0000000..0744fa5 --- /dev/null +++ b/iemlib1/src/sin_freq~.c @@ -0,0 +1,102 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iemlib1 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2011 */ + +#include "m_pd.h" +#include "iemlib.h" + +/* --- sin_freq~ - output the frequency of a --- */ +/* --- sinewave in Hz ----- */ +/* --- as a signal ----------------------------- */ + +typedef struct _sin_freq_tilde +{ + t_object x_obj; + t_sample x_prev; + t_sample x_cur_out; + t_sample x_counter; + t_sample x_sr; + t_float x_float_sig_in; +} t_sin_freq_tilde; + +static t_class *sin_freq_tilde_class; + +static t_int *sin_freq_tilde_perform(t_int *w) +{ + t_sample *in = (t_sample *)(w[1]); + t_sample *out = (t_sample *)(w[2]); + t_sin_freq_tilde *x = (t_sin_freq_tilde *)(w[3]); + int i, n = (t_int)(w[4]); + t_sample prev=x->x_prev; + t_sample cur_out=x->x_cur_out; + t_sample counter=x->x_counter; + t_sample sr=x->x_sr; + t_sample delta_x=0.0; + + for(i=0; i<n; i++) + { + if((in[i] >= 0.0) && (prev < 0.0)) /* begin of counting, pos. zero cross of sig_in */ + { + delta_x = prev / (prev - in[i]); /* dx = y1 / (y1 - y2) */ + counter += delta_x; + cur_out = sr / counter; + + counter = 1.0 - delta_x; + } + else + { + counter += 1.0; + } + + prev = in[i]; + out[i] = cur_out; + } + + x->x_prev = prev; + x->x_cur_out = cur_out; + x->x_counter = counter; + + return(w+5); +} + +static void sin_freq_tilde_dsp(t_sin_freq_tilde *x, t_signal **sp) +{ + x->x_sr = (t_sample)sp[0]->s_sr; + dsp_add(sin_freq_tilde_perform, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n); +} + +static void *sin_freq_tilde_new(void) +{ + t_sin_freq_tilde *x = (t_sin_freq_tilde *)pd_new(sin_freq_tilde_class); + + outlet_new(&x->x_obj, &s_signal); + + x->x_prev = 0.0; + x->x_cur_out = 0.0; + x->x_counter = 0.0; + x->x_sr = 44100.0; + x->x_float_sig_in = 0.0; + + return (x); +} + +void sin_freq_tilde_setup(void) +{ + sin_freq_tilde_class = class_new(gensym("sin_freq~"), (t_newmethod)sin_freq_tilde_new, + 0, sizeof(t_sin_freq_tilde), 0, 0); + CLASS_MAINSIGNALIN(sin_freq_tilde_class, t_sin_freq_tilde, x_float_sig_in); + class_addmethod(sin_freq_tilde_class, (t_method)sin_freq_tilde_dsp, gensym("dsp"), 0); +} + +/* +geradengleichung: + +y - y1 = ((y2 - y1) / (x2 - x1)) * (x - x1) +y = ((y2 - y1) / (x2 - x1)) * (x - x1) + y1 = 0 +x1 = 0 +x2 = 1 +0 = ((y2 - y1) / 1) * (x) + y1 +-y1 = (y2 - y1) * x +x = y1 / (y1 - y2) +*/ |