SynthMaker

Code Component

Archive · 2005 7 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

rl ·

Hi Guys. You asked for early adopter feedback, Ok I'm starting with the code component:

Basically: It's great!!!!, some minor suggestions:

For longer code-parts scrollbars would be helpful

When doing mistakes, the place where the error occurs can be guessed by the fact that sm gives up on syntax colouring. I would prefer a visble marker for the error location.

For longer codes, editing seems to become slow.

The sin1 function is a good start, but I want more 😉 : tanh, pow, exp, log,...

Subroutines (maybe with inline expansion) would be great.

How about control structures (if, for,...)

What is the difference between monoin/out and polyin/out vars?

bye, rl

jorge ·

rl wrote: The sin1 function is a good start, but I want more 😉 : tanh, pow, exp, log,...

If one of those is urgent and you're getting stuck because of not having it, please let us know. You can actually create your own using taylor expansion series inside a code component, that's probably how it would work if you had those functions anyway, but ofcourse it's much better to have the functions ready.

rl wrote: Subroutines (maybe with inline expansion) would be great.

I think that will happen at some stage. Probably not for v1.0.

rl wrote: How about control structures (if, for,...)

The code component processes 4 voices at the same time. Loops should be possible as they affect the 4 voices but conditional jumps are not possible if you want to keep using SSE instructions for processing 4 voices at the same time. There are ways to avoid conditional jumps by using compare functions to create masks and using the masks with boolean operations. For example the following control structure:

if ( cnt >= 1.0 ) cnt = cnt - 1.0;

can be done as follows:

cnt=cnt - ( ( cnt >= 1.0 ) & 1.0 );

rl wrote: What is the difference between monoin/out and polyin/out vars?

Poly data is passed around as SSE data with 4 floats together with each float being used for a separate voice/note. Mono data is also passed around as SSE data with 4 floats but only the first float is used. You can use Poly components as if they were Mono, it will work, but you might be wasting processing of the 3 unused floats. If you use Mono components as if they were Poly, every 4th note you play will work but not the other 3. The idea is to use Poly data all the way up to the PolyToMono component and Mono data after that, that way the effects section of your synth is calculated only once independently of the number of notes played.

malc ·

Hi rl,

rl wrote: For longer code-parts scrollbars would be helpful

When doing mistakes, the place where the error occurs can be guessed by the fact that sm gives up on syntax colouring. I would prefer a visble marker for the error location.

Some good suggestions there. Shouldn't be too difficult. I will add that to the list 🙂

rl wrote: ]For longer codes, editing seems to become slow.

Yes, I see what you mean. I'll need to look at this.

Thanks for the info, always very helpful to us.

rl ·

jorge wrote: For example the following control structure:

if ( cnt >= 1.0 ) cnt = cnt - 1.0;

can be done as follows:

cnt=cnt - ( ( cnt >= 1.0 ) & 1.0 );

yes, I remember these tricks from the old days of C programming.....

jorge wrote: Poly data is passed around as SSE data with 4 floats together with each float being used for a separate voice/note. Mono data is also passed around as SSE data with 4 floats but only the first float is used. You can use Poly components as if they were Mono, it will work, but you might be wasting processing of the 3 unused floats. If you use Mono components as if they were Poly, every 4th note you play will work but not the other 3. The idea is to use Poly data all the way up to the PolyToMono component and Mono data after that, that way the effects section of your synth is calculated only once independently of the number of notes played.

thanks for the explaination, so for the code within the code component there should be no difference ?!

rl

jorge ·

Hi rl

rl wrote: so for the code within the code component there should be no difference ?!

Yeah, correct, I guess that's the simple answer you wanted.

At the moment anything you do inside the Code component will process the four sound channels at the same time. It means it will work for both poly and mono although there might be ways later on to make the mono code more efficient in certain cases.

If you have any other questions please let us know.

rl ·

jorge wrote: If you have any other questions please let us know.

Well, yes....

It looks like the only implemented comparison operator ist '>=', there ist no '<', '<='. '>', at least syntax highlighting stops here. Also the unary '-' operator is not completely supported. I had to write '-1 * x' instead of '-x'.

Againt the missing if-then-else structure gives me some headaches. Example: I'm working on a filter algo that uses the tanh function to model non-linear behavior.

tanh (x) = 1 - 2 / (exp (2*x) + 1) replacing exp(2x) with the first three terms of a taylor series:

tanh(x) = 1 - 2 / ( 1 + 2*x + 2*x*x + 4/3*x*x*x + 1 )

since this approximation is only good for x => 0, I would use the fact that tanh is an odd function, thus tanh(-x) = -tanh(x) for x < 0, so in plain old C i would write:

if ( x >= 0) tanh_result = 1 - 2 / ( 1 + 2*x + 2*x*x + 4/3*x*x*x + 1 ); else tanh_result = -1* ( 1 - 2 / ( 1 - 2*x + 2*x*x - 4/3*x*x*x + 1 ) );

Actually using all said workarounds my code looks like this:

tanh_result = (x >= 0) * ( 1 - 2 / ( 1 + 2*x + 2*x*x + 4/3*x*x*x + 1 ) ) + (-1*x >= 0) * -1 * ( 1 - 2 / ( 1 - 2*x + 2*x*x - 4/3*x*x*x + 1 ) );

I trying to misuse the boolean result of the comparison as numical value (0 or 1) for the multiplication. (Can I expect the comparison result having the value '1'?)

As you can see the code in the example looks a bit cluttered. I understand that you have good reasons not to support control structures.

Things that would help me are subroutines, eg:

float function tanh (float x) {......

They could be placed inside the code component and maybe evaluated by means of macro expansion techniques, or even better you could provide code library components that can be placed somewhere on the schematics.

stefan ·

The comparison ( >= ) results in a bool mask, not 1.0. You should use the & operator, probably like this:

tanh_result = (x >= 0) & ( 1 - 2 / ( 1 + 2*x + 2*x*x + 4/3*x*x*x + 1 ) ); + (-1*x >= 0) & (-1 * ( 1 - 2 / ( 1 - 2*x + 2*x*x - 4/3*x*x*x + 1 ) ) ) ;

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.