Global CONST SizePattern = 256

CONST maxTones = 12

CONST maxSteps = 6

' iPhase and iDeltas are wprking variablds

Global iTones( maxTones) as Single ' Original values

Global iPhases(maxTones) as Single

Global iDeltas(maxTones,maxSteps) as Single 'create four steps for each base toner

Global currentDeltas(maxTones)

Global DefaultTones(1 to 12, 1 to 1)

Global ToneCount as Integer

Global pcmPattern(SizePattern) as Single

function stepsGet()

stepsGet = maxSteps

end function

Function DeltaK(tone as Single, delta as Single) as Single

Dim dt as Single

Dim dk as Single

Dim ik as Integer

Dim y as Single

dt = 1/sampleRate 'seconds per sample, global

if(opMode and AlignBit) then

dk = tone / tempo ' cydles per second/beats per second tempo global

ik = dk ' to the nearest integer

tone = ik*tempo

endif

'cycles per second * seconds/sample give cycle per sample, a fraction of the cycle

' the pattern is one cycle, so pattern size * fraction of wave give delta k

delta = tone * dt * SizePattern

DeltaK = tone ' return adjusted tone

end Function

'cycles per second * seconds/sample give cycle per sample, a fraction of the cycle

' the pattern is one cycle, so pattern size * fraction of wave give delta k

Sub SetDelta(iRow)

Dim tone as Single

Dim index as integer

Dim dk as Single

for index = 0 to maxSteps-1

tone = iTones(iRow)*PitchRatio^index

tone = DeltaK(tone,dk) ' Returns phase adjusted tone

dk = tone * SizePattern /sampleRate

iDeltas(iRow,index) = dk

iPhases(iRow) = 0

next

end sub

Sub toneSet(ledger() as variant) as Integer

Dim iRow as Integer

if ToneCount > maxTones then

msgbox("err too many tones")

else

for iRow = 0 to ToneCount-1

iTones(iRow) = ledger(iRow+1,1)

SetDelta(iRow)

Next

end if

end Sub

sub toneDef(T)

x = Array(329.63,246.95,196.00,146.84,110.01,82.41,0,0,0,0,0,0)

for i = 1 to 6

T(i,1) = x(i-1)

next

end sub

sub patternInit()

dr = 2*pi/SizePattern

dt=0

for i = 0 to SizePattern-1

pcmPattern(i) = sin(dt)

dt = dt + dr

next i

end sub

'Preset tone pattern

Sub initPattern

Dim dr as Single

Dim dt as Single

Dim i as Integer

dr = 2*pi/256

dt=0

for i = 0 to SizePattern-1

pcmPattern(i) = sin(dt) + 1

dt = dt + dr

next i

end sub

Function ValPhase(index as Integer) as Single

Dim phase as Single

Dim val as Single

Dim k as Integer

phase = iDeltas(index,1)

phase = iPhases(index)

k= Fix(phase)

val = pcmPattern(k)

phase = iPhases(index) +currentDeltas(index)

if phase >= SizePattern then phase = phase - SizePattern

iPhases(index) = phase

ValPhase = val

end Function

' not used

Function GetDelta(index as Integer,tonestep as Integer, Optional x) as Single

if index < 12 and tonestep < 5 then

GetDelta=iDeltas(index,tonestep)

else

GetDelta=0

end If

end Function

## No comments:

Post a Comment