Main Archive Specials Wiki | FAQ Links Submit Forum


(Allmost) Ready-to-use oscillators

Type : waveform generation
References : Ross Bencina, Olli Niemitalo, ...

Notes :
Ross Bencina: original source code poster
Olli Niemitalo: UpdateWithCubicInterpolation


Code :
//this code is meant as an EXAMPLE

//uncomment if you need an FM oscillator
//define FM_OSCILLATOR

/*
members are:

float phase;
int TableSize;
float sampleRate;

float *table, dtable0, dtable1, dtable2, dtable3;

->these should be filled as folows... (remember to wrap around!!!)
table[i] = the wave-shape
dtable0[i] = table[i+1] - table[i];
dtable1[i] = (3.f*(table[i]-table[i+1])-table[i-1]+table[i+2])/2.f
dtable2[i] = 2.f*table[i+1]+table[i-1]-(5.f*table[i]+table[i+2])/2.f
dtable3[i] = (table[i+1]-table[i-1])/2.f
*/

float Oscillator::UpdateWithoutInterpolation(float frequency)
{
int i = (int) phase;

phase += (sampleRate/(float TableSize)/frequency;

if(phase >= (float)TableSize)
phase -= (float)TableSize;

#ifdef FM_OSCILLATOR
if(phase < 0.f)
phase += (float)TableSize;
#endif

return table[i] ;
}

float Oscillator::UpdateWithLinearInterpolation(float frequency)
{
int i = (int) phase;
float alpha = phase - (float) i;

phase += (sampleRate/(float)TableSize)/frequency;

if(phase >= (float)TableSize)
phase -= (float)TableSize;

#ifdef FM_OSCILLATOR
if(phase < 0.f)
phase += (float)TableSize;
#endif

/*
dtable0[i] = table[i+1] - table[i]; //remember to wrap around!!!
*/

return table[i] + dtable0[i]*alpha;
}

float Oscillator::UpdateWithCubicInterpolation( float frequency )
{
int i = (int) phase;
float alpha = phase - (float) i;

phase += (sampleRate/(float)TableSize)/frequency;

if(phase >= (float)TableSize)
phase -= (float)TableSize;

#ifdef FM_OSCILLATOR
if(phase < 0.f)
phase += (float)TableSize;
#endif

/* //remember to wrap around!!!
dtable1[i] = (3.f*(table[i]-table[i+1])-table[i-1]+table[i+2])/2.f
dtable2[i] = 2.f*table[i+1]+table[i-1]-(5.f*table[i]+table[i+2])/2.f
dtable3[i] = (table[i+1]-table[i-1])/2.f
*/

return ((dtable1[i]*alpha + dtable2[i])*alpha + dtable3[i])*alpha+table[i];
}



Comments


Added on : 14/07/10 by kathygray[ AT ]mail333[ DOT ]com
Comment :
Some time before, I really needed to buy a good house for my business but I didn't earn enough cash and couldn't buy anything. Thank God my mother suggested to take the <a href="http://bestfinance-blog.com/topics/home-loans">home loans</a> at trustworthy bank. Thence, I acted so and was satisfied with my secured loan.



Added on : 15/10/17 by anthonyemail[ AT ]antonmotolko[ DOT ]com
Comment :
Èñëåäîâàòåëüñêàÿ îïåðàöèÿ â îáëàñòè êðóøåíèÿ ñàìîëåòà Òó-154 îêîëî Ñî÷è èäåò äùî ñèõ ïîð[url=http://tvto.ru/].[/url] Íà÷èíàÿ ñî âòîðíèêà â íåé çàäåéñòâîâàíî 45 êîðàáëåé è ñóäîâ, 15 ãëóáîêîâîäíûõ àïïàðàòîâ, 192 âîäîëàçà, 12 ñàìîëåòîâ è ïÿòü âåðòîëåòîâ. Õî÷åòñÿ óçíàòü â ÷åì æå íà ñàìîì äåëå ïðè÷èíà ïàäåíèÿ???



Added on : 03/11/17 by michaelale[ AT ]antonmotolko[ DOT ]com
Comment :
íà äàííîì  áëîãå [url=http://vmracer.ru/]http://vmracer.ru/[/url] ìîæíî ïîñìîòðåòü îãðîìíûé âûáîð èíòåðåñíûõ ñòàòåé î ìîäå.



Added on : 06/11/17 by jessietar[ AT ]antonmotolko[ DOT ]com
Comment :
ó íàñ íà    áëîãå [url=http://jtayl.org/]http://jtayl.org/[/url] ñîáðàí îãðîìíûé âûáîð óíèêàëüíûõ íîâîñòåé î ñòðîéìàòåðèàëàõ.



Added on : 08/11/17 by clarochka[ AT ]antonmotolko[ DOT ]com
Comment :
Ðîê-ãðóïïà Linkin Park îòìåíèëà ñâîé ñåâåðîàìåðèêàíñêèé êîíöåðòíûé òóð ïîñëå êîí÷èíû âîêàëèñòà ×åñòåðà Áåííèíãòîíà. Îá ýòîì ãîâîðèòñÿ â îáíàðîäîâàííîì â ïÿòíèöó çàÿâëåíèè êîìïàíèè Live Nation, çàíèìàþùåéñÿ îðãàíèçàöèåé âûñòóïëåíèé[url=http://arbat-info.ru/].[/url]
æàëêî ×åñòåðà. ëèíêè áûëè ìîåé ëþáèìîé ãðóïïîé




Added on : 10/11/17 by michazzz[ AT ]antonmotolko[ DOT ]com
Comment :
Îðãàíû îïåêè ãîòîâÿò ðàçðåøåíèå íà ïîñåùåíèå ìàòåðüþ äåòåé, èçúÿòûõ îðãàíàìè ñîöçàùèòû è ïîëèöèåé èç ïðèåìíîé ñåìüè â Ìîñêâå. Îá ýòîì ñîîáùèëà æóðíàëèñòàì óïîëíîìî÷åííûé ïðè ïðåçèäåíòå ÐÔ ïî ïðàâàì ðåáåíêà Àííà Êóçíåöîâà. Ïî åå äàííûì, óæå ñîáðàíà "ýêñòðåííàÿ êîìèññèÿ" ïî îáñóæäåíèþ ýòîé ñèòóàöèè[url=http://www.kruizrock.ru/].[/url]
Ñëûøàëè? Äà çà òàêîå âîîáùå ñàæàòü íàäî!




Added on : 22/11/17 by kevinhack[ AT ]antonmotolko[ DOT ]com
Comment :
ó íàñ íà îôèöèàëüíîì  ñàéòå [url=http://www.ortodar.ru/]http://www.ortodar.ru/[/url] ñîáðàí îãðîìíûé âûáîð èíòåðåñíûõ ñòàòåé ïðî çäîðîâüå.



Added on : 23/11/17 by colton[ AT ]antonmotolko[ DOT ]com
Comment :
  íà îôèöèàëüíîì  ðåñóðñå [url=http://colton.ru/]http://colton.ru/[/url] ñîáðàí îãðîìíûé âûáîð   íîâîñòåé î ñòðîèòåëüñòâå.



Added on : 05/12/17 by harryart[ AT ]antonmotolko[ DOT ]com
Comment :
ó íàñ íà âûøåïðèâåäåííîì âåá-ïîðòàëå [url=http://artcrow.net/]http://artcrow.net/[/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