Re: Hardsynced squarewave and anti aliasing technics
[email protected] Mon, 31 May 2021 08:12:33 +0200
| Newsgroups | gmane.comp.audio.supercollider.user |
|---|---|
| Message-ID | <[email protected]> |
I have also struggled against this, and I think this is something we are lacking in the UGens. I have a reset square here:
https://github.com/spluta/SPSynthTools/tree/master/Maths/MathsOG/LFPulseReset <https://github.com/spluta/SPSynthTools/tree/master/Maths/MathsOG/LFPulseReset>
It is compiled for macos, but it is a basic sc ugen, so it could be compiled for any system.
There is no help file, but this should give you the vibe:
({
var reset = Trig1.ar(Impulse.ar(13), 0.005)-0.5;
[LFPulseReset.ar(73, 0, 0.5, reset), reset]
}.plot(0.5))
Sam
> On May 31, 2021, at 1:59 AM, [email protected] wrote:
>
> On Sun, May 30, 2021 at 12:51 PM <[email protected]> wrote:
>> For a couple years I've been using this approximation of a square wave that I found in some paper somewhere, can't find the paper right now, but it is basically just multiplying a sine wave by some large value, calculated to avoid extreme aliasing, and putting it through tanh distortion. Not perfect but you can go a lot higher without noticeable aliasing than with a naive approach and as a benefit supports hard sync using a phasor like James said:
>
> Oh, that is a very neat trick!
>
> tanh is basically a softer form of clipping.
>
> Multiplying by a large number and clipping is a way to simulate a
> signal comparator: (a > 0) approx == (a * 10e34).clip(0, 1) -- there's
> a very small range of numbers just above zero where this is not true,
> but, close enough for most signal processing.
>
> My approach used a signal comparator (effectively the same as
> multiplying by a large number and clipping) -- so this just softens
> the clipping. Nice.
>
> Variable pulse width would just be a matter of offsetting the
> sinewave, wouldn't it?
>
> (
> a = {
> var freq = MouseX.kr(200, 4000, 1);
> var syncFreq = MouseY.kr(50, 800, 1);
> var syncSig = SinOsc.ar(syncFreq);
> var phase = Phasor.ar(syncSig, freq * SampleDur.ir, 0, 1) * 2pi;
> var k = 12000 * (SampleRate.ir/44100) / (freq * log10(freq));
> var width = SinOsc.kr(0.1).range(0, 1); // width is usually 0 - 1
> var sinSig = SinOsc.ar(0, phase) - (width * 2 - 1);
> var sqSig = tanh(sinSig * k);
>
> sqSig = LeakDC.ar(sqSig);
>
> (sqSig * 0.05).dup
> }.play;
> )
>
> hjh
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/