Main Archive Specials Wiki | FAQ Links Submit Forum


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


Added on : 22/04/03 by 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.



Added on : 24/10/06 by asynth[ AT ]io[ DOT ]com
Comment :
looks like the formula has gotten munged.
w = freq * twopi / samplerate




Added on : 28/08/13 by 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?



Added on : 29/08/13 by la[ DOT ]cantina[ AT ]vp[ DOT ]pl
Comment :
Kewl you should come up with that. <a href="http://mwxhfr.com">Exetnlelc!</a>



Added on : 29/08/13 by 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]



Added on : 30/08/13 by 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



Added on : 07/09/13 by 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]



Added on : 03/03/14 by 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.




Added on : 25/06/17 by 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]



Added on : 10/09/17 by rpedson[ AT ]rainmail[ DOT ]top
Comment :
[url=https://loansforbadcredit.us.com/]payday loans for bad credit[/url]



Added on : 13/09/17 by 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]



Added on : 13/09/17 by jwhutch[ AT ]jaggernautemail[ DOT ]win
Comment :
[url=http://www.zsbbbs.com/home.php?mod=space&uid=82936]cialis from canada[/url]



Added on : 13/09/17 by 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]



Added on : 13/09/17 by littleblueclaw[ AT ]sgdfhghtj5[ DOT ]live
Comment :
[url=http://kamagra.fund/]kamagra jelly usa[/url]



Added on : 13/09/17 by 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]



Added on : 13/09/17 by 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]



Added on : 13/09/17 by 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]



Added on : 13/09/17 by 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]



Added on : 13/09/17 by 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]



Added on : 14/09/17 by 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]



Added on : 14/09/17 by job6551[ AT ]freewebpages[ DOT ]top
Comment :
[url=http://buydiclofenac.shop/]diclofenac gel[/url]



Added on : 14/09/17 by 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]



Added on : 14/09/17 by 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]



Added on : 14/09/17 by 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]



Added on : 14/09/17 by 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]



Added on : 14/09/17 by 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]



Added on : 14/09/17 by 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]



Added on : 14/09/17 by bleplast[ AT ]rainmail[ DOT ]top
Comment :
[url=https://onlineloans.us.com/]payday loans online[/url] [url=https://essayonline.us.com/]buy essay online[/url]



Added on : 15/09/17 by 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]



Added on : 15/09/17 by 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]



Added on : 16/09/17 by jocapet[ AT ]rainmail[ DOT ]top
Comment :
[url=https://paydayloans.us.org/]online payday loans direct lenders[/url]



Added on : 17/09/17 by briandavies1945[ AT ]sgdfhghtj5[ DOT ]reisen
Comment :
[url=http://viagra247.us.com/]Generic Viagra Online[/url] [url=http://fluoxetine20mg.us.org/]buy fluoxetine[/url]



Added on : 17/09/17 by cecile[ AT ]evropost[ DOT ]top
Comment :
[url=https://paydayloans.us.org/]payday loans[/url]



Added on : 17/09/17 by 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]



Added on : 18/09/17 by kpoloman[ AT ]regiopost[ DOT ]top
Comment :
[url=https://paydayloans.us.org/]More Bonuses[/url]



Added on : 19/09/17 by kyuchan[ AT ]mailmonster[ DOT ]stream
Comment :
[url=http://trazodone247.us.com/]trazodone 100mg[/url] [url=http://cheapvardenafil365.us.com/]vardenafil tablets 20 mg[/url]



Added on : 20/09/17 by mkoren0306[ AT ]yourfreemail[ DOT ]stream
Comment :
[url=http://doxycyclineprice.us.org/]doxycycline price[/url]



Added on : 21/09/17 by desilaloo[ AT ]freewebpages[ DOT ]stream
Comment :
[url=http://colchicine247.us.com/]buy colchicine[/url] [url=http://erythromycin500mg.us.org/]erythromycin online[/url] [url=http://doxycycline100mg.us.org/]Doxycycline 100 Mg[/url]



Add your own comment
Comments are displayed in fixed width, no HTML code allowed!
Email:

Comment:

Are you human?



Site created and maintained by Bram
Graphic design by line.out | Server sponsered by fxpansion