SynthMaker

Arrays

Archive · 2005 16 old posts

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

Nu Audio Science ·

OK so i have been reading a couple of C++ books for reference on Arrays.

I still dont understood how it can be used to make a delay ? I understand that an Array is a collection of individual pieces of data of a single type. Do you feed the audio data to the elements in the array meanwhile playing back the previous element with the current audio ? Is the numerology the same as C++ IE element 1 is referenced as element 0 ? Is an element size dynamic so that you could change its size for differing delay sizes or is this achieved differently ? How is the array referenced or does it just constantly cycle ?

Sorry if these questions are stupid but i am 😉

unkargherth ·

Nu Audio Science wrote: OK so i have been reading a couple of C++ books for reference on Arrays.

I still dont understood how it can be used to make a delay ?

An arrau will also be considered as a Buffer. That's the basic you need in a delay to store prvious inputs in order to repeat it

Nu Audio Science wrote: I understand that an Array is a collection of individual pieces of data of a single type.

Yes. in our case floats

Nu Audio Science wrote: Do you feed the audio data to the elements in the array meanwhile playing back the previous element with the current audio ?

Well . more or less. Abit complex thatn this, but yes, that's the idea

Nu Audio Science wrote: Is the numerology the same as C++ IE element 1 is referenced as element 0 ?

Yes

Nu Audio Science wrote: Is an element size dynamic so that you could change its size for differing delay sizes or is this achieved differently ?

No size is static, and must be known in build time. To get a variable size array, you should make one as bigger as you could need in worst case and then you must manually control the index for smaller sizes

Nu Audio Science wrote: How is the array referenced or does it just constantly cycle ?

No It isn't constantly cycling you can refer to any element this way for read it

float myarray[10000]; // define an array of 1000 positions, indexed from 0 to 999 float a; a= myarray[25] // set a to the value of 26th position in the array

or this one for write on it

float myarray[10000]; // define an array of 1000 positions, indexed from 0 to 999 float a; a=0.5; myarray[25]=a // set value of 26th position in the array to 0.5

Nu Audio Science wrote: Sorry if these questions are stupid but i am 😉

The only stupid question is the one that never is asked....

skOre ·

I read up on it as well, and I understood it this way:

The Array is there to take snapshots up to a specific number of samples (one sample per one fraction of an array) and to pass them on from the beginning to the end where they get dropped out after the number of stages.

Is this anywhere near to being correct?

unkargherth ·

Well, not exactly The array is there, it's work in the way it's described and can be used to anything you find is useful. not only for samples. I use it for example to store coefficients of cascaded filters, nothing to do with samples, because simplifies the management of filters

Anyway you spoted ONE of it's posible uses, I spotted ANOTHER ONE above and there's posibly a million more

An array isn't and audio buffer. An array a structure that CAN be used as audio buffer, and as 1001 other things ( stacks, lists,ect)

unkargherth ·

Sorry NAS. When replying, i forget this

If you wanna an example on using an array for a delay, look here

Nu Audio Science ·

So how do you write to it and read from it at the right time ? I suppose i mean how do you get the delay on beat ? How do you trigger the writes and reads ?

This bloody C++ book doesn't actually give you much help, Would it be better if i bought a C book ?

jorge ·

Nu Audio Science wrote: So how do you write to it and read from it at the right time ? I suppose i mean how do you get the delay on beat ? How do you trigger the writes and reads ?

This bloody C++ book doesn't actually give you much help, Would it be better if i bought a C book ?

IMO It's looking like you'll learn a lot just by asking questions here.

Nu Audio Science ·

I've honestly learnt more here than from the book but i think i need something as reference that would answer some of the smaller questions.

Nu Audio Science ·

Phew i'm glad you pointed that flanger out Unk, No more messing with arrays just yet for me, I think i better learn the syntax a lot more first, I dont understand hardly any of that 🙁

stefan ·

Nu Audio Science wrote: So how do you write to it and read from it at the right time ? I suppose i mean how do you get the delay on beat ? How do you trigger the writes and reads ?

This bloody C++ book doesn't actually give you much help, Would it be better if i bought a C book ?

Lets for this example make a delay that is 1 second long.

What you have to do then is let the "read cursor" read 1 second behind the "write cursor". In 44100Hz this would mean reading 44100 indices lower than the write cursor.

Kind of like this:

