From the original SynthMaker forum (2004–2014), with its members’ names and dates.
Neptune ·
Hi,
i have created a simple saw code based on the simple saw example shown in the Wiki.
But i am not a coder and i am struggeling even with the basics.
I have now 2 problems with the code
1.) When trying an addition of more then 8 floats the code does not longer work. Adding the 9th float breaks the code.
2.) The calculation of the simple saw is repeated 9 times. Is it possible to make the result from the 1st calculation a constant which can be used for further calculations?
Please see the attachment.
Thanks in advance!
Damian (Neptune)
DigitalWhiteByte ·
Please read User Giude at page 118/119
Section:
Code Component
Expression
One limitation of the code component is that you can only have 8 successive operations in an
expression. For example, the expression:
a = 0+1+2+3+4+5+6+7+9+10;
is not allowed because there are 9 addition operations in a row. You can easily get round this by
splitting the expression up into smaller sections using brackets ‘(‘ and ‘)’. For example:
a = (0+1+2+3+4)+(5+6+7+9+10);
Neptune ·
DigitalWhiteByte wrote: Please read User Giude at page 118/119
Section:
Code Component
Expression
Thank you for this hint. I missed that one in the guide.
I am still struggeling with the 2nd question.
I thought i can move the result into a new float. But it is not that simple as i thougt.
My idea was:
float a1,b1;
float z1;
a1 = a1 + frequency;
a1 = a1 - (a1 > 1) & 2;
z1 = a1;
b1 = z1;
But this does not work.
infuzion ·
I think so in ASM.
cyto ·
I think you need to be a little clearer about what you are trying to accomplish here. For instance, what's the point of calculating the function nine times? If you take a step back and look at your first block of code...
...each iteration is calculating the same number. It could just as easily be written...
streamin frequency;
streamin volume;
//streamin detune;
streamout out1;
streamout out2;
float a;
a = a + (frequency);
a = a - (a > 1) & 2;
out1 = volume*(a*8);
out2 = volume*a;
Are you trying to generate nine separate saw waves. In that case, you'd need to have nine different frequency incrementors. Your second block of code (if I'm understanding what you're asking) where you would take the result of one iteration and feed it into the next (nine times?) could simply be written...
streamin frequency;
streamin volume;
streamout out;
float a;
a = a + (frequency*9);
a = a - (a > 1) & 2;
out = volume*a
... since each iteration is simply adding the frequency incrementor to the "carrier" value. The result would simply be a saw wave transposed up a few octaves. I'm sure this is not the desired result. If you explain "conceptually" what you are trying to do, it might be easier to offer some advice.
-cyto
trogluddite ·
I notice in your code you have 'commented out' the line 'streamin detune'.
Is this something you have removed from the orginal code (because you don't want detuning), or something you are wanting to add? (i.e. making a detuned 'supersaw' type waveform).
If it is something removed, then cyto is correct - you only need one iteration of the code, as all of the 'a' variables are just calculating the same saw. So out1 is just the same as out2, but 8 times louder.
If the intention is to have detuning, then each iteration needs to add a slightly different amount of the 'detune' variable to the frequency, to generate 8 saws, all at slightly different frequencies, e.g....
a1=a1+(frequency + amount1 * detune);
...with different 'amount' variables for each line.
Neptune ·
Thanks again for all help.
Yes, i have removed some code before just to understand the basics.
It is a detuneable osc exactly as described by trog
Neptune ·
I think that i totally messed it up.
The osc sounds somehow nice but it is full of phasing and noise.
I have checked a lot of example-oscs which are around here on the forum but i still have no idea how to fix this phase issue (if this can be fixed at all). 😕
Btw. can someone explain to me how to compensate pitch<->volume. The lower the note, the osc becomes more silent and the other way around. How to keep the volume more or less constant?
So many question on my mind about this first try of coding... 😉
Have a nice time
Neptune
infuzion ·
Neptune wrote: Btw. can someone explain to me how to compensate pitch<->volume. The lower the note, the osc becomes more silent and the other way around. How to keep the volume more or less constant?
This will happen due to how we hear & how speakers & sound work.
Fix idea: Key Follow * Volume
cyto ·
Neptune wrote: The osc sounds somehow nice but it is full of phasing and noise.
I have checked a lot of example-oscs which are around here on the forum but i still have no idea how to fix this phase issue (if this can be fixed at all). 😕
Your phasing problems stem from the fact that your "detuners" are really frequency "shifters." Take a step back and visualize what's going on in your code: All of your "carriers" (a1,a2,a3,etc.) are starting at zero each time a voice is initiated. In order for the saw waveform to take shape, each of these carriers is incremented up by a certain value. In your case this value is the normalized frequency. This addition is perfectly sound because the normalized frequency is calculated by ((2*freq)/sample rate). So each increment is a perfectly scaled fraction equal to 2/[number of samples required to complete the waveform]. Each addition takes place at sample rate, so by the time the carrier reaches 1 it resets to -1 (a jump of 2) and starts its "climb" again. That part should be easy to visualize.
A problem is introduced, though, by your "detuning" algorithm. Your solution to simply add (or subtract) an arbitrary value to the incrementor in reality simply shifts the frequency by a fixed value. Since we perceive pitch on a 2^x scale, when multiple voices are present their harmonic relationship is completely distorted. For instance: at 44.1kH sample rate, an increment addition of .001 would shift the frequency by 44Hz. In the higher octaves (where the frequencies are in the thousands), this shift be perceived as just a slight detune of a few cents. However, in the lower frequencies (where the frequencies are in the hundreds or less), this would result in a detuning of potentially several steps. This method, therefore, results in extremely uneven detuning across the harmonic scale.
The obvious solution is to abandon the shifting (by addition) algorithm and instead use a proportional method. Instead of adding to the incrementor, multiply the normalized frequency incrementor by some factor. This will ensure that the detuning is scaled smoothly and make the code samplerate-independent. You can calculate appropriate factors by using this formula: factor=2^(x/1200) where x is the detune amount in cents (negative values work, too, in this equation).
Also, your LP and HP maths don't work as there's really no recursion going on. They seem to just convolude (not in a good way) the frequency shifting. Take them out for now and concentrate on getting a good solid waveform. Eventually, you will need to add some LP to the output to tame some of the aliasing but I wouldn't worry about that until you get the oscillator just right (too much going on in the code may make it difficult to concentrate on the important maths).
infuzion wrote: This will happen due to how we hear & how speakers & sound work.
Fix idea: Key Follow * Volume
Do a google search for "equal loudness contour" or "Fletcher–Munson" to gain some insight. My personal solution is some carefully calculated wide notch (smile) filters near the output of the schematic. I can post a generic version if you want.
-cyto
trogluddite ·
Yes, Cyto is spot on - multiplication for a detuning, addition for 'out-pf-tuning'!!!.
My apologies if my earlier post led you astray - after using SM for so long, I really have no excuse for making such a schoolboy error! 😝
Wrote something here? To have a post removed or your name hidden, write to [email protected].