Skip to content

Commit 79a5095

Browse files
committed
borrow tanh~ from ELSE
1 parent beb6dd1 commit 79a5095

File tree

2 files changed

+64
-49
lines changed

2 files changed

+64
-49
lines changed

cyclone_objects/binaries/audio/tanh.c

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,37 @@
66
#include "m_pd.h"
77
#include <common/api.h>
88

9-
typedef struct _tanh {
10-
t_object x_obj;
11-
t_inlet *tanh;
12-
t_outlet *x_outlet;
13-
} t_tanh;
14-
15-
void *tanh_new(void);
16-
static t_int * tanh_perform(t_int *w);
17-
static void tanh_dsp(t_tanh *x, t_signal **sp);
18-
199
static t_class *tanh_class;
2010

21-
static t_int *tanh_perform(t_int *w)
22-
{
23-
int nblock = (int)(w[1]);
11+
typedef struct _tanh{
12+
t_object x_obj;
13+
}t_tanh;
14+
15+
static t_int * tanh_perform(t_int *w){
16+
int n = (int)(w[1]);
2417
t_float *in = (t_float *)(w[2]);
2518
t_float *out = (t_float *)(w[3]);
26-
while (nblock--)
27-
{
28-
float f = *in++;
29-
*out++ = tanhf(f); /* CHECKED no protection against NaNs */
30-
}
31-
return (w + 4);
19+
while(n--)
20+
*out++ = tanhf(*in++);
21+
return(w+4);
3222
}
3323

34-
static void tanh_dsp(t_tanh *x, t_signal **sp)
35-
{
36-
dsp_add(tanh_perform, 3, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec);
24+
static void tanh_dsp(t_tanh *x, t_signal **sp){
25+
x = NULL;
26+
signal_setmultiout(&sp[1], sp[0]->s_nchans);
27+
dsp_add(tanh_perform, 3, (t_int)(sp[0]->s_length * sp[0]->s_nchans),
28+
sp[0]->s_vec, sp[1]->s_vec);
3729
}
3830

39-
void *tanh_new(void)
40-
{
31+
void *tanh_new(void){
4132
t_tanh *x = (t_tanh *)pd_new(tanh_class);
42-
x->x_outlet = outlet_new(&x->x_obj, &s_signal);
43-
return (x);
33+
outlet_new(&x->x_obj, &s_signal);
34+
return(void *)x;
4435
}
4536

46-
CYCLONE_OBJ_API void tanh_tilde_setup(void)
47-
{
48-
tanh_class = class_new(gensym("tanh~"), (t_newmethod)tanh_new, 0,
49-
sizeof(t_tanh), CLASS_DEFAULT, 0);
37+
CYCLONE_OBJ_API void tanh_tilde_setup(void){
38+
tanh_class = class_new(gensym("tanh~"),
39+
(t_newmethod) tanh_new, 0, sizeof (t_tanh), CLASS_MULTICHANNEL, 0);
5040
class_addmethod(tanh_class, nullfn, gensym("signal"), 0);
5141
class_addmethod(tanh_class, (t_method) tanh_dsp, gensym("dsp"), A_CANT, 0);
5242
}

documentation/help_files/tanh~-help.pd

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
#N canvas 461 70 564 517 10;
1+
#N canvas 502 85 564 582 10;
22
#X declare -stdpath ./;
3-
#X obj 4 485 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
4-
#X obj 4 372 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
5-
#X obj 4 412 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
6-
#X obj 4 451 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
7-
#X obj 136 383 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
8-
#X obj 136 423 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
9-
#X text 164 383 signal;
10-
#X text 164 423 signal;
11-
#X text 165 460 (none);
12-
#X text 231 383 - input to hyperbolic tangent function;
13-
#X text 231 423 - output of hyperbolic tangent function;
14-
#X text 66 97 [tanh~] calculates the hyperbolic tangent function of input sample. It is also useful for waveshaping \, where it simulates analog distortion.;
3+
#X obj 4 555 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
4+
#X obj 4 442 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
5+
#X obj 4 482 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
6+
#X obj 4 521 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
7+
#X obj 136 453 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
8+
#X obj 136 493 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
9+
#X text 164 453 signal;
10+
#X text 164 493 signal;
11+
#X text 165 530 (none);
12+
#X text 231 453 - input to hyperbolic tangent function;
13+
#X text 231 493 - output of hyperbolic tangent function;
1514
#X obj 499 69 cyclone/dsponoff~;
1615
#X obj 3 3 ./header tanh~;
1716
#X text 22 61 Signal hyperbolic tangent function;
18-
#X obj 187 186 sig~;
17+
#X obj 187 192 sig~;
1918
#X obj 187 245 cyclone/snapshot~ 1;
2019
#X obj 187 275 nbx 9 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
21-
#X obj 187 162 nbx 9 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
20+
#X obj 187 170 nbx 9 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
2221
#X obj 187 216 cyclone/tanh~;
2322
#N canvas 657 64 420 544 example 0;
2423
#X obj 232 172 +~ 11;
@@ -41,7 +40,7 @@
4140
#X connect 5 0 3 0;
4241
#X connect 6 0 1 0;
4342
#X connect 10 0 9 0;
44-
#X restore 428 241 pd example;
43+
#X restore 406 226 pd example;
4544
#X text 32 324 see also:;
4645
#X text 200 324 as a Vanilla alternative;
4746
#X text 361 324 and;
@@ -82,7 +81,33 @@
8281
#X text 257 322 - actually a cosine wavetable;
8382
#X restore 393 325 pd all-trig-objects;
8483
#X obj 97 325 expr~ tanh($v1);
85-
#X connect 15 0 19 0;
86-
#X connect 16 0 17 0;
84+
#X text 38 86 [tanh~] calculates the hyperbolic tangent function of input sample. It is also useful for waveshaping \, where it simulates analog distortion. This is not an actual MAX clone but an object that is borrowed from ELSE which has more functionalities (MC Support) and is backwards compatible to MAX's object!, f 70;
85+
#X obj 307 398 open-else;
86+
#X text 348 370 click;
87+
#X text 92 371 Plugdata users can just use the original object from ELSE instead (same with those with ELSE)., f 33;
88+
#X msg 307 371 tanh~;
89+
#N canvas 795 189 371 312 multichannel 0;
90+
#X listbox 58 102 12 0 0 0 - - - 0;
91+
#X text 100 28 Multichannel support example.;
92+
#X obj 58 128 snake~ in;
93+
#X obj 58 161 cyclone/tanh~;
94+
#X obj 58 219 cyclone/snapshot~ 1;
95+
#X obj 58 249 nbx 9 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
96+
#X obj 58 191 snake~ out, f 24;
97+
#X obj 199 219 cyclone/snapshot~ 1;
98+
#X obj 199 249 nbx 9 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
99+
#X obj 58 73 cyclone/loadmess 0.75 1.2;
100+
#X connect 0 0 2 0;
101+
#X connect 2 0 3 0;
102+
#X connect 3 0 6 0;
103+
#X connect 4 0 5 0;
104+
#X connect 6 0 4 0;
105+
#X connect 6 1 7 0;
106+
#X connect 7 0 8 0;
107+
#X connect 9 0 0 0;
108+
#X restore 406 253 pd multichannel;
109+
#X connect 14 0 18 0;
110+
#X connect 15 0 16 0;
111+
#X connect 17 0 14 0;
87112
#X connect 18 0 15 0;
88-
#X connect 19 0 16 0;
113+
#X connect 29 0 26 0;

0 commit comments

Comments
 (0)