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.

FTable[256] := 1;<br />

end;<br />

exponent:<br />

begin<br />

// symetric exponent similar to triangle<br />

for i:=0 to 127 do<br />

begin<br />

FTable[i] := 2 * ((exp(i/128) - 1) / (exp(1) - 1)) - 1 ;<br />

FTable[i+128] := 2 * ((exp((128-i)/128) - 1) / (exp(1) - 1)) - 1 ;<br />

end;<br />

FTable[256] := -1;<br />

end;<br />

end;<br />

end;<br />

function TPaLfo.WaveformName:String;<br />

begin<br />

result:=WFStrings[Ord(Fwaveform)];<br />

end;<br />

function TPaLfo.Tick: Single;<br />

var<br />

i:integer;<br />

frac:Single;<br />

begin<br />

// the 8 MSB are the index in the table in the range 0-255<br />

i := Pinteger(Fphase)^ shr 24;<br />

// and the 24 LSB are the fractionnal part<br />

frac := (PInteger(Fphase)^ and $00FFFFFF) * k1Div24lowerBits;<br />

// increment the phase for the next tick<br />

Fphase :=FPhase + Finc; // the phase overflows itself<br />

Result:= Ftable[i]*(1-frac) + Ftable[i+1]* frac; // linear interpolation<br />

end;<br />

end.<br />

from : thaddy@thaddy.com<br />

comment : Oops,<br />

This one is correct:<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:dword;<br />

FRate: Single;<br />

FSampleRate: Single;<br />

FWaveForm: TWaveForm;<br />

procedure SetRate(const Value: Single);

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

Saved successfully!

Ooh no, something went wrong!