Re: Hardsynced squarewave and anti aliasing technics
[email protected] Mon, 31 May 2021 07:59:37 +0800
| Newsgroups | gmane.comp.audio.supercollider.user |
|---|---|
| Message-ID | <CAFniQ7XUEm7JguY9sX0QzdMTUVhw80zN93uRvz8K=rP8-U-CzA@mail.gmail.com> |
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/