Page 1 of 2

Sin Osc (for curiosity)

PostPosted: Thu Jul 28, 2022 3:26 pm
by Tepeix
Here's a sin osc.
But it's more for curiosity.
I recommend to use the Martin Vicaneck sin osc that is a little faster.

Also my phase system would probably make little problem ??
(need at least a dezip if controlled manually)

Optionally, we could have a little 3x harmonic.
I tried to shut down the aliasing, but i'm not sure i found the perfect value.

I liked the concept to use less variables, only 2, to convert a triangle in a sin approximation.
But this take more calculation..

Here's the formula :
X is Trig (0-1) >
X1 = X*X
X2 = 1-((1-X)*(1-X))
z = ( (X2-X1)* X) + X1
zz = ( (z-X)* 0.282425) + X
result = ( (X2-X1)* zz) + X1

(I also find that a triangle derivative multiplied by the frequency, then again derivative * freq make almost a sin..
But this lead to DC problematic that are more hard to deal..)

Re: Sin Osc (for curiosity)

PostPosted: Thu Jul 28, 2022 10:07 pm
by adamszabo
interesting, however the sine wave you produce is unipolar (goes between 0 and 1), a normal sine should be bipolar (-1 to 1) ;)

Re: Sin Osc (for curiosity)

PostPosted: Fri Jul 29, 2022 7:47 pm
by Tepeix
Yes, in fact it's like a (sin1(x) / 2) +0.5
But it only work for input value from 0 to 1.)

Re: Sin Osc (for curiosity)

PostPosted: Sat Jul 30, 2022 1:17 pm
by Tepeix
I was wrong with the derivative idea..

Seeing a derivative of a derivative of a triangle, i was thinking it's close to a sin.
To fight the DC that make a derivative, i find the "triangle derivative".

That's a triangle osc that take as input another's triangle multiplied by a multiple of his frequency.

> when changing the frequency it will act badly and go out of sync.. Needing a reset.

But the real problem is that the harmonics are not completely shut down even with 3 derivarive..

When frequency output is higher than 440 hertz the aliasing become very horrible !
Maybe each triangle derivative will shut harmonic only if they are not aliasing...

Also, with some frequency, an imprecision will make the "triangle derivative" out of sync repeatably.

Very not a good way to make a sin or i miss something to fix all of this !)

Re: Sin Osc (for curiosity)

PostPosted: Sat Jul 30, 2022 2:20 pm
by Tepeix
Here's another "sin".. But it fail to shut down completely harmonics..

(I might be obsessed by sin approximation osc !)

We make a ramp that go from 0 to 1.
And a square from 1 to -1, each time the ramp reset, the square switch.
Image

Now it's "easy" to interpolate the square and almost make a sin like this:

C1 = 1-( (1-ramp)*(1-ramp))
C2 = 1-(ramp*ramp)

Result = square * C1 * C2.

But it take 4 multiply and a lot of instruction..
also it's not a prefect sin..

Re: Sin Osc (for curiosity)

PostPosted: Sun Jul 31, 2022 9:48 am
by Spogg
Interesting stuff!

In the old days of solid state analogue electronics the approach was to take a triangle wave, which was fairly easy to make, and process it with a bipolar non-linear transfer, often made using the non-linear range of forward conductance of diodes. This would be below about 0.7 volts for silicon and about 0.3 volts for germanium. This method also often appears in guitar distortion pedals and guitarists seem to argue about whether germanium or silicon diodes sound “better”. Go figure!

I’ve simulated this in the schematic using the tan(h)x module by Martin. In the analogue version there would usually be a trimmer to get the waveform with the fewest harmonics and in the oscillators I made back then I tuned it by ear, as you can with this version. Of course in the digital world aliasing can be heard at higher frequencies, even with the band-limited triangle osc by Martin. Oversampling should reduce that.

In even older gear like a Rhodes piano, the valve-based low frequency oscillator for tremolo was made using a filtered square wave passed through a similar non-linear transfer function to give a “rounded” click-free waveform. This method was used because a valve-based low frequency sine wave osc was virtually impossible to make.

You did want a history lesson I hope! :lol:

Re: Sin Osc (for curiosity)

PostPosted: Sun Jul 31, 2022 5:26 pm
by Tepeix
Thanks very interesting !

I was just trying to find some info on analog osc.
But i was not understanding anything and now it's very better !)
I need someday to go back to the basic of electricity, if i want to understand the articles on this subject.

Re: Sin Osc (for curiosity)

PostPosted: Mon Aug 01, 2022 8:39 am
by Spogg
Tepeix wrote:...I was just trying to find some info on analog osc...
...I need someday to go back to the basic of electricity, if i want to understand the articles on this subject...


It’s interesting to me that I came from the analogue world to DSP and found it hard at first, but younger folk start off with DSP then get interested in analogue processes and find that tricky to understand.

You might be interested to look inside my Quilcom ASS (Analogue Sounding Synthesiser):
viewtopic.php?f=3&t=8705&hilit=quilcom+ass

Re: Sin Osc (for curiosity)

PostPosted: Mon Aug 01, 2022 4:42 pm
by Tepeix
I will be very interested to see inside this !!)

Here's another sin osc.
I'm surprise it works not so bad.

But they are limitations..
It's not adapted to sample rate and the input is not in hertz.
(Might be possible to upgrade in this way..)

Also it only go to 600 hz. (Might also be possible to upgrade but might be probably limited)

also it's only mono due to the filter design.

So it's a very naive form.

Taking the MV superfast random noise we feed a bandpass filter.
A feedback loop re-feed the bandpass; this one need to be clipped to avoid hard rise in volume.

And we got a sin without harmonic.. But i'm not sure how it will do transition of volume or note.

Re: Sin Osc (for curiosity)

PostPosted: Wed Aug 03, 2022 3:14 pm
by Tepeix
Another sin !)

I like those research of sin.. So many possibility, so many strange math, geometry..

Maybe this one could be good for cpu, have to test it more..


Taking a triangle from -0.5 to 0.5. x

We do f1= (x+x) - (abs(x)*(x+x)).
This is a faster way to do like 1-((1-x)*(1-x)) and it works also for negative value.

Then we do f2 = f1*(abs(f1))

We now have to multiply f2 by a parameter and simply add to f1.
(note that the output volume is greater than -1 to 1. also the input might be *0.5)

Depending of the parameter we could have a sin with almost no harmonics.
But the 3X harmonic stay so at approximately 7000hz aliasing will be audible.

Finally the parameter do not so bad at 0.5.
So another optimization is to do f1+f1+f2. Avoiding a multiplication.
But the aliasing will come a little faster.