Page 1 of 1
Flanger code, starting point
Posted: Thu Oct 21, 2021 11:20 am
by gary00k
Hi everyone. I found nice flanger code at spinsemi site. I modified it to make flanger depth controlled manually. It should increase delay (make fx frequency lower) with pot increasing and it works like that. The problem is, even if pot1 is set to 0 at the beginning, flanger goes itself from low to high frequency and just then I can control it by myself. Is it possible to make it starting directly from pot value?
Code: Select all
;pot1 = flange rate
mem fladel 512
equ fladel_138 fladel+138 ;mid pointer to flange delay
equ fladel_139 fladel+139 ;mid pointer to flange delay +1
equ tri reg0 ;triangle made from ramp
equ flaout reg1 ;mixed flanger output
equ fladout reg2 ;flange delay output
equ k1 reg3 ;first coefficient for linear interpolation
equ k2 reg4 ;second coefficient for linear interpolation
equ temp reg5 ;general temp register
; Inputs control
rdax fladout, 0.6 ; get fraction of flange output
rdax adcl, 0.5 ; add inputs * 0.5 each
rdax adcr, 0.5
wra fladel, 0 ; write flange delay input, clear acc
; Flanger control
sof 0, -0.13
rdax pot0, 0.13
sof 0.00015, 0 ; scale to filter
rdax tri, 0.9999 ; filter triangle waveform so that pitch bend does not get too great at high rates
wrax tri, 0 ; write triangle wave to register, clear accumulator
; Formulate delay pointer,
or fladel_138 < 8 ; fladel^ + 138 ;get midpoint address pointer
rdax tri, 0.03125 ; add triangle wave modulation, scaled to fit delay range
wrax addr_ptr, 1 ; establish address for lower interpolation sample
; Develop fraction of tri:
and 0x0000FF ; mask off integer portion of address, leaving a fractional value in the lowest acc byte
sof -2,0 ; these operations shift the resulting fractional value to the range 0.0 to 0.999...
sof -2,0 ; only -2.0 is exact, but it changes sign of shifted value
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2, 0
sof -1, 0 ; 15 shifts
wrax k2, 0 ; write result as coefficient for second sample read
or 0x7FFFFF
rdax k2, -1
wrax k1, 0 ; write result as coefficient for first sample read
; Read from first pointer:
rmpa 1 ; read memory for first sample read
mulx k1 ; multiply by K1
wrax temp, 0 ; and store in temp, while clearing the acc
; Get second pointer:
or fladel_139 < 8 ; fladel^ + 139 ;form second pointer
rdax tri, 0.03125 ; add triangle waveform again
wrax addr_ptr, 0 ; establish address for upper interpolation sample
rmpa 1 ; read second interpolation sample
mulx k2 ; multiply by K2
rdax temp, 1 ; add temp (first value*K1)
wrax fladout, 1 ; write the result to the flanger delay output
rda fladel, 1 ; add the input to the flanger delay
wrax flaout, 0 ; write result to flaout and clear acc
rdax flaout, 1 ; add flaout
wrax dacr, 1 ; write to right output, save accumulator
wrax dacl, 0 ; write to left output, clear acc
Re: Flanger code, starting point
Posted: Thu Oct 21, 2021 7:45 pm
by frank
gary00k wrote: ↑Thu Oct 21, 2021 11:20 am
The problem is, even if pot1 is set to 0 at the beginning, flanger goes itself from low to high frequency and just then I can control it by myself. Is it possible to make it starting directly from pot value?
I assume you mean pot0 as pot1 does not appear in the code.
Try doing a skp run at the start of the code and initialize tri to a value based on the pot
Re: Flanger code, starting point
Posted: Thu Oct 21, 2021 11:11 pm
by gary00k
frank wrote: ↑Thu Oct 21, 2021 7:45 pmI assume you mean pot0 as pot1 does not appear in the code.
Yes, my bad
frank wrote: ↑Thu Oct 21, 2021 7:45 pmTry doing a skp run at the start of the code and initialize tri to a value based on the pot
Unfortunately, that didn't change anything.
Code: Select all
;pot0 = flange rate
mem fladel 512
equ fladel_138 fladel+138 ; mid pointer to flange delay
equ fladel_139 fladel+139 ; mid pointer to flange delay +1
equ tri reg0 ; triangle made from ramp
equ flaout reg1 ; mixed flanger output
equ fladout reg2 ; flange delay output
equ k1 reg3 ; first coefficient for linear interpolation
equ k2 reg4 ; second coefficient for linear interpolation
equ temp reg5 ; general temp register
; Inits
skp run, 2
sof 0, -0.0000195 ; ( -0.13 + ( 0 * 0.13 ) ) * 0.00015
wrax tri, 0
; Inputs control
rdax fladout, 0.6 ; get fraction of flange output
rdax adcl, 0.5 ; add inputs * 0.5 each
rdax adcr, 0.5
wra fladel, 0 ; write flange delay input, clear acc
; Flanger control
sof 0, -0.13
rdax pot0, 0.13
sof 0.00015, 0 ; scale to filter
rdax tri, 0.9999 ; filter triangle waveform so that pitch bend does not get too great at high rates
wrax tri, 0 ; write triangle wave to register, clear accumulator
; Formulate delay pointer,
or fladel_138 < 8 ; fladel^ + 138 ;get midpoint address pointer
rdax tri, 0.03125 ; add triangle wave modulation, scaled to fit delay range
wrax addr_ptr, 1 ; establish address for lower interpolation sample
; Develop fraction of tri:
and 0x0000FF ; mask off integer portion of address, leaving a fractional value in the lowest acc byte
sof -2,0 ; these operations shift the resulting fractional value to the range 0.0 to 0.999...
sof -2,0 ; only -2.0 is exact, but it changes sign of shifted value
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2, 0
sof -1, 0 ; 15 shifts
wrax k2, 0 ; write result as coefficient for second sample read
or 0x7FFFFF
rdax k2, -1
wrax k1, 0 ; write result as coefficient for first sample read
; Read from first pointer:
rmpa 1 ; read memory for first sample read
mulx k1 ; multiply by K1
wrax temp, 0 ; and store in temp, while clearing the acc
; Get second pointer:
or fladel_139 < 8 ; fladel^ + 139 ;form second pointer
rdax tri, 0.03125 ; add triangle waveform again
wrax addr_ptr, 0 ; establish address for upper interpolation sample
rmpa 1 ; read second interpolation sample
mulx k2 ; multiply by K2
rdax temp, 1 ; add temp (first value*K1)
wrax fladout, 1 ; write the result to the flanger delay output
rda fladel, 1 ; add the input to the flanger delay
wrax flaout, 0 ; write result to flaout and clear acc
rdax flaout, 1 ; add flaout
wrax dacr, 1 ; write to right output, save accumulator
wrax dacl, 0 ; write to left output, clear acc
Re: Flanger code, starting point
Posted: Fri Oct 22, 2021 7:29 am
by frank
gary00k wrote: ↑Thu Oct 21, 2021 11:11 pm
frank wrote: ↑Thu Oct 21, 2021 7:45 pmTry doing a skp run at the start of the code and
initialize tri to a value based on the pot
Unfortunately, that didn't change anything.
Code: Select all
;pot0 = flange rate
; Inits
skp run, 2
sof 0, -0.0000195 ; ( -0.13 + ( 0 * 0.13 ) ) * 0.00015
wrax tri, 0
I do not see the pot being used in the init code, you need to read it and use it.
Re: Flanger code, starting point
Posted: Fri Oct 22, 2021 10:19 am
by gary00k
Okay, I thought it was simply about entering the value I want to start with.
Still without change.
Code: Select all
;pot0 = flange rate
mem fladel 512
equ fladel_138 fladel+138 ; mid pointer to flange delay
equ fladel_139 fladel+139 ; mid pointer to flange delay +1
equ tri reg0 ; triangle made from ramp
equ flaout reg1 ; mixed flanger output
equ fladout reg2 ; flange delay output
equ k1 reg3 ; first coefficient for linear interpolation
equ k2 reg4 ; second coefficient for linear interpolation
equ temp reg5 ; general temp register
; Inits
skp run, 4
sof 0, -0.13
rdax pot0, 0.13
sof 0.00015, 0
wrax tri, 0
; Inputs control
rdax fladout, 0.6 ; get fraction of flange output
rdax adcl, 0.5 ; add inputs * 0.5 each
rdax adcr, 0.5
wra fladel, 0 ; write flange delay input, clear acc
; Flanger control
sof 0, -0.13
rdax pot0, 0.13
sof 0.00015, 0 ; scale to filter
rdax tri, 0.9999 ; filter triangle waveform so that pitch bend does not get too great at high rates
wrax tri, 0 ; write triangle wave to register, clear accumulator
; Formulate delay pointer,
or fladel_138 < 8 ; fladel^ + 138 ;get midpoint address pointer
rdax tri, 0.03125 ; add triangle wave modulation, scaled to fit delay range
wrax addr_ptr, 1 ; establish address for lower interpolation sample
; Develop fraction of tri:
and 0x0000FF ; mask off integer portion of address, leaving a fractional value in the lowest acc byte
sof -2,0 ; these operations shift the resulting fractional value to the range 0.0 to 0.999...
sof -2,0 ; only -2.0 is exact, but it changes sign of shifted value
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2, 0
sof -1, 0 ; 15 shifts
wrax k2, 0 ; write result as coefficient for second sample read
or 0x7FFFFF
rdax k2, -1
wrax k1, 0 ; write result as coefficient for first sample read
; Read from first pointer:
rmpa 1 ; read memory for first sample read
mulx k1 ; multiply by K1
wrax temp, 0 ; and store in temp, while clearing the acc
; Get second pointer:
or fladel_139 < 8 ; fladel^ + 139 ;form second pointer
rdax tri, 0.03125 ; add triangle waveform again
wrax addr_ptr, 0 ; establish address for upper interpolation sample
rmpa 1 ; read second interpolation sample
mulx k2 ; multiply by K2
rdax temp, 1 ; add temp (first value*K1)
wrax fladout, 1 ; write the result to the flanger delay output
rda fladel, 1 ; add the input to the flanger delay
wrax flaout, 0 ; write result to flaout and clear acc
rdax flaout, 1 ; add flaout
wrax dacr, 1 ; write to right output, save accumulator
wrax dacl, 0 ; write to left output, clear acc
Re: Flanger code, starting point
Posted: Tue Oct 26, 2021 3:10 am
by gary00k
Any aditional suggestions, please?
Re: Flanger code, starting point
Posted: Tue Oct 26, 2021 7:41 am
by frank
gary00k wrote: ↑Tue Oct 26, 2021 3:10 am
Any aditional suggestions, please?
You will have to go through the code line by line and find where you need to make the changes. Use something like Excel to calculate the values each sample period and graph them to see what is going on and what need to change.
Re: Flanger code, starting point
Posted: Tue Oct 26, 2021 11:55 am
by gary00k
I was afraid of that but ok, tell me please, does "fladel_139 < 8" means to shift fladel_139 value 8 places left?
Re: Flanger code, starting point
Posted: Tue Oct 26, 2021 1:19 pm
by frank
gary00k wrote: ↑Tue Oct 26, 2021 11:55 am
I was afraid of that but ok, tell me please, does "fladel_139 < 8" means to shift fladel_139 value 8 places left?
Yes, shift of 8 bits left
Re: Flanger code, starting point
Posted: Wed Oct 27, 2021 3:45 am
by gary00k
Okay. One more thing: is there a easier way to shift ACC value by X bits? I mean to simplify this:
Code: Select all
and 0x0000FF
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2,0
sof -2, 0
sof -1, 0
to something like this:
Leave the last byte and shift it 15 bits left. Or maybe some trick with log/exp to rise the value after mask?
You know, this multiplications uses at least 15 lines of code.
Re: Flanger code, starting point
Posted: Wed Oct 27, 2021 7:32 am
by frank
The log might help (the "and" with the <15 will not work) but I have never done it. I would try something like:
mask with the AND 0x0000FF
take log of result
add 0x710000
take exp