Stupid questions. For beginners.

Algorithm development and general DSP issues

Moderator: frank

Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

I added a block of the tone control code for code Ring modulator. Where'd I go wrong? Why is this a bug? I want answers! :)

;POT0 : Control frequency
;
equ s reg0
equ c reg1
equ lp_filt reg2

;Then initialize the oscillator by setting one to xero and the other to -1
;we do this just once, during the first cycle of operation

skp run,endset ;do not execute if already running
wrax s,0 ;set s to 0, (acc should be zero)
sof 0,-1 ;set accum to -1
wrax c,0 ;write to c
endset: ;jump-to label

;Now do the LFO, using pot0 as a control for frequency

rdax s,0.02 ;read the s register, change this value between 0.001 and 1.0
mulx pot0 ;multiply by pot value
rdax c,1 ;read the c register
wrax c,-0.02 ;integrate the c value, this value MUST be the negative of
;what ever you set the value in 'rdax s,X' to above
mulx pot0 ;multiply by pot value
rdax s,1 ;read s reg
wrax s,1 ;integrate the s value

;Either the s or c register will be producing s waveforms (just shifted in
;phase), so either can be used as a modulation source. The maximum
;frequency of this LFO is Fs/2pi, which should be high enough!


rdax lp_filt,-1.0 ; ADCL - lp_filt
mulx pot1 ; * C (POT1 in this case)
rdax lp_filt,1.0 ; +lp_filt
wrax lp_filt,1.0; write result to lp_filt


mulx adcl

;and output the result

wrax dacl,0

I want to POT2 it was a MIX between the effect and clean guitar. How to do it? I want to apply it in other codes too :) .

With the addition of reverb to Octaver also released failure: (I want a more detailed explanation. What a block of code should I use? How to determine the beginning and end of the block and how to properly use the code.

Thanks in advance.
livingston
Posts: 131
Joined: Sun Nov 15, 2009 3:37 pm
Location: New Orleans, LA US

Post by livingston »

The reason that failed is that you are applying the tone control to the oscillator signal only.

The block diagram for this ring modulator would be

create oscillator - multiply the input signal with oscillator - write to output

The ring modulated guitar signal is in the accumulator after the "mulx adcl" operation, so you need to put your tone control there.
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Well. Thank you! I will try. Began to learn the knowledge base:). Little is know, but I hope with your help I will learn to understand it:)

I want to POT2 it was a MIX between the effect and clean guitar. How to do it? I want to apply it in other codes too Smile .
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Tell me please, why not pitch shifter works?
;pot0 adjusts reverb
;pot1 adjusts auto wah
;pot2 adjusts pitch shift

mem pdel 512 ;delay for pitch transposing
mem pmix 1

mem ap1 334
mem ap2 556
mem ap3 871

mem lap1a 808
mem lap1b 1934
mem d1 2489

mem lap2a 1016
mem lap2b 1787
mem d2 2287

;register equates:

equ mono reg0
equ apout reg1
equ lp1 reg2
equ lp2 reg3
equ revout reg4
equ wahout reg5
equ wf1 reg6
equ wf2 reg7
equ wf reg8
equ wq reg9
equ temp reg10
equ avg reg11
equ lavg reg12
equ ffil reg13
equ bypass reg14
equ potfil reg15 ;adjusts pitch

;declare constants:

equ kap 0.6 ;all pass coefficient
equ krt 0.55 ;reverb time
equ krf 0.5 ;reverb lpf freq
equ krs -0.6 ;reverb lpf shelf


; Initialization, only run on first executuion of code
; Skip the following two instructions if NOT the first time

skp RUN, loop
wldr 0, 0, 512 ; Load up ramp0 LFO to shift up 0 octaves, A=0x0 (512 range)
wrax lp1,0
wrax lp2,0
wrax wf1,0
wrax wf2,0
wlds sin0,12,100
loop:

;set up pot2 to control pitch shift:

rdax pot2, 1.0 ; Read in pot 2
sof 0.25, -0.125 ; POT2 in ACC, -0.125 to +0.125
rdfx potfil, 0.02 ; Smooth the result to avoid jumping
wrax potfil, 1.0
wrax rmp0_rate, 0 ; Write to LFO control register

; Do the pitch shift:

rdax adcl,1.0 ; Read in a value, ADCL * 1.0 -> ACC
wra pdel,0 ; Write it to memory address 0
cho rda,rmp0,reg|compc,pdel ; (1-k)*sample[addr]
cho rda,rmp0,0,pdel+1 ; k*sample[addr+1] + ACC
wra pmix,0 ; Save it off to memory and clear ACC

