Skip to content

Commit

Permalink
pd: correctly handle sample rate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacechild1 authored and sletz committed Jul 11, 2024
1 parent a8e88ee commit f8f1616
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions architecture/puredata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ static t_int *faust_perform(t_int *w)
static void faust_dsp(t_faust *x, t_signal **sp)
{
int n = sp[0]->s_n, sr = (int)sp[0]->s_sr;
if (x->rate <= 0) {
/* default sample rate is whatever Pd tells us */
if (sr != x->rate) {
/* update sample rate */
PdUI *ui = x->ui;
float *z = NULL;
if (ui->nelems > 0 &&
Expand Down Expand Up @@ -659,14 +659,17 @@ static void *faust_new(t_symbol *s, int argc, t_atom *argv)
} else break;
}
// sr|id
// NB: we keep this code for backwards compatibility.
// 'sr' doesn't really do anything because faust_dsp() will
// always update the DSP to the actual samplerate.
for (int i = 0; i < argc; i++) {
if (argv[i].a_type == A_FLOAT)
sr = (int)argv[i].a_w.w_float;
else if (argv[i].a_type == A_SYMBOL)
id = argv[i].a_w.w_symbol;
}
x->rate = sr; // NB: keep -1, see faust_dsp()
if (sr <= 0) sr = 44100;
x->rate = sr;
x->xfade = 0;
x->n_xfade = (int)(sr*XFADE_TIME/64);
x->inputs = x->outputs = x->buf = NULL;
Expand Down

0 comments on commit f8f1616

Please sign in to comment.