17.01.2013 Views

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Audiable alias free waveform gen using width sine (click this to go back to the index)<br />

Type : Very simple<br />

References : Posted by joakim[DOT]dahlstrom[AT]ongame[DOT]com<br />

Notes :<br />

Warning, my english abilities is terribly limited.<br />

How ever, the other day when finally understanding what bandlimited wave creation is (i am a noobie, been doing DSP stuf on and off for a half/year) it<br />

hit me i can implement one little part in my synths. It's all about the freq (that i knew), very simple you can reduce alias (the alias that you can hear that<br />

is) extremely by keeping track of your frequence, the way i solved it is using a factor, afact = 1 - sin(f*2PI). This means you can do audiable alias free<br />

synthesis without very complex algorithms or very huge tables, even though the sound becomes kind of low-filtered.<br />

Propably something like this is mentioned b4, but incase it hasn't this is worth looking up<br />

The psuedo <strong>code</strong> describes it more.<br />

// Druttis<br />

Code :<br />

f := freq factor, 0 - 0.5 (0 to half samplingrate)<br />

afact(f) = 1 - sin(f*2PI)<br />

t := time (0 to ...)<br />

ph := phase shift (0 to 1)<br />

fm := freq mod (0 to 1)<br />

sine(t,f,ph,fm) = sin((t*f+ph)*2PI + 0.5PI*fm*afact(f))<br />

fb := feedback (0 to 1) (1 max saw)<br />

saw(t,f,ph,fm,fb) = sine(t,f,ph,fb*sine(t-1,f,ph,fm))<br />

pm := pulse mod (0 to 1) (1 max pulse)<br />

pw := pulse width (0 to 1) (1 square)<br />

pulse(t,f,ph,fm,fb,pm,pw) = saw(t,f,ph,fm,fb) - (t,f,ph+0.5*pw,fm,fb) * pm<br />

I am not completely sure about fm for saw & pulse since i cant test that atm. but it should work :) otherwise<br />

just make sure fm are 0 for saw & pulse.<br />

As you can see the saw & pulse wave are very variable.<br />

// Druttis<br />

Comments<br />

from : druttis@darkface.pp.se<br />

comment : Um, reading it I can see a big flaw...<br />

afact(f) = 1 - sin(f*2PI) is not correct!<br />

should be<br />

afact(f) = 1 - sqrt(f * 2 / sr)<br />

where sr := samplingrate<br />

f should be exceed half sr<br />

from : laurent@ohmforce.com<br />

comment :<br />

from : laurent@ohmforce.com<br />

comment : f has already be divided by sr, right ? So it should become :<br />

afact (f) = 1 - sqrt (f * 2)<br />

And i see a typo (saw f<strong>org</strong>otten in the second expression) :<br />

pulse(t,f,ph,fm,fb,pm,pw) = saw(t,f,ph,fm,fb) - saw(t,f,ph+0.5*pw,fm,fb) * pm<br />

However I haven't checked the formula.<br />

from : 909@gmx.de<br />

comment : Hi Lauent,<br />

I'm new to that DSP stuff and can't get the key to<br />

what'S the meaning of afact? - Can you explain please!? - Thanks in advice!<br />

from : druttis@chello.se<br />

comment : I've been playing around with this for some time. Expect a major update in a while, as soon as I know how to describe it :)<br />

from : druttis@chello.se

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!