monoin input; monoout output; float array[100000]; float size = 100000; float length = 1.0; // 1 second float samplerate = 44100;

readPos = writePos - length*samplerate; writePos = writePos + 1;

// make sure readPos and writePos doesn't go outside of the array readPos = readPos + readPos < 0 & (size - 1); writePos = writePos - writePos >= size & size; array[writePos] = input; output = array[readPos];

I probably did something wrong, wrote this straight from top of my head and haven't used the arrays myself yet... 🙂

jorge ·

Nu Audio Science wrote: So how do you write to it and read from it at the right time ?

Let's say you have an array of 3 elements, your values would be: array[0],array[1],array[2] That would allow you to do a 3 samples delay as follows:

1-read array[0] and send it to output 2-store input in array[0] 3-read array[1] and send it to output 4- store input in array[1] 5-read array[2] and send it to output 6-store input in array[2]

Initially all the memory is cleared to zero so you'd start with array[0]=0,array[1]=0,array[2]=0

now as an example lets assume we have the following sound data arriving at the input: 0.1,0.2,0.3,0.4,0.5 etc now let's go through the steps like above 1- read array[0]=0 send it to output so out=0 2- store input=0.1 in array [0] so the state of the array becomes array[0]=0.1,array[1]=0,array[2]=0 3- read array[1]=0 and send it to output so out=0 4-store input=0.2 in array[1] so the state of the array becomes: array[0]=0.1,array[1]=0.2,array[2]=0 5- read array[2]=0 and send it to output so out=0 6-store input=0.3 in array[2] so the state of the array becomes: array[0]=0.1,array[1]=0.2,array[2]=0.3

now we wrap around the memory and the output will become the previous inputs with a delay of 3 samples

7- read array[0]=0.1 and send it to output so out=0.1 8-store input=0.4 in array[0] so the state of the array becomes: array[0]=0.4,array[1]=0.2,array[2]=0.3 9- read array[1]=0.2 and send it to output so out=0.2 10-store input=0.5 in array[1] so the state of the array becomes: array[0]=0.4,array[1]=0.5,array[2]=0.3

etc

basically for input=0.1,0.2,0.3,0.4,0.5... you got output=0,0,0,0.1,0.2,0.3,0.4...

I hope that wasnt too confusing, but as you can see the output represents the data that arrived 3 samples before meaning that it is delayed by 3 samples.

Basically the algorithm reads from memory, sends to output , stores the new value on top and moves the array index up to the next position wrapping around when it gets to the end.

Nu Audio Science ·

🙂 🙂 🙂

I'm not actually sure i understood any of that yet, Is one sample one element ? , So for instance 44100 elements is one second if the SR is 44100. then you wold leave an ammount of elements empty at the start of reading back to achieve the particular delay you wanted.

So if you write 44100 elements and then read 44100 elements that were empty followed by the 44100 elements that had been written to, you would have a 1 second delay with a feedback of one second.

So is the number of elements you write to proportional to the feedback and the ammount of empty elements at the beggining of reading back is proportional to the delay time ?

stefan ·

Nu Audio Science wrote: :) 🙂 🙂

I'm not actually sure i understood any of that yet, Is one sample one element ? , So for instance 44100 elements is one second if the SR is 44100. then you wold leave an ammount of elements empty at the start of reading back to achieve the particular delay you wanted.

So if you write 44100 elements and then read 44100 elements that were empty followed by the 44100 elements that had been written to, you would have a 1 second delay with a feedback of one second.

Correct, apart from semantics. Feedback is something that is an amount. What you're talking about here is the delay length, the delay feedback is something else 🙂

Nu Audio Science wrote: So is the number of elements you write to proportional to the feedback and the ammount of empty elements at the beggining of reading back is proportional to the delay time ?

Proportional to the delay length, yes 🙂

Nu Audio Science ·

cheers i understand it a little better but i dont think i'll be coding a delay for a while.

Just out of interest could arrays be used for something like Suppatrigga ?

Shifrin ·

Nu Audio Science wrote: Just out of interest could arrays be used for something like Suppatrigga ?

Yep, if you have the sample rate and BPM you can store say 1 bars worth of incoming data, then play it back in any order your wish, while at the same time storing the next bars worth of data in a second array - or something to that effect 😉

Shif.

Nu Audio Science ·

Cheers Shif I think these kiddies are gonna really be used alot in my stuff when i can get my head around em.

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.