17.01.2013 Views

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

another LFO class (click this to go back to the index)<br />

References : Posted by mdsp<br />

Linked file : LFO.zip<br />

Notes :<br />

This LFO uses an unsigned 32-bit phase and increment whose 8 Most Significant Bits adress a Look-up table while the 24 Least Significant Bits are<br />

used as the fractionnal part.<br />

Note: As the phase overflow automatically, the index is always in the range 0-255.<br />

It performs linear interpolation, but it is easy to add other types of interpolation.<br />

Don't know how good it could be as an oscillator, but I found it good enough for a LFO.<br />

BTW there is also different kind of waveforms.<br />

Modifications:<br />

We could use phase on 64-bit or change the proportion of bits used by the index and the fractionnal part.<br />

Comments<br />

from : aja@sonardyne.co.uk<br />

comment : This type of oscillator is know as a numerically controlled oscillator(nco) or phase accumulator sythesiser. Integrated circuits that<br />

implement it in hardware are available such as the AD7008 from Analog Devices.<br />

The frequency resolution is very high and is = (SampleRate)/32^2. So if clocked at 44.1Khz the frequency resolution would be 0.00001026Hz!<br />

As you said the output waveform can be whatever shape you choose to put in the lookup table. The phase register is already in saw tooth form.<br />

Regards,<br />

Tony<br />

from : thaddy@thaddy.com<br />

comment : It works great!<br />

Here's a Delphi version I just knocked up. Both VCL and KOL supported.<br />

<strong>code</strong>:<br />

unit PALFO;<br />

//<br />

// purpose: LUT based LFO<br />

// author: © 2004, Thaddy de Koning<br />

// Remarks: Translated from c++ <strong>source</strong>s by Remy Mueller, www.<strong>musicdsp</strong>.<strong>org</strong><br />

interface<br />

uses<br />

{$IFDEF KOL}<br />

Windows, Kol,KolMath;<br />

{$ELSE}<br />

Windows, math;<br />

{$ENDIF}<br />

const<br />

k1Div24lowerBits = 1/(1 shl 24);<br />

WFStrings:array[0..4] of string =<br />

('triangle','sinus', 'sawtooth', 'square', 'exponent');<br />

type<br />

Twaveform = (triangle, sinus, sawtooth, square, exponent);<br />

{$IFDEF KOL}<br />

PPaLfo = ^TPALfo;<br />

TPaLfo = object(TObj)<br />

{$ELSE}<br />

TPaLfo = class<br />

{$ENDIF}<br />

private<br />

FTable:array[0..256] of Single;// 1 more for linear interpolation<br />

FPhase,<br />

FInc:Single;<br />

FRate: Single;<br />

FSampleRate: Single;<br />

FWaveForm: TWaveForm;<br />

procedure SetRate(const Value: Single);<br />

procedure SetSampleRate(const Value: Single);<br />

procedure SetWaveForm(const Value: TWaveForm);<br />

public<br />

{$IFNDEF KOL}<br />

constructor create(SampleRate:Single);virtual;<br />

{$ENDIF}<br />

// increments the phase and outputs the new LFO value.<br />

// return the new LFO value between [-1;+1]<br />

function WaveformName:String;<br />

function Tick:Single;<br />

// The rate in Hz

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!