; Do other transposer tap:

cho rda,rmp0,rptr2|compc,pdel ; (1-k)*sample[addr+ half ramp]
cho rda,rmp0,rptr2,pdel+1 ; k*sample[addr+ half ramp + 1] + ACC

;crossfade between taps:

cho sof,rmp0,na|compc,0 ; Result in ACC, multiply it by (1-XFADE) coefficient
cho rda,rmp0,na, pmix ; Add value saved in memory, multiply value by XFADE coefficient
wrax dacl,0 ; Write it to DACL and clear ACC

;sum inputs to mono:

rdax adcl,0.5
rdax adcr,0.5
wrax mono,0

;do reverb and put result in revout (after pot0 control):

rdax wahout,0.5
rda ap1#,kap
wrap ap1,-kap
rda ap2#,kap
wrap ap2,-kap
rda ap3#,kap
wrap ap3,-kap
wrax apout,0

rda d2#,krt
rdax apout,1
rda lap1a#,kap
wrap lap1a,-kap
rda lap1b#,kap
wrap lap1b,-kap
rdfx lp1,krf
wrlx lp1,krs
wra d1,0

rda d1#,krt
rdax apout,1
rda lap2a#,kap
wrap lap2a,-kap
rda lap2b#,kap
wrap lap2b,-kap
rdfx lp2,krf
wrlx lp2,krs
wra d2,1.99
rda d1,1.99
mulx pot0
mulx pot0
wrax revout,0

;smooth reverb:

cho rda,sin0,sin|reg|compc,lap1b+100
cho rda,sin0,sin,lap1b+101
wra lap1b+200,0
cho rda,sin0,sin|reg|compc,lap2b+100
cho rda,sin0,sin,lap2b+101
wra lap2b+200,0

;Now do wah, a 2 pole LPF, peaking.
;begin by getting control level into detector:

rdax mono,1 ;get input
absa ;absolute value
rdfx avg,0.01 ;average input level
wrax avg,0 ;write avg level, pass on
rdax lavg,0.001
sof -0.01,0
rdax lavg,1
wrax temp,0
rdax avg,1
maxx temp,1 ;filter a long average
wrax lavg,0

;now set up a means by which the sensitivity control can affect the filter frequency:

rdax lavg,1
sof 1,0.002 ;never let lavg go to zero
log 1,0
wrax temp,0
rdax avg,1
log 1,0
rdax temp,-1
mulx pot1
exp 1,0
rdfx ffil,0.0005
wrax ffil,1
sof 0.7,0.02 ;limit frequency range
wrax wf,0

;get wfq value from pot2:

rdax pot1,1
sof -0.2,0.25 ;make 0.3 to 0.05
wrax wq,0 ;write Q value (pos number)

;do filter:

rdax wf1,1
mulx wf
rdax wf2,1
wrax wf2,-1
rdax mono,1
wrax temp,0 ;save signal
rdax wf1,-1
mulx wq
rdax temp,1
mulx wf
rdax wf1,1
wrax wf1,0 ;finished with biquad filter.

;derive bypass signal from pot2:

rdax pot1,1
rdax bypass,0.9 ;recursive gain
wrax bypass,0

;now combine outputs to make a wahout signal

rdax mono,-1
rdax wf2,1
mulx bypass
rdax mono,1
wrax wahout,1
rdax revout,1
sof 1,0.02
wrax dacl,1
sof 1,-0.04
wrax dacr,0
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

You are overwriting the DACL output. In the pitch portion:

Code: Select all

; Do the pitch shift:

rdax adcl,1.0 ; Read in a value, ADCL * 1.0 -> ACC
wra pdel,0 ; Write it to memory address 0
cho rda,rmp0,reg|compc,pdel ; (1-k)*sample[addr]
cho rda,rmp0,0,pdel+1 ; k*sample[addr+1] + ACC
wra pmix,0 ; Save it off to memory and clear ACC

; Do other transposer tap:

cho rda,rmp0,rptr2|compc,pdel ; (1-k)*sample[addr+ half ramp]
cho rda,rmp0,rptr2,pdel+1 ; k*sample[addr+ half ramp + 1] + ACC

;crossfade between taps:

cho sof,rmp0,na|compc,0 ; Result in ACC, multiply it by (1-XFADE) coefficient
cho rda,rmp0,na, pmix ; Add value saved in memory, multiply value by XFADE coefficient
wrax dacl,0 ; Write it to DACL and clear ACC <<<<<<<< WRITING TO DACL

