Re: varying a synthdef with respect to input frequency

[email protected]
Newsgroups gmane.comp.audio.supercollider.user
Message-ID <CAFniQ7WEjSjhoCgXS33aN0TYRAnrXg9QuNr7QingaGeaUXqBaQ@mail.gmail.com>
On Thu, Mar 18, 2021 at 10:26 PM <[email protected]> wrote:
> Given that I was happy with this model I wanted to implement it as a synthdef. The freq and sig inputs are bus numbers. The problem is that when I try to instantiate it, I get the error: "ERROR: Non Boolean in test" in which it points to the first of the comparisons of fr >= cutoff_freq. I assume it's because I'm trying to compare a control signal (fr) to a constant (cutoff_freq1).

The main problem here is that, in server-style logic, reassigning a
variable isn't allowed.

A variable is a language-site concept. The server literally has no
idea what `div` is. The server can't change the value of `div` based
on server-side values.

The comparison `freq >= cutoff_freq` is fine (no DC.kr needed). It's
the `div = ...` that is the problem.

You could do:

div = case
{ i == 1 } { 1 }
{ i == 3 } {
    if(freq >= cutoff_freq, 0.5, 0.2)
}
{ i == 4 } {
    if(freq >= cutoff_freq, 0.1, 0.4)
}
{ 0.02 }; // default case

(However, there's a slight inefficiency: `freq >= cutoff_freq` is
calculated twice. I'd save the UGen result of this comparison in a
variable and use the variable in the 'if' expressions.)

I think, however, that a lookup table would be more efficient. Here,
it's a small lookup, so you could encode it directly in the synth.
Let's say: 2 values for each i, interleaved (and clip the index to
handle `i > 4`).

var div_lookup = [
    0.5, 0.5,  // i == 0: first is freq >= cutoff
    1, 1,      // i == 1, etc.
    0.5, 0.5,
    0.2, 0.5,
    0.4, 0.1,
    0.02, 0.02
];

var div = Select.kr(
    (min(i, 5) * 2) + (freq >= cutoff_freq),
    div_lookup
);

No conditionals!

For larger lookup tables, I would use a Buffer with Index.kr. This is
small enough that it's not worth the trouble.

hjh

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.