Been playing around attempting to make the fastest pitch LFO possible. This is my latest version which takes about 4/5th of a scan line. I also need it to be able to handle positive and negative "depth" so that I can use it for pitch sweeping too (set sweep direction in "depth" and a LFO speed of 0).
Can anyone improve on it? It's not a pointless challenge, I'm investigating a new project that needs 36 LFOs so they need to be FAST!
Can anyone improve on it? It's not a pointless challenge, I'm investigating a new project that needs 36 LFOs so they need to be FAST!
Code:
initLFO:
lda #$00
sta lfoPhase
lda #$F0
sta lfoDepth
lda #$00
sta lfoSpeed
sta lfoCounter
rts
;
;Phase: %00 / %01 = positve, %10 / %11 = negative
;
pitchLFO:
ldx lfoDepth
lda lfoPhase
and #%00000010
bne @down
txa ;if phase is negative, invert the depth
eor #$FF
clc
adc #$01
tax
@down: txa
bmi @a
clc
adc freqLo
sta freqLo
bcc @b
inc freqHi
@b: dec lfoCounter
beq @c
rts
@a: clc
adc freqLo
sta freqLo
bcs @b
dec freqHi
dec lfoCounter ;time to change phase?
bne @d
@c: dec lfoPhase ;yes, go backwards %00, %11, %10, %01
lda lfoSpeed ;reset counter
sta lfoCounter
@d: rts
lda #$00
sta lfoPhase
lda #$F0
sta lfoDepth
lda #$00
sta lfoSpeed
sta lfoCounter
rts
;
;Phase: %00 / %01 = positve, %10 / %11 = negative
;
pitchLFO:
ldx lfoDepth
lda lfoPhase
and #%00000010
bne @down
txa ;if phase is negative, invert the depth
eor #$FF
clc
adc #$01
tax
@down: txa
bmi @a
clc
adc freqLo
sta freqLo
bcc @b
inc freqHi
@b: dec lfoCounter
beq @c
rts
@a: clc
adc freqLo
sta freqLo
bcs @b
dec freqHi
dec lfoCounter ;time to change phase?
bne @d
@c: dec lfoPhase ;yes, go backwards %00, %11, %10, %01
lda lfoSpeed ;reset counter
sta lfoCounter
@d: rts