Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreguillot committed Jul 25, 2018
1 parent 3ae0285 commit c370b36
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 36 deletions.
58 changes: 37 additions & 21 deletions external/faustgen~-help.pd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#N canvas 428 137 481 548 10;
#X obj 12 15 cnv 15 360 17 empty empty faustgen~ 2 9 0 14 -233017 -66577
0;
#X obj 286 115 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
#X obj 286 115 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X msg 286 135 \; pd dsp \$1;
#X obj 32 308 dac~ 1 2;
Expand All @@ -27,26 +27,28 @@ using the programming language "Pure" : https://github.com/agraef/pure-lang.
, f 67;
#X text 125 189 Control the parameters with their names, f 15;
#X text 26 399 faustgen~ institutions: CICM - ANR MUSICOLL;
#X text 26 413 faustgen~ website: github.com/grame-cncm/faust-pd;
#X text 26 427 faustgen~ developer: Pierre Guillot;
#X msg 62 211 gain \$1;
#X obj 32 118 osc~ 220;
#X obj 31 265 faustgen~ examples/gain;
#N canvas 389 171 372 237 options 0;
#N canvas 766 136 471 246 options 0;
#X text 16 70 Change the compile options and recompile;
#X msg 17 91 compileoptions -vec -vs 64;
#X text 56 141 Use the compile options as default arguments;
#X text 19 196 All the compile options are listed page 54 and page
55 of the PDF file faust-quick-reference, f 46;
#X obj 17 165 faustgen~ examples/gain -vec -lv 1 -double;
#X text 21 27 Use the compile options to optimize the CPU or improve
the redering, f 55;
#X msg 41 115 print;
#X text 84 116 Print faustgen~ informations;
#X connect 1 0 4 0;
#X connect 6 0 4 0;
#X obj 405 65 switch~;
#X obj 405 43 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 17 165 faustgen~ examples/gain -vec -lv 1;
#X connect 1 0 9 0;
#X connect 5 0 9 0;
#X connect 8 0 7 0;
#X restore 287 185 pd options;
#N canvas 287 129 388 208 recompilation 0;
#N canvas 287 129 524 202 recompilation 0;
#X obj 17 75 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1
;
#X msg 17 134 autocompile \$1 100;
Expand All @@ -61,11 +63,12 @@ f 37;
#X msg 155 134 compile;
#X text 214 128 Reload and recompile the FAUST file manually, f 23
;
#X obj 339 90 switch~;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 6 0 2 0;
#X restore 287 214 pd recompilation;
#N canvas 364 121 646 630 control 0;
#N canvas 575 109 646 630 control 0;
#X obj 30 598 dac~ 1 2;
#X msg 45 195 print;
#N canvas 0 22 450 278 (subpatch) 0;
Expand Down Expand Up @@ -129,12 +132,14 @@ the index 2, f 36;
#X text 199 388 Dynamic approach, f 9;
#X text 254 398 Index;
#X text 312 398 Size;
#X obj 30 566 *~;
#X obj 45 546 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
#X obj 303 107 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X text 301 86 Turn DSP on;
#X obj 303 128 switch~;
#X connect 1 0 6 0;
#X connect 5 0 6 0;
#X connect 6 0 33 0;
#X connect 6 0 0 0;
#X connect 6 0 0 1;
#X connect 7 0 6 0;
#X connect 8 0 7 0;
#X connect 9 0 8 0;
Expand All @@ -153,15 +158,13 @@ the index 2, f 36;
#X connect 27 0 28 2;
#X connect 28 0 29 0;
#X connect 29 0 24 0;
#X connect 33 0 0 0;
#X connect 33 0 0 1;
#X connect 34 0 33 1;
#X connect 33 0 35 0;
#X restore 287 243 pd control lists;
#N canvas 532 169 409 407 passive 0;
#X obj 32 308 dac~ 1 2;
#X obj 32 118 osc~ 220;
#X obj 30 265 faustgen~ examples/mixer;
#X msg 85 184 print;
#X msg 242 79 print;
#X msg 257 216 compile;
#X msg 145 199 snapshot;
#X msg 309 268 john;
Expand All @@ -173,6 +176,7 @@ the index 2, f 36;
-262144 -1 -1 0 256;
#X obj 160 142 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X obj 128 71 switch~;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
#X connect 2 0 0 1;
Expand All @@ -184,11 +188,23 @@ the index 2, f 36;
#X connect 7 0 8 0;
#X connect 9 0 10 0;
#X restore 287 273 pd passive parameters;
#X obj 103 305 snapshot~;
#X obj 103 326 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10
-262144 -1 -1 0.619613 256;
#X obj 103 284 metro 100;
#X obj 103 264 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 31 242 faustgen~ examples/gain;
#X text 26 413 faustgen~ website: github.com/CICM/faust-pd;
#X connect 1 0 2 0;
#X connect 4 0 19 0;
#X connect 4 0 18 0;
#X connect 5 0 6 0;
#X connect 6 0 4 0;
#X connect 19 0 21 0;
#X connect 20 0 21 0;
#X connect 21 0 3 0;
#X connect 21 0 3 1;
#X connect 18 0 28 0;
#X connect 19 0 28 0;
#X connect 24 0 25 0;
#X connect 26 0 24 0;
#X connect 27 0 26 0;
#X connect 28 0 3 0;
#X connect 28 0 3 1;
#X connect 28 0 24 0;
40 changes: 33 additions & 7 deletions src/faust_tilde_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,21 @@ static char faust_io_manager_resize_inputs(t_faust_io_manager *x, size_t const n
{
return 0;
}
for(i = rnins; i < cins; ++i)
for(i = cins; i > rnins; --i)
{
inlet_free(x->f_inlets[i]);
x->f_inlets[i] = NULL;
inlet_free(x->f_inlets[i-1]);
x->f_inlets[i-1] = NULL;
}
ninlets = (t_inlet **)resizebytes(x->f_inlets, sizeof(t_inlet*) * cins, sizeof(t_inlet*) * rnins);
if(ninlets)
{
for(i = cins; i < rnins; ++i)
{
ninlets[i] = signalinlet_new((t_object *)x->f_owner, 0);
if(!ninlets[i])
{
pd_error(x->f_owner, "faustgen~: memory allocation failed - input %i", (int)i);
}
}
x->f_inlets = ninlets;
x->f_ninlets = rnins;
Expand All @@ -121,26 +125,48 @@ static char faust_io_manager_resize_outputs(t_faust_io_manager *x, size_t const
size_t i;
size_t const couts = faust_io_manager_get_noutputs(x);
size_t const rnouts = nouts;
if(rnouts == couts && faust_io_manager_has_extra_output(x) == extraout)

if(rnouts == couts)
{
if(faust_io_manager_has_extra_output(x) && !extraout)
{
outlet_free(x->f_extra_outlet);
x->f_extra_outlet = NULL;
return 0;
}
else if(!faust_io_manager_has_extra_output(x) && extraout)
{
x->f_extra_outlet = outlet_new((t_object *)x->f_owner, NULL);
if(x->f_extra_outlet)
{
return 0;
}
pd_error(x->f_owner, "faustgen~: memory allocation failed - extra output");
return 1;
}
return 0;
}

if(faust_io_manager_has_extra_output(x))
{
outlet_free(x->f_extra_outlet);
x->f_extra_outlet = NULL;
}
for(i = rnouts; i < couts; ++i)
for(i = couts; i > rnouts; --i)
{
outlet_free(x->f_outlets[i]);
x->f_outlets[i] = NULL;
outlet_free(x->f_outlets[i-1]);
x->f_outlets[i-1] = NULL;
}
noutlets = (t_outlet **)resizebytes(x->f_outlets, sizeof(t_outlet*) * couts, sizeof(t_outlet*) * rnouts);
if(noutlets)
{
for(i = couts; i < rnouts; ++i)
{
noutlets[i] = outlet_new((t_object *)x->f_owner, gensym("signal"));
if(!noutlets[i])
{
pd_error(x->f_owner, "faustgen~: memory allocation failed - output %i", (int)i);
}
}
x->f_outlets = noutlets;
x->f_noutlets = rnouts;
Expand Down
2 changes: 1 addition & 1 deletion src/faust_tilde_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ char faust_ui_manager_set(t_faust_ui_manager *x, t_symbol* name, t_float f)
*(ui->p_zone) = ui->p_min;
return 0;
}
else if(v > ui->p_max)
if(v > ui->p_max)
{
*(ui->p_zone) = ui->p_max;
return 0;
Expand Down
90 changes: 83 additions & 7 deletions src/faustgen_tilde.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <sys/stat.h>

#include <faust/dsp/llvm-c-dsp.h>
Expand All @@ -24,6 +25,11 @@ typedef struct _faustgen_tilde
t_object f_obj;
llvm_dsp_factory* f_dsp_factory;
llvm_dsp* f_dsp_instance;

FAUSTFLOAT** f_signal_matrix;
FAUSTFLOAT* f_signal_aligned;
size_t f_signal_aligned_size;

t_faust_ui_manager* f_ui_manager;
t_faust_io_manager* f_io_manager;
t_faust_opt_manager* f_opt_manager;
Expand Down Expand Up @@ -242,24 +248,90 @@ static void faustgen_tilde_anything(t_faustgen_tilde *x, t_symbol* s, int argc,

static t_int *faustgen_tilde_perform(t_int *w)
{
computeCDSPInstance((llvm_dsp *)w[1], (int)w[2], (FAUSTFLOAT **)w[3], (FAUSTFLOAT **)w[4]);
return (w+5);
int i, j;
llvm_dsp *dsp = (llvm_dsp *)w[1];
int const nsamples = (int)w[2];
int const ninputs = (int)w[3];
int const noutputs = (int)w[4];
FAUSTFLOAT** faustsigs = (FAUSTFLOAT **)w[5];
t_sample const** realinputs = (t_sample const**)w[6];
t_sample** realoutputs = (t_sample **)w[7];
for(i = 0; i < ninputs; ++i)
{
for(j = 0; j < nsamples; ++j)
{
faustsigs[i][j] = (FAUSTFLOAT)realinputs[i][j];
}
}
computeCDSPInstance(dsp, nsamples, faustsigs, faustsigs+ninputs);
for(i = 0; i < noutputs; ++i)
{
for(j = 0; j < nsamples; ++j)
{
realoutputs[i][j] = (t_sample)faustsigs[ninputs+i][j];
}
}
return (w+8);
}

static void faustgen_tilde_free_signal(t_faustgen_tilde *x)
{
if(x->f_signal_aligned)
{
free(x->f_signal_aligned);
}
x->f_signal_aligned = NULL;
if(x->f_signal_matrix)
{
free(x->f_signal_matrix);
}
x->f_signal_matrix = NULL;
}

static void faustgen_tilde_dsp(t_faustgen_tilde *x, t_signal **sp)
{
if(x->f_dsp_instance)
{
faust_ui_manager_save_states(x->f_ui_manager);
initCDSPInstance(x->f_dsp_instance, sp[0]->s_sr);
char initialized = getSampleRateCDSPInstance(x->f_dsp_instance) != sp[0]->s_sr;
if(initialized)
{
faust_ui_manager_save_states(x->f_ui_manager);
initCDSPInstance(x->f_dsp_instance, sp[0]->s_sr);
}
if(!faust_io_manager_prepare(x->f_io_manager, sp))
{
dsp_add((t_perfroutine)faustgen_tilde_perform, 4,
(t_int)x->f_dsp_instance, (t_int)sp[0]->s_n,
size_t i;
size_t const ninputs = faust_io_manager_get_ninputs(x->f_io_manager);
size_t const noutputs = faust_io_manager_get_noutputs(x->f_io_manager);
size_t const nsamples = (size_t)sp[0]->s_n;

faustgen_tilde_free_signal(x);
x->f_signal_aligned = (t_sample *)malloc((ninputs + noutputs) * nsamples * sizeof(FAUSTFLOAT));
if(!x->f_signal_aligned)
{
pd_error(x, "memory allocation failed");
return;
}
x->f_signal_matrix = (FAUSTFLOAT **)malloc((ninputs + noutputs) * sizeof(FAUSTFLOAT *));
if(!x->f_signal_matrix)
{
pd_error(x, "memory allocation failed");
return;
}
for(i = 0; i < (ninputs + noutputs); ++i)
{
x->f_signal_matrix[i] = (x->f_signal_aligned+(i*nsamples));
}
dsp_add((t_perfroutine)faustgen_tilde_perform, 7,
(t_int)x->f_dsp_instance, (t_int)nsamples, (t_int)ninputs, (t_int)noutputs,
(t_int)x->f_signal_matrix,
(t_int)faust_io_manager_get_input_signals(x->f_io_manager),
(t_int)faust_io_manager_get_output_signals(x->f_io_manager));
}
faust_ui_manager_restore_states(x->f_ui_manager);
if(initialized)
{
faust_ui_manager_restore_states(x->f_ui_manager);
}
}
}

Expand All @@ -280,6 +352,10 @@ static void *faustgen_tilde_new(t_symbol* s, int argc, t_atom* argv)
x->f_dsp_factory = NULL;
x->f_dsp_instance = NULL;

x->f_signal_matrix = NULL;
x->f_signal_aligned = NULL;
x->f_signal_aligned_size = 0;

x->f_ui_manager = faust_ui_manager_new((t_object *)x);
x->f_io_manager = faust_io_manager_new((t_object *)x, canvas_getcurrent());
x->f_opt_manager = faust_opt_manager_new((t_object *)x, canvas_getcurrent());
Expand Down

0 comments on commit c370b36

Please sign in to comment.