Fast sine wave calculation

Type : waveform generation
References : James McCartney in Computer Music Journal, also the Julius O. Smith paper
Notes :
(posted by Niels Gorisse)
If you change the frequency, the amplitude rises (pitch lower) or lowers (pitch rise) a LOT I fixed the first problem by thinking about what actually goes wrong. The answer was to recalculate the phase for that frequency and the last value, and then continue normally.
Code :
Variables:
ip = phase of the first output sample in radians
w = freq*pi / samplerate
b1 = 2.0 * cos(w)

Init:
y1=sin(ip-w)
y2=sin(ip-2*w)

Loop:
y0 = b1*y1 - y2
y2 = y1
y1 = y0

output is in y0 (y0 = sin(ip + n*freq*pi / samplerate), n= 0, 1, 2, ... I *think*)

Later note by James McCartney:
if you unroll such a loop by 3 you can even eliminate the assigns!!

y0 = b1*y1 - y2
y2 = b1*y0 - y1
y1 = b1*y2 - y0

Comments
from : kainhart[at]hotmail[DOT]com
comment : try using this to make sine waves with frequency less that 1. I did and it gives very rough half triangle-like waves. Is there any way to fix this? I want to use a sine generated for LFO so I need one that works for low frequencies.

from : asynth[AT]io[DOT]com
comment : looks like the formula has gotten munged. w = freq * twopi / samplerate

from : joi[AT]nea[DOT]ufsc[DOT]br
comment : Hey Rodrigo, great site! Learning a lot already. I was wrineondg, is there a way to make the sine wave not sound as tinny with riffwave.js? It sounds a lot cleaner in the Firefox example, and I'm guessing it's from the fact that you need to round it for riffwave? Is there any way to get around that?

from : la[DOT]cantina[AT]vp[DOT]pl
comment : Kewl you should come up with that. <a href="http://mwxhfr.com">Exetnlelc!</a>

from : jennifergreen[AT]fairpoint[DOT]net
comment : hi can we do a link exchange? i know that this is too much to ask but i'm hnivag trouble right now marketing my blog so I'm expanding my presence by doing link exchanges. I already added you in my blogroll so If you have the time you can check it out. My blog's a tech blog now shifting with anime and gaming. I hope you do have a time putting me in your sidebarthanks a lot!!kyle http://ncrlwgutn.com [url=http://xezivf.com]xezivf[/url] [link=http://oefkjqltn.com]oefkjqltn[/link]

from : dcrock323[AT]gmail[DOT]com
comment : hello, do you mind doing a blog link exchange? my blog is about news of <a href="http://tkvflrtx.com">firuges</a> with mostly about PVC's. I already put your link in my blog, and hoping that I could be in your blog list too, thanks

from : trinakhol[AT]yahoo[DOT]com
comment : Hi in England.. I'm from Liverpool been here in the U.S. forever thugoh. I went back home in 2009 and stayed with relatives in Leamington Spa and enjoyed every minute. I love Tiff & company they make me laugh, you make me laugh. I left a messaage on one of your amazon discussion pages. Glad I found your series, I'm now playing catch up and having fun reading about Tiff crawling through the prickly bush. http://htysfsodpj.com [url=http://mdaxssosf.com]mdaxssosf[/url] [link=http://rgvixai.com]rgvixai[/link]

from : 005fbff9n[AT]hotmail[DOT]com
comment : Common insurance Quotes Chimp are run and created by customers of policy contract. Unlike an inventory firm, where purchasing an insurance plan provides the possessor no-interest in the insurance firm it self, the action of investing in an insurance policy from a shared firm makes the buyer a balanced person who owns such corporation. Officially, customers possess the corporation but use small handle over mgmt.

