-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,39 @@ | ||
/* code generated thanks to Schiavoni's Pure Data external Generator */ | ||
// Porres 2017-2023, part of ELSE | ||
|
||
#include "m_pd.h" | ||
#include <common/api.h> | ||
#include "math.h" | ||
#include <math.h> | ||
|
||
// --------------------------------------------------- | ||
// Class definition | ||
// --------------------------------------------------- | ||
static t_class *trunc_class; | ||
|
||
// --------------------------------------------------- | ||
// Data structure definition | ||
// --------------------------------------------------- | ||
typedef struct _trunc { | ||
t_object x_obj; | ||
t_outlet * x_outlet_dsp_0; | ||
} t_trunc; | ||
|
||
// --------------------------------------------------- | ||
// Functions signature | ||
// --------------------------------------------------- | ||
void * trunc_new(void);// Constructor | ||
void trunc_destroy(t_trunc *x); //Destructor | ||
static t_int * trunc_perform(t_int *w); //Perform function | ||
static void trunc_dsp(t_trunc *x, t_signal **sp); //DSP function | ||
|
||
// --------------------------------------------------- | ||
// Perform | ||
// --------------------------------------------------- | ||
static t_int * trunc_perform(t_int *w) | ||
{ | ||
t_trunc *x = (t_trunc *)(w[1]); // Seu objeto | ||
int n = (int)(w[2]); // Número de samples no bloco | ||
t_float *in1 = (t_float *)(w[3]); // bloco de entrada | ||
t_float *out1 = (t_float *)(w[4]); // bloco de saida | ||
|
||
//interagir com todas as amostras do bloco (de 0 a n) | ||
int i = 0; | ||
for (i = 0 ; i < n ; i++){ | ||
out1[i] = trunc(in1[i]); // trunc~ | ||
} | ||
return (w + 5); // proximo bloco | ||
typedef struct _trunc{ | ||
t_object x_obj; | ||
}t_trunc; | ||
|
||
static t_int * trunc_perform(t_int *w){ | ||
int n = (int)(w[1]); | ||
t_float *in = (t_float *)(w[2]); | ||
t_float *out = (t_float *)(w[3]); | ||
while(n--) | ||
*out++ = trunc(*in++); | ||
return(w+4); | ||
} | ||
|
||
// --------------------------------------------------- | ||
// DSP Function | ||
// --------------------------------------------------- | ||
static void trunc_dsp(t_trunc *x, t_signal **sp) | ||
{ | ||
dsp_add(trunc_perform, 4, x, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec); | ||
static void trunc_dsp(t_trunc *x, t_signal **sp){ | ||
x = NULL; | ||
signal_setmultiout(&sp[1], sp[0]->s_nchans); | ||
dsp_add(trunc_perform, 3, (t_int)(sp[0]->s_length * sp[0]->s_nchans), | ||
sp[0]->s_vec, sp[1]->s_vec); | ||
} | ||
|
||
// --------------------------------------------------- | ||
// Constructor of the class | ||
// --------------------------------------------------- | ||
void * trunc_new(void) | ||
{ | ||
t_trunc *x = (t_trunc *) pd_new(trunc_class); | ||
x->x_outlet_dsp_0 = outlet_new(&x->x_obj, &s_signal); | ||
return (void *) x; | ||
void *trunc_new(void){ | ||
t_trunc *x = (t_trunc *)pd_new(trunc_class); | ||
outlet_new(&x->x_obj, &s_signal); | ||
return(void *)x; | ||
} | ||
|
||
// --------------------------------------------------- | ||
// Destroy the class | ||
// --------------------------------------------------- | ||
void trunc_destroy(t_trunc *x) | ||
{ | ||
outlet_free(x->x_outlet_dsp_0); | ||
void trunc_tilde_setup(void){ | ||
trunc_class = class_new(gensym("trunc~"), | ||
(t_newmethod) trunc_new, 0, sizeof (t_trunc), CLASS_MULTICHANNEL, 0); | ||
class_addmethod(trunc_class, nullfn, gensym("signal"), 0); | ||
class_addmethod(trunc_class, (t_method) trunc_dsp, gensym("dsp"), A_CANT, 0); | ||
} | ||
|
||
// --------------------------------------------------- | ||
// Setup | ||
// --------------------------------------------------- | ||
CYCLONE_OBJ_API void trunc_tilde_setup(void) { | ||
trunc_class = class_new(gensym("trunc~"), | ||
(t_newmethod) trunc_new, // Constructor | ||
(t_method) trunc_destroy, // Destructor | ||
sizeof (t_trunc), | ||
CLASS_DEFAULT, | ||
0);//Must always ends with a zero | ||
|
||
class_addmethod(trunc_class, nullfn, gensym("signal"), 0); | ||
class_addmethod(trunc_class, (t_method) trunc_dsp, gensym("dsp"), A_CANT, 0); | ||
} | ||
// EOF--------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
#N canvas 413 30 566 546 10; | ||
#X obj 7 407 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0; | ||
#X obj 7 455 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0; | ||
#X obj 7 492 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0; | ||
#X obj 116 464 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0; | ||
#X obj 116 421 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0; | ||
#X text 144 464 signal; | ||
#X text 197 502 (none); | ||
#X obj 7 524 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0; | ||
#X obj 216 174 nbx 8 14 -127 127 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256; | ||
#X obj 219 148 hsl 180 15 -127 127 0 0 empty empty empty -2 -8 0 10 #dcdcdc #000000 #000000 0 1; | ||
#X obj 216 199 sig~; | ||
#X obj 216 232 cyclone/trunc~; | ||
#X text 144 421 signal; | ||
#X text 78 95 [trunc~] converts signals with fractional values such as 1.75 to 1 (negative values are modified so that -1.75 becomes -1).; | ||
#X text 199 421 - a signal whose values will be truncated; | ||
#X text 197 464 - the truncated input signal; | ||
#X text 73 295 The truncated value =>; | ||
#N canvas 413 38 570 582 10; | ||
#X obj 7 437 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0; | ||
#X obj 7 485 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0; | ||
#X obj 7 522 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0; | ||
#X obj 116 494 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0; | ||
#X obj 116 451 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0; | ||
#X text 144 494 signal; | ||
#X text 197 532 (none); | ||
#X obj 7 554 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0; | ||
#X obj 216 204 nbx 8 14 -127 127 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256; | ||
#X obj 219 178 hsl 180 15 -127 127 0 0 empty empty empty -2 -8 0 10 #dcdcdc #000000 #000000 0 1; | ||
#X obj 216 229 sig~; | ||
#X obj 216 262 cyclone/trunc~; | ||
#X text 144 451 signal; | ||
#X text 199 451 - a signal whose values will be truncated; | ||
#X text 197 494 - the truncated input signal; | ||
#X text 73 325 The truncated value =>; | ||
#X obj 499 69 cyclone/dsponoff~; | ||
#X text 24 59 Truncate signal values; | ||
#X obj 216 265 cyclone/snapshot~ 1; | ||
#X obj 216 295 nbx 9 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256; | ||
#X obj 216 295 cyclone/snapshot~ 1; | ||
#X obj 216 325 nbx 9 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256; | ||
#X obj 5 6 header trunc~; | ||
#X obj 410 360 open-else; | ||
#X text 457 337 click; | ||
#X msg 410 338 trunc~; | ||
#X text 80 338 Note that Plugdata users actually get [else/trunc~] instead \, which also has multichannel capabilities and is more powerful., f 51; | ||
#X obj 370 394 open-else; | ||
#X text 417 371 click; | ||
#X msg 370 372 trunc~; | ||
#X text 78 95 [trunc~] truncates a signal towards zero \, that means only the integer value is considered. This is not an actual MAX clone but an object that is borrowed from ELSE which has more functionalities (support for multichannel connections) and is backwards compatible to MAX's.; | ||
#X text 149 367 Plugdata users can just use the original object from ELSE instead (same with those with ELSE)., f 33; | ||
#X connect 8 0 10 0; | ||
#X connect 9 0 8 0; | ||
#X connect 10 0 11 0; | ||
#X connect 11 0 19 0; | ||
#X connect 19 0 20 0; | ||
#X connect 24 0 22 0; | ||
#X connect 11 0 18 0; | ||
#X connect 18 0 19 0; | ||
#X connect 23 0 21 0; |