SynthMaker

Array/loop bug or my mistake?

Archive · 2005 6 old posts

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

unkargherth ·

Can somebody tell me why this code outpus a continuous zero, while it shouldn't ?

polyin i; polyout o; float c[4]; float z[4]; float n; n=0;o=0; c[0]=0.12;c[1]=-0.29;c[2]=0.31;c[3]=0.07;

loop(3) { z[n]=z[n+1]; o=o+(z[n]*c[n]); n=n+1; } z[3]=i; o=o+z[3]*c[3];

I checked it a hundred times. Input is a Sine wave. In theory this is a mini convolution. but it always ouputs a zero. if i forget the loop and the arrays and use float vars, it works flawlessly

It's a bug or is my mistake?

jorge ·

I think your variable "n" goes as follows:

1st sample: n=0 2nd sample: n=1 3rd sample: n=2 4th sample: n=3 5th sample: n=4 6th sample: n=5

etc

and the array has size=4. The way the arrays are implemented in order to be user friendly and not crash is to use the last value in the array when the index is higher.

Anyway, maybe I dont understand your code and it is a bug.

I think you mean to have n=0,n=1,n=2,n=3,n=0,n=1,n=2 etc Although I didnt try it, you can probably initialize the n variable every 3rd sample with:

hop(3) { n=0; }

or another way would be to make sure n wraps around the size of the array like:

n=n-(n>3.5)&4;

also note that at the moment using arrays as variables is not very efficient ( although that will change ). The code compiled for var=array[3]; is at the moment similar to when you're indexing the array with a float variable. The "3" is treated like a float that is converted to an integer which is then used to get a value from memory for each of the SSE channel separately. The same could be done with just one instruction and like I said it will change to be efficient.

unkargherth ·

Sure n is working this way ? Note the line saying

n=0;o=0;

So, in theory, is setting n=0 and also initializing output at every sample ( note that this is the reason i didn't done float n=0;

jorge ·

unkargherth wrote: Sure n is working this way ? Note the line saying

n=0;o=0;

So, in theory, is setting n=0 and also initializing output at every sample ( note that this is the reason i didn't done float n=0;

yeah, you're right, must be a bug then. I'll try your code. I'm suspecting it could be related to the line "z[n]=z[n+1];" which would probably work if you had "var=z[n+1];z[n]=var;" but I havent tried it yet.

jorge ·

This code seems to work:

polyin i; polyout o; float c[4]; float z[4]; float n,tz1,tc,tz; n=0;o=0; c[0]=0.12;c[1]=-0.29;c[2]=0.31;c[3]=0.07;

loop(3) { tz1=z[n+1]; z[n]=tz1; tz=z[n]; tc=c[n]; o=o+(tz*tc); n=n+1; } z[3]=i; o=o+z[3]*c[3];

Which narrows down the cause of the bug quite a lot. I think the array indeces for reading ( n+1 ) and writing ( n ) are getting mixed up as they use the same internal arrayindex variable. I'll change the code to cope with it.

unkargherth ·

Lots of thanks jorge !!!! Man, you're damned fast. I lasted more to find the bug than you to find a workaround !!!!

I was thinking more ona Loop bug, but from that new POV i agrre with you that seems an array index corruption issue

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.