Skip to content

Commit

Permalink
trunc~
Browse files Browse the repository at this point in the history
  • Loading branch information
porres committed Jul 2, 2024
1 parent f1ae572 commit dd5e6fb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 109 deletions.
104 changes: 28 additions & 76 deletions cyclone_objects/binaries/audio/trunc.c
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---------------------------------------------------


12 changes: 6 additions & 6 deletions documentation/help_files/pink~-help.pd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#N canvas 299 60 565 549 10;
#N canvas 355 101 565 549 10;
#X declare -stdpath ./;
#X obj 226 168 cyclone/pink~;
#X text 63 86 [pink~] generates pink noise. This is not an actual MAX clone but an object that is borrowed from ELSE which has more functionalities and is backwards compatible to MAX's object since the original just outputs pink noise!, f 75;
Expand Down Expand Up @@ -67,9 +67,9 @@
#X obj 3 2 ./header pink~;
#X text 22 61 Pink noise generator;
#X obj 62 211 declare -stdpath ./;
#X obj 413 319 open-else;
#X text 51 296 Plugdata users actually have the object from ELSE instead \, and those with ELSE can just use the original instead.;
#X msg 413 292 pink~;
#X text 454 291 click;
#X obj 331 318 open-else;
#X msg 331 291 pink~;
#X text 372 290 click;
#X text 116 291 Plugdata users can just use the original object from ELSE instead (same with those with ELSE)., f 33;
#X connect 0 0 18 0;
#X connect 24 0 22 0;
#X connect 23 0 22 0;
54 changes: 27 additions & 27 deletions documentation/help_files/trunc~-help.pd
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;

0 comments on commit dd5e6fb

Please sign in to comment.