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 :
ip = phase of the first output sample in radians
w = freq*pi / samplerate
b1 = 2.0 * cos(w)


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

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="">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 [url=]xezivf[/url] [link=]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="">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. [url=]mdaxssosf[/url] [link=]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=]levitra at lowest cost[/url] [url=]Arimidex By Mail Order[/url] [url=]Ampicillin Quick Shipment[/url]

from : rpedson[AT]rainmail[DOT]top
comment : [url=]payday loans for bad credit[/url]

from : gwalker[AT]bestemail[DOT]stream
comment : [url=]cialis over the counter[/url] [url=]cialis 5mg[/url] [url=]buy cialis online[/url]

from : jwhutch[AT]jaggernautemail[DOT]win
comment : [url=]cialis from canada[/url]

from : roni377[AT]snailmail[DOT]men
comment : [url=]buy cialis online[/url] [url=]cialis online[/url] [url=]buy cialis online[/url] [url=]buy cialis online[/url] [url=]more help[/url]

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

from : davisrg[AT]hostnow[DOT]men
comment : [url=]buy clindamycin[/url] [url=]purchase valtrex online[/url] [url=]tadalis sx without prescription[/url] [url=]prescription amoxicillin[/url]

from : jboghosian[AT]mypop3[DOT]win
comment : [url=]generic viagra price comparison[/url] [url=]valtrex[/url] [url=]furosemide 20 mg[/url] [url=]elimite[/url]

from : jamesnew4066[AT]simply-email[DOT]bid
comment : [url=]atarax[/url] [url=]rogaine propecia[/url] [url=]celebrex from canada[/url]

from : mattie[AT]emailme[DOT]win
comment : [url=]azithromycin[/url] [url=]cialis[/url] [url=]home page[/url] [url=]colchicine drug[/url]

from : sloanzone5[AT]freechatemails[DOT]bid
comment : [url=]phenergan without a prescription[/url] [url=]zetia tab 10mg[/url] [url=]acomplia rimonabant[/url]

from : vonreis[AT]free-chat-emails[DOT]bid
comment : [url=]tretinoin 0.025 cream[/url] [url=]azithromycin online[/url] [url=]buy paxil online[/url] [url=]indocin[/url]

from : job6551[AT]freewebpages[DOT]top
comment : [url=]diclofenac gel[/url]

from : stephine[AT]simplemailserver[DOT]bid
comment : [url=]clonidine[/url] [url=]plavix generic[/url] [url=]wellbutrin[/url]

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

from : adele[AT]mail-server[DOT]bid
comment : [url=]allopurinol[/url] [url=]levitra[/url] [url=]purchase augmentin[/url] [url=]vardenafil 20 mg[/url]

from : standard655[AT]bqhost[DOT]top
comment : [url=]atarax[/url] [url=]hydrochlorothiazide 25mg tablets[/url] [url=]cephalexin[/url] [url=]our site[/url]

from : tonyobrien1972[AT]wwwemail[DOT]bid
comment : [url=]fluoxetine 10 mg[/url] [url=]allopurinol[/url] [url=]rimonabant[/url] [url=]generic sildalis[/url]

from : alexanderlaschinski[AT]livemail[DOT]stream
comment : [url=]citalopram[/url] [url=]keflex 250 mg[/url] [url=]buy amoxicillin[/url] [url=]antabuse[/url]

from : bleplast[AT]rainmail[DOT]top
comment : [url=]payday loans online[/url] [url=]buy essay online[/url]

from : jackiebligh[AT]youripost[DOT]download
comment : [url=]cialis prescription[/url] [url=]buy cialis online[/url] [url=]Cialis From Canada[/url] [url=]cialis from canada[/url]

from : svimmeltor[AT]youripost[DOT]download
comment : [url=]generic cialis from canada[/url] [url=]buy cialis online[/url] [url=]buy cialis online[/url] [url=]buy cialis online[/url] [url=]generic viagra cialis[/url]

from : jocapet[AT]rainmail[DOT]top
comment : [url=]online payday loans direct lenders[/url]

from : briandavies1945[AT]sgdfhghtj5[DOT]reisen
comment : [url=]Generic Viagra Online[/url] [url=]buy fluoxetine[/url]

from : cecile[AT]evropost[DOT]top
comment : [url=]payday loans[/url]

from : raven9283[AT]mypop3[DOT]win
comment : [url=]fluoxetine 20 mg[/url] [url=]Bupropion SR 150 Mg[/url]

from : kpoloman[AT]regiopost[DOT]top
comment : [url=]More Bonuses[/url]

from : kyuchan[AT]mailmonster[DOT]stream
comment : [url=]trazodone 100mg[/url] [url=]vardenafil tablets 20 mg[/url]