from : buddyray[AT]bestemail[DOT]stream
comment : wh0cd364789 [url=http://levitraprice.us.com/]levitra at lowest cost[/url] [url=http://buyarimidex.us.org/]Arimidex By Mail Order[/url] [url=http://buyampicillin.us.org/]Ampicillin Quick Shipment[/url]

from : rpedson[AT]rainmail[DOT]top
comment : [url=https://loansforbadcredit.us.com/]payday loans for bad credit[/url]

from : gwalker[AT]bestemail[DOT]stream
comment : [url=http://forum.al-consulting.com/profile.php?id=71391]cialis over the counter[/url] [url=http://tzxzlw.com/bbs/home.php?mod=space&uid=713668]cialis 5mg[/url] [url=http://nongyexinxi.net/home.php?mod=space&uid=105476]buy cialis online[/url]

from : jwhutch[AT]jaggernautemail[DOT]win
comment : [url=http://www.zsbbbs.com/home.php?mod=space&uid=82936]cialis from canada[/url]

from : roni377[AT]snailmail[DOT]men
comment : [url=http://www.lifescienceinvestments.com/forum/memberlist.php?mode=viewprofile&u=1984]buy cialis online[/url] [url=http://www.jmxiaoxue.com/home.php?mod=space&uid=17943]cialis online[/url] [url=http://hangangcompany.com/bbs/home.php?mod=space&uid=56045]buy cialis online[/url] [url=http://xjgkyy.net/discuz/home.php?mod=space&uid=111351]buy cialis online[/url] [url=http://www.zzpenqifang.com/home.php?mod=space&uid=101306]more help[/url]

from : littleblueclaw[AT]sgdfhghtj5[DOT]live
comment : [url=http://kamagra.fund/]kamagra jelly usa[/url]

from : davisrg[AT]hostnow[DOT]men
comment : [url=http://buyclindamycin.shop/]buy clindamycin[/url] [url=http://genericvaltrex.pro/]purchase valtrex online[/url] [url=http://tadalis-sx.store/]tadalis sx without prescription[/url] [url=http://buy-amoxicillin.reisen/]prescription amoxicillin[/url]

from : jboghosian[AT]mypop3[DOT]win
comment : [url=http://viagraprice.shop/]generic viagra price comparison[/url] [url=http://genericvaltrex.pro/]valtrex[/url] [url=http://furosemide20mg.pro/]furosemide 20 mg[/url] [url=http://elimite.store/]elimite[/url]

from : jamesnew4066[AT]simply-email[DOT]bid
comment : [url=http://atarax.directory/]atarax[/url] [url=http://buy-propecia.reisen/]rogaine propecia[/url] [url=http://buy-celebrex.store/]celebrex from canada[/url]

from : mattie[AT]emailme[DOT]win
comment : [url=http://azithromycin.fail/]azithromycin[/url] [url=http://genericcialis.work/]cialis[/url] [url=http://buy-cymbalta.store/]home page[/url] [url=http://colchicine.mba/]colchicine drug[/url]

from : sloanzone5[AT]freechatemails[DOT]bid
comment : [url=http://phenergandm.pro/]phenergan without a prescription[/url] [url=http://zetia.fund/]zetia tab 10mg[/url] [url=http://buy-rimonabant.shop/]acomplia rimonabant[/url]

from : vonreis[AT]free-chat-emails[DOT]bid
comment : [url=http://retina.fund/]tretinoin 0.025 cream[/url] [url=http://azithromycin.systems/]azithromycin online[/url] [url=http://buypaxil.shop/]buy paxil online[/url] [url=http://buyindocin.shop/]indocin[/url]

from : job6551[AT]freewebpages[DOT]top
comment : [url=http://buydiclofenac.shop/]diclofenac gel[/url]

from : stephine[AT]simplemailserver[DOT]bid
comment : [url=http://clonidine.zone/]clonidine[/url] [url=http://plavixgeneric.pro/]plavix generic[/url] [url=http://wellbutrinsr.pro/]wellbutrin[/url]

from : toi[AT]securesmtp[DOT]download
comment : [url=http://tadacip.live/]tadacip 20 mg[/url] [url=http://buyviagrasoft.reisen/]soft tabs viagra[/url] [url=http://doxycycline.shop/]doxycycline hyc 100mg[/url] [url=http://albuterol.reisen/]where can i buy albuterol[/url]

from : adele[AT]mail-server[DOT]bid
comment : [url=http://allopurinol.reisen/]allopurinol[/url] [url=http://priceoflevitra.pro/]levitra[/url] [url=http://buyaugmentin.reisen/]purchase augmentin[/url] [url=http://buy-vardenafil.work/]vardenafil 20 mg[/url]

from : standard655[AT]bqhost[DOT]top
comment : [url=http://atarax.directory/]atarax[/url] [url=http://hydrochlorothiazide25mg.pro/]hydrochlorothiazide 25mg tablets[/url] [url=http://buy-cephalexin.work/]cephalexin[/url] [url=http://buybuspar.reisen/]our site[/url]

from : tonyobrien1972[AT]wwwemail[DOT]bid
comment : [url=http://buy-fluoxetine.work/]fluoxetine 10 mg[/url] [url=http://allopurinol.reisen/]allopurinol[/url] [url=http://buy-rimonabant.shop/]rimonabant[/url] [url=http://sildalisonline.pro/]generic sildalis[/url]

from : alexanderlaschinski[AT]livemail[DOT]stream
comment : [url=http://citalopram20mg.pro/]citalopram[/url] [url=http://cephalexin.mba/]keflex 250 mg[/url] [url=http://buy-amoxicillin.reisen/]buy amoxicillin[/url] [url=http://antabuse.schule/]antabuse[/url]

from : bleplast[AT]rainmail[DOT]top
comment : [url=https://onlineloans.us.com/]payday loans online[/url] [url=https://essayonline.us.com/]buy essay online[/url]

from : jackiebligh[AT]youripost[DOT]download
comment : [url=http://s13.zifboards.com/RSM_CUSTOMER_SERVICE/index.php?showuser=157516]cialis prescription[/url] [url=http://bbs.zh51home.com/home.php?mod=space&uid=209514]buy cialis online[/url] [url=http://hljouts.com/home.php?mod=space&uid=778978]Cialis From Canada[/url] [url=http://www.hualiangyuan.com/home.php?mod=space&uid=22438]cialis from canada[/url]

from : svimmeltor[AT]youripost[DOT]download
comment : [url=http://www.aumation.com/powerretail/home.php?mod=space&uid=24912]generic cialis from canada[/url] [url=http://www.bp002.com/home.php?mod=space&uid=1497]buy cialis online[/url] [url=http://bbs.manmanqi.com/home.php?mod=space&uid=176646]buy cialis online[/url] [url=http://www.dna-review.com/member/1845-kennethpax]buy cialis online[/url] [url=http://geek.topics.my/profile.php?id=111306]generic viagra cialis[/url]

from : jocapet[AT]rainmail[DOT]top
comment : [url=https://paydayloans.us.org/]online payday loans direct lenders[/url]

from : briandavies1945[AT]sgdfhghtj5[DOT]reisen
comment : [url=http://viagra247.us.com/]Generic Viagra Online[/url] [url=http://fluoxetine20mg.us.org/]buy fluoxetine[/url]

from : cecile[AT]evropost[DOT]top
comment : [url=https://paydayloans.us.org/]payday loans[/url]

from : raven9283[AT]mypop3[DOT]win
comment : [url=http://fluoxetine20mg.us.org/]fluoxetine 20 mg[/url] [url=http://bupropionsr150mg.us.org/]Bupropion SR 150 Mg[/url]

from : kpoloman[AT]regiopost[DOT]top
comment : [url=https://paydayloans.us.org/]More Bonuses[/url]

from : kyuchan[AT]mailmonster[DOT]stream
comment : [url=http://trazodone247.us.com/]trazodone 100mg[/url] [url=http://cheapvardenafil365.us.com/]vardenafil tablets 20 mg[/url]