(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
from : 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.

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

from : michaelale[AT]antonmotolko[DOT]com
comment : íà äàííîì áëîãå [url=http://vmracer.ru/]http://vmracer.ru/[/url] ìîæíî ïîñìîòðåòü îãðîìíûé âûáîð èíòåðåñíûõ ñòàòåé î ìîäå.

from : jessietar[AT]antonmotolko[DOT]com
comment : ó íàñ íà áëîãå [url=http://jtayl.org/]http://jtayl.org/[/url] ñîáðàí îãðîìíûé âûáîð óíèêàëüíûõ íîâîñòåé î ñòðîéìàòåðèàëàõ.

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

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

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

from : colton[AT]antonmotolko[DOT]com
comment : íà îôèöèàëüíîì ðåñóðñå [url=http://colton.ru/]http://colton.ru/[/url] ñîáðàí îãðîìíûé âûáîð íîâîñòåé î ñòðîèòåëüñòâå.

from : harryart[AT]antonmotolko[DOT]com
comment : ó íàñ íà âûøåïðèâåäåííîì âåá-ïîðòàëå [url=http://artcrow.net/]http://artcrow.net/[/url] ñîáðàí áîëüøîé íàáîð óíèêàëüíûõ ñòàòåé î èíòåðüåðå.