Then further down you have:

Code: Select all

;now combine outputs to make a wahout signal

rdax mono,-1
rdax wf2,1
mulx bypass
rdax mono,1
wrax wahout,1
rdax revout,1
sof 1,0.02
wrax dacl,1 ;<<<<<<<< YOU ARE OVERWRITING DACL
sof 1,-0.04
wrax dacr,0
What you should be doing is saving the result of each step to a register then adding them all together at the end then writing to DACL or DACR
Frank Thomson
Experimental Noize
Fulcrum
Posts: 7
Joined: Tue Oct 04, 2011 10:48 am

Post by Fulcrum »

Is there a debugger for SpinAsm (like Turbo debugger for TASM) to track the value of registers after each operation?
Would be of great help to me as lurking through the code trying to memorize which value you have when there are 15 registers is truly slowing down.

Would also help to avoid mistakes like one stated above with overwriting sectors.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Fulcrum wrote:Is there a debugger for SpinAsm (like Turbo debugger for TASM) to track the value of registers after each operation?
Nope, no debugger available.
Fulcrum wrote: Would be of great help to me as lurking through the code trying to memorize which value you have when there are 15 registers is truly slowing down.

Would also help to avoid mistakes like one stated above with overwriting sectors.
There are some rules I like to follow that help:

Always name registers, it is easier to see a mistake when writing to a named register that a numbered one.

Only write to the DACL and DACR at then end of the program, it is rare you will ever need to write in the middle of the program.

Search for DACL and DACR in your code if there is a problem, there should only be one of each and should always follow the format "wrax DACL,x" where x is a number.
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Tell me please, why not pitch shifter works?


;pitch transopse in left channel, echo in right chan
;pot0 adjusts reverb
;pot1 adjusts auto wah
;pot2 adjusts pitch shift

mem pdel 512 ;delay for pitch transposing
mem pmix 1

mem ap1 334
mem ap2 556
mem ap3 871

mem lap1a 808
mem lap1b 1934
mem d1 2489

mem lap2a 1016
mem lap2b 1787
mem d2 2287

;register equates:

equ mono reg0
equ apout reg1
equ lp1 reg2
equ lp2 reg3
equ revout reg4
equ wahout reg5
equ wf1 reg6
equ wf2 reg7
equ wf reg8
equ wq reg9
equ temp reg10
equ avg reg11
equ lavg reg12
equ ffil reg13
equ bypass reg14
equ potfil reg15 ;adjusts pitch

;declare constants:

equ kap 0.6 ;all pass coefficient
equ krt 0.55 ;reverb time
equ krf 0.5 ;reverb lpf freq
equ krs -0.6 ;reverb lpf shelf


; Initialization, only run on first executuion of code
; Skip the following two instructions if NOT the first time

skp RUN, loop
wldr 0, 0, 512 ; Load up ramp0 LFO to shift up 0 octaves, A=0x0 (512 range)
wrax lp1,0
wrax lp2,0
wrax wf1,0
wrax wf2,0
wlds sin0,12,100
loop:

;set up pot2 to control pitch shift:

rdax pot2, 1.0 ; Read in pot 2
sof 0.25, -0.125 ; POT2 in ACC, -0.125 to +0.125
rdfx potfil, 0.02 ; Smooth the result to avoid jumping
wrax potfil, 1.0
wrax rmp0_rate, 0 ; Write to LFO control register

; Do the pitch shift:

rdax adcl,1.0 ; Read in a value, ADCL * 1.0 -> ACC
wra pdel,0 ; Write it to memory address 0
cho rda,rmp0,reg|compc,pdel ; (1-k)*sample[addr]
cho rda,rmp0,0,pdel+1 ; k*sample[addr+1] + ACC
wra pmix,0 ; Save it off to memory and clear ACC

; Do other transposer tap:

cho rda,rmp0,rptr2|compc,pdel ; (1-k)*sample[addr+ half ramp]
cho rda,rmp0,rptr2,pdel+1 ; k*sample[addr+ half ramp + 1] + ACC

;crossfade between taps:

cho sof,rmp0,na|compc,0 ; Result in ACC, multiply it by (1-XFADE) coefficient
cho rda,rmp0,na, pmix ; Add value saved in memory, multiply value by XFADE coefficient
wrax potfil,0 ; Write it to reg15 and clear ACC

