SynthMaker

code question (and glitches on output)

Archive · 2012 11 old posts

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

tester ·

Is it possible to make in the code a bypas, when some of the float inputs get certain values? I have a code, that performs a math function on input signal, but when the math result is no different from input - I'd like to bypass the math function. It takes some CPU to calculate, so I'd like to optimize.

Here is the code:

streamin in; streamin shape; streamout out;

float polarity; float absolute;

//Get polarity and rectify polarity = sign(in); //will be -1 or 1 absolute = abs(in); //rectify to all positive

// math function to bypass when shape = 1 out = pow(absolute,shape);

//Restore sign out = out * polarity;

tester ·

I see that I have a second problem with this code-based input processing. I'm using this processed signal as a very slow LFO. I have glitches on output (CPU shows norm). Glitches seem to appear somewhat randomly but only where the split (positive/negative values) takes place in the code. What I'm missing?

cyto ·

It is not possible to bypass instructions internally based on values in the code module. It is, however, very doable in assembly. I often set up routines that only get run when incoming values change. I don't know how well versed you are in assembly language, but if this is something you really need, it might be worth it to invest in the time to learn it. Otherwise, you could use external selectors to bypass entire code blocks based on the "shape" value, but that might result in glitches when the stream re-initializes.

Regarding your spike values: that is a result of the using the pow(x,y) with a zero base. I know mathematically it is sound, but the way SM calculates the pow(x,y) instruction causes this glitch...

You could include a little conditional that adds a small value (ie 1e-036) to any zeroes before performing the pow(x,y) instruction.

-cyto

tester ·

Thanks!

Meanwhile I found that I probably could use different solution on the schematic itself. Because the LFO acts as a switchable ring modulator (bipolar modulation) or autopanner (unipolar modulation) - I could just add DC switch on first place, and then 'absolute' module to invert negative values (which occur only at bipolar AM; it can be done because both sides of bipoar signal modulate in the same positive way), and then - add the power function (via core or primitives) plus maybe some switch regarding where add this power (bipoar absolutized) and where not (unipolar).

tester ·

Okay, I give up 😉 @cyto - I'm a greenhorn here. What should I to add to this particular code, to avoid glitches? Something like this?

absolute = absolute + (absolute <=0)&(1e-036);

just before math?

cyto ·

tester wrote: Something like this?

absolute = absolute + (absolute <=0)&(1e-036);

just before math?

That should work just fine 😉

-cyto

martinvicanek ·

Or why not just absolute = absolute + 1e-036;

tester ·

Is not the first one - raising up the local signal value (zero or less), and the second one the whole signal?

Just a habit to stay formal somewhat 😉

Anyway - it works. Thakns!

I decided to add a separate on/off switch for powering the signal. This code takes a lot of CPU, even if the exponent = 1 and output is unchanged.

cyto ·

tester wrote: Is not the first one - raising up the local signal value (zero or less), and the second one the whole signal

Yes, but technically the first one only raises a zero value because there should be no value less than zero. Martin's example does raise the whole signal but it has the advantage avoiding a bunch of internal maths necessary to do the compare. With a value like 1e-036 the result will be virtually the same.

Perhaps the "best" way to go about this is like so...

out = pow(absolute,shape)&(absolute!=0);

This method should mask out all of the spikes while still maintaining the dc integrity of the signal. But again, with such an inconsequential number like 1e-036 (or whatever), it really shouldn't make that much difference.

-cyto

tester ·

I see, thanks for detailed explanations and examples. Learning such contextual basics helps with more advanced topics.

By the way - I'm curious - is a way to speed up this code (or just the symetric power function for bipolar signals)?

infuzion ·

tester wrote: By the way - I'm curious - is a way to speed up this code (or just the symetric power function for bipolar signals)?

You can translate it into ASM then remove the unused channels, or/& use Pack4. There are optimized POWs around...

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.