From the original SynthMaker forum (2004–2014), with its members’ names and dates.
vr760 ·
Hello, I am a new member and I am an Italian boy, so I apologize if you do not speak English well.
I write about prevents this forum to ask for help to create a square wave oscillator with the code SinthMaker.
When I wrote the following code:
Streamin frequency;
Streamin Gain;
Streamout out;
float a,b;
/ / First reverse wave saw
a = a + (freq * -1);
a = a + (a <-1) & 2;
/ / Second Wave saw no reverse
b = b + freq;
b = b - (b> 1) & 2;
out = Gain * (a+b);
I created a reverse of the other 2 saw waves but I think the latter is to be phased differently from the otherwise not hear anything.
They are on the right track or am I all wrong?
How's the complete code to place the timing of the wave right?
Thanks to all ....
trogluddite ·
Welcome to the forum,
Your code is very close - you just need to shift the phase of the second saw by 180deg.
The easiest way, is simply to offset the saw wave, then remove the offset in the final calculation.
Here's the modified code...
streamin frequency;
streamin Gain;
streamout out;
float a,b;
// First reverse wave saw
a = a + (frequency * -1);
a = a + (a <-1) & 2;
// Second Wave saw no reverse
b = b + frequency;
b = b - (b> 0) & 2; //Reset the wave half a cycle early
out = Gain * (a+b+1); //Add one to remove the DC offset
vr760 ·
I had gone close to perfect .... but I did not know how to do the last step .... are still inexperienced.
Thank you for your time. Hello.
vr760 ·
Excuse me, I wanted to implement the oscillator with an input to create a vibrato LFO .... How should I write the code?
infuzion ·
LFO = OSC with a very very low frequency
vr760 ·
Yes, if all 'input phase of an oscillator put a vibrato LFO get if I am correct??
I would like to implement the code above to post an LFO ....
vr760 ·
Let me explain .... How can I create a vibrato?
trogluddite ·
There is no need to create an extra input - you can put the LFO straight into your existing 'frequency' input. SM automatically adds together the numbers if you put many links into the same input.
vr760 ·
I tried but I'm not connecting the vibrato LFO frequency of
vr760 ·
Basically I want to get the same effect that I would get by entering the phase of an oscillator, LFO
tinkergnome ·
i'm only wondering what other different type of oscillator i could code .... i put that code into a widget
... and its like a perfect SQR wave almost...... i mixed some things into it and made a dubious sound
mangler. oh what fun!! i spawned a few different variations of that schematic that included the SQR
coded oscillator. man, if i could render that as a functional VSTi,... that would be sweet!!
trogluddite ·
tinkergnome wrote: i'm only wondering
tinkergnome wrote: made a dubious sound mangler.
tinkergnome wrote: fun!! i spawned a few different variations
That's the spirit!
Here on the forum it is great for getting specific questions answered - but the key to really learning SM is lot's of mad experiments.
The learning curve for SM is most steep at the beginning - lots of new concepts. But if you keep your inquisitive attitude, you will be making "functioning VSTs" sooner than you think.
tinkergnome ·
well you know trogluddite? .... i could post a few audio captures on sound cloud or something?
if you'd like to hear some examples? it might take a few minutes or so to post 4 short clips.
infuzion ·
tinkergnome wrote: well you know trogluddite? .... i could post a few audio captures on sound cloud or something?
if you'd like to hear some examples? it might take a few minutes or so to post 4 short clips.
Either that or just upload the MP3 to the forum. A ref to the OSM or formula used would be a neat lesson...
tinkergnome ·
ok .. this patch may not be the most advanced synth internals you'll ever see. its a work
in progress most definitely. i fleshed this out this *.osm quickly in response to the post
i saw regarding a coded SQR wave oscillator. i couldn't help but think i could seriously do
something with it for the type of experimental synth idea. my experience with max/msp
has given me an understanding of some common wiring/connection technique,.... though
i realize synthmaker is different. when you load the patch initially, playing a few of the
keys to hear it may seem a bit in need to hear more. try to keep the slider adjustments low
as the higher the adjustment is made the more further chaotic the tonic result would be.
its a type of industrial noise generator,..... perhaps i could specialize in that.
tip: keeping 1 of the sliders high in value & the other 2 sliders low in value could result in
some interesting tones played,..... like it or hate it, i guess i should do some other variations
just to flesh out more possibilities.
tinkergnome ·
when inspecting the coded window..... i realized that variables could be set to
further alter the code within. i had no idea it could be so simple. it boggles the
mind to imagine greater heights of what can become of a coded oscillator. hmm...
if only i could have a compendium of every conceivable oscillator known,.... that
would be sweet. then again, ... i could always experiment though, i don't really
know what a coded sawtooth,triangle,ramp or sine may look like.
rl ·
sorry for nitpicking, but this is not a square wave (it's still a saw, check with Analyzer or a scope window).
THIS is a square wave:
streamin frequency;
streamin Gain;
streamout out;
float a,b;
stage(0) {
b=1; // RL: both saws need to start at opposite phase
}
a = a - frequency;
a = a + (a < -1) & 2;
b = b + frequency;
b = b - (b > 1) & 2;
out = Gain * (a + b); // RL: the former multiplication with 0.0054 makes effect of b marginal
tinkergnome ·
hey ... thanks rl for providing some insight..... i can need all the help i can find.
cyto ·
tinkergnome wrote: i don't really know what a coded sawtooth,triangle,ramp or sine may look like.
You're 95% there for saw, ramp, and sine...
streamin frequency;
streamin Gain;
streamout square; //!!! |
streamout saw; //!!! scroll down
streamout ramp; //!!! |
streamout sine; //!!! V
float a,b;
stage(0) {
b=1; // RL: both saws need to start at opposite phase
}
a = a - frequency;
a = a + (a < -1) & 2;
b = b + frequency;
b = b - (b > 1) & 2;
square = Gain * (a + b); // RL
saw = Gain * a; //!!!
ramp = Gain * b; //!!!
sine = Gain * sin1(a); //!!!
...and to clarify RL's response, multiplication (and division) always takes precedence over addition (and subtraction) within expressions: so your .0054 value was only multiplying the b value. If you wanted it to multiply the sum of a+b (for some reason), you would need to enclose them in parentheses...(a+b)*.0054
-cyto
tinkergnome ·
to cyto.... thanks a million. much appreciated buddy. it's always a good thing to see what
a coded multi-oscillator looks like,.... interesting indeed !
cyto ·
tinkergnome wrote: to cyto.... thanks a million. much appreciated buddy. it's always a good thing to see what
a coded multi-oscillator looks like,.... interesting indeed !
No problem. I'd be remiss, though, if I didn't qualify things by saying that you need to be careful using such "ideal" functions as audio oscillators. You'll inevitably run into aliasing issues particularly with the square, ramp, saw, and triangle waveforms. When using any waveform that creates "infinite" harmonics, it's really best practice to use some form of bandlimiting. Having said that, the following should round out your collection...
-cyto
ps. notice I fixed an earlier mistake in the sine function.
tinkergnome ·
thanks again cyto.....
i'll take a look @ that coded multi-oscillator. it seems really simple of an equation,... tho that's fine.
i wonder if it could work well with a regular prefab'd oscillator ???? (a one that is already built that you cannot
move inside to see its inner workings).....
infuzion ·
tinkergnome wrote: it seems really simple of an equation,... tho that's fine.
i wonder if it could work well with a regular prefab'd oscillator ????
Only for LFOs; search "oscillator aliasing"
Neptune ·
Thanks for these oscs. They could really be added to the SM wiki.
Can someone please add phase to this code.
I tried it myself but all my attemps to add phase -1/+1 let the oscs become unipolar 😠
MikeG ·
Neptune wrote: Can someone please add phase to this code.
I tried it myself but all my attemps to add phase -1/+1 let the oscs become unipolar 😠
I'm still learning, but shouldn't it be like sine = Gain*sin1(a*.5+(Phase*2*Pi);
It seems you placed the sum outside the Sin()-function which just gives you DC offset.
Also notice that a full cycle is 2*Pi (or it should be) instead of 1. SM uses radians, right?
EDIT: Of course you need to add streamin Phase; to the code 😀
cyto ·
MikeG wrote: I'm still learning, but shouldn't it be like sine = Gain*sin1(a*.5+(Phase*2*Pi) [...] SM uses radians, right?
Actually, SM uses a "sin1" function that scales the circumference to 1 instead of 2pi (or 360deg.) You are correct about the implementation, though, except that it should be... sine=Gain*sin1(a*.5+Phase);
That will work for the sine wave, but for the other ones, you'll need to add some extra conditionals. When I have time later, I'll try to post a more universal solution.
-cyto
Wrote something here? To have a post removed or your name hidden, write to [email protected].