;sum inputs to mono:

rdax potfil,0.5
rdax adcr,0.5
wrax mono,0

;do reverb and put result in revout (after pot0 control):

rdax wahout,0.5
rda ap1#,kap
wrap ap1,-kap
rda ap2#,kap
wrap ap2,-kap
rda ap3#,kap
wrap ap3,-kap
wrax apout,0

rda d2#,krt
rdax apout,1
rda lap1a#,kap
wrap lap1a,-kap
rda lap1b#,kap
wrap lap1b,-kap
rdfx lp1,krf
wrlx lp1,krs
wra d1,0

rda d1#,krt
rdax apout,1
rda lap2a#,kap
wrap lap2a,-kap
rda lap2b#,kap
wrap lap2b,-kap
rdfx lp2,krf
wrlx lp2,krs
wra d2,1.99
rda d1,1.99
mulx pot0
mulx pot0
wrax revout,0

;smooth reverb:

cho rda,sin0,sin|reg|compc,lap1b+100
cho rda,sin0,sin,lap1b+101
wra lap1b+200,0
cho rda,sin0,sin|reg|compc,lap2b+100
cho rda,sin0,sin,lap2b+101
wra lap2b+200,0

;Now do wah, a 2 pole LPF, peaking.
;begin by getting control level into detector:

rdax mono,1 ;get input
absa ;absolute value
rdfx avg,0.01 ;average input level
wrax avg,0 ;write avg level, pass on
rdax lavg,0.001
sof -0.01,0
rdax lavg,1
wrax temp,0
rdax avg,1
maxx temp,1 ;filter a long average
wrax lavg,0

;now set up a means by which the sensitivity control can affect the filter frequency:

rdax lavg,1
sof 1,0.002 ;never let lavg go to zero
log 1,0
wrax temp,0
rdax avg,1
log 1,0
rdax temp,-1
mulx pot1
exp 1,0
rdfx ffil,0.0005
wrax ffil,1
sof 0.7,0.02 ;limit frequency range
wrax wf,0

;get wfq value from pot2:

rdax pot1,1
sof -0.2,0.25 ;make 0.3 to 0.05
wrax wq,0 ;write Q value (pos number)

;do filter:

rdax wf1,1
mulx wf
rdax wf2,1
wrax wf2,-1
rdax mono,1
wrax temp,0 ;save signal
rdax wf1,-1
mulx wq
rdax temp,1
mulx wf
rdax wf1,1
wrax wf1,0 ;finished with biquad filter.

;derive bypass signal from pot2:

rdax pot1,1
rdax bypass,0.9 ;recursive gain
wrax bypass,0

;now combine outputs to make a wahout signal

rdax mono,-1
rdax wf2,1
mulx bypass
rdax mono,1
wrax wahout,1
rdax revout,1
sof 1,0.02
wrax dacl,1
sof 1,-0.04
wrax dacr,0








;Insane Pitch+sin_modulation+reverb
;pitch transopse in left channel, echo in right chan
;pot0 adjusts pitch
;pot1 adjusts sin modulation
;pot2 adjusts reverb

mem pdel 4096 ;delay for pitch transposing
mem pmix 1
mem ap1 334
mem ap2 556
mem ap3 871
mem lap1a 808
mem lap1b 1934
mem d1 2489
mem lap2a 1016
mem lap2b 1787
mem d2 2287

;register equates:

equ potfil reg0 ;adjusts pitch
equ temp reg1
equ wahl reg2
equ wahr reg3
equ lp1 reg4
equ lp2 reg5
equ revout reg6
equ apout reg7
equ pitout reg8
equ s reg10
equ c reg11
equ freq reg12

;declare constants:

equ kap 0.6 ;all pass coefficient
equ krt 0.55 ;reverb time
equ krf 0.5 ;reverb lpf freq
equ krs -0.6 ;reverb lpf shelf

; Initialization, only run on first executuion of code
; Skip the following two instructions if NOT the first time
;------------------------------------------------------------------------
skp RUN, loop
wldr 0, 0, 4096 ; Load up ramp0 LFO to shift up 0 octaves, A=0x0 (4096 range)
clr ; Clear ACC
wrax s,0 ; Write 0 to sin reg
sof 0,0.5 ; 0.5 -> ACC
wrax c,0 ; Write 0.5 to cos reg

loop:
;-------------------------------------------------------------
;set up pot0 to control pitch shift:

rdax pot0, 1.0 ; Read in pot 0
sof 0.25, -0.125 ; POT0 in ACC, -0.125 to +0.125
rdfx potfil, 0.02 ; Smooth the result to avoid jumping
wrax potfil, 1.0
wrax rmp0_rate, 0 ; Write to LFO control register

; Do the pitch shift:

rdax adcl,1.0 ; Read in a value, ADCL * 1.0 -> ACC
wra pdel,0 ; Write it to memory address 0
cho rda,rmp0,reg|compc,pdel ; (1-k)*sample[addr]
cho rda,rmp0,0,pdel+1 ; k*sample[addr+1] + ACC
wra pmix,0 ; Save it off to memory and clear ACC

; Do other transposer tap:

cho rda,rmp0,rptr2|compc,pdel ; (1-k)*sample[addr+ half ramp]
cho rda,rmp0,rptr2,pdel+1 ; k*sample[addr+ half ramp + 1] + ACC

;crossfade between taps:

cho sof,rmp0,na|compc,0 ; Result in ACC, multiply it by (1-XFADE) coefficient
cho rda,rmp0,na, pmix ; Add value saved in memory, multiply value by XFADE coefficient
wrax potfil,0 ; Write it to DACL and clear ACC

;sum inputs to pitout:

rdax potfil,0.5
rdax adcr,0.5
wrax pitout,0
;---------------------------------------------------------------------------
;sin modulation start:

clr
rdax pot1, 0.05 ; Read pot 1, scale to adjust max speed
wrax freq, 0 ; Save the freq coefficient
;
; Do the SIN calculation
rdax c, 1.0 ; COS -> ACC
mulx freq ; COS*fcoeff
rdax s, 1.0 ; +SIN
wrax s,0 ; Write it back
;
; Do the COS calculation, -SIN in ACC
rdax s, -1.0
mulx freq
rdax c, 1.0
wrax c, 0
;
; Modulate the inputs and write them to the regs
ldax adcl
mulx s
wrax wahl,0
ldax adcr
mulx s
wrax wahr,0

;----------------------------------------------------

;do reverb and put result in revout (after pot2 control):

rdax potfil,0.5
rda ap1#,kap
wrap ap1,-kap
rda ap2#,kap
wrap ap2,-kap
rda ap3#,kap
wrap ap3,-kap
wrax apout,0

rda d2#,krt
rdax apout,1
rda lap1a#,kap
wrap lap1a,-kap
rda lap1b#,kap
wrap lap1b,-kap
rdfx lp1,krf
wrlx lp1,krs
wra d1,0

rda d1#,krt
rdax apout,1
rda lap2a#,kap
wrap lap2a,-kap
rda lap2b#,kap
wrap lap2b,-kap
rdfx lp2,krf
wrlx lp2,krs
wra d2,1.99
rda d1,1.99
mulx pot2
mulx pot2
wrax revout,0

;smooth reverb:

cho rda,sin0,sin|reg|compc,lap1b+100
cho rda,sin0,sin,lap1b+101
wra lap1b+200,0
cho rda,sin0,sin|reg|compc,lap2b+100
cho rda,sin0,sin,lap2b+101
wra lap2b+200,0

;---------------------------------------------------------------

;now combine outputs

rdax pitout,1
rdax wahl,1
rdax revout,1
wrax dacl,1
wrax dacr,0
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Remove everything except pitch shifting and try to get that going first. It is difficult to debug a program with so much going on, you need to attack the problem in smaller steps.
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Hi! Guys, please tell me how to invert one signal in different channels, he was in a different phase. Thank you! Alex.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

To invert a signal just multiply by -1.0 like:

RDAX ADCL, -1.0

that would read in ADCL, invert it and put it in the ACC
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Thank you, Frank!

RDAX ADCL, -1.0
RDAX ADCR, 0

That's it right?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

I think you mean:

RDAX ADCL, -1.0
RDAX ADCR, 1.0

Because "RDAX ADCR, 0" means ADCR*0 so you would just be adding 0 to the accumulator not the ADCR value.
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Thank you, Frank! It looks like this is what I need :)
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Hi guys! I need your advice! I need to POT1 worked opposite. Ie with a minimum of POT1 was the maximum volume, and would decrease with increasing values ​​of POT1. Thank you! Sincerely, Alex.

Code: Select all

rdax   adcl,0.5    ; Write it to left delay and clear ACC
rdax   adcr,0.5     ; Write it to left delay and clear ACC

mulx POT1,1

wrax      dacl,1
wrax      dacr,0
Post Reply