Synth

Algorithm development and general DSP issues

Moderator: frank

frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Yup, slacker did what I was meaning. Here is a 48-bit LFSR based one, uses more instructions but has a very long repeat cycle.

Code: Select all

; LFSR for random numbers
; Frank Thomson - OCT Distribution
; 2011
;
; reg 0 : low lfsr register
; reg 1 : high lfsr register
; reg 2 : temp register
;
equ lfsrl reg0
equ lfsrh reg1
equ temp reg2
;
;
;
;
; seed the lfsr with a non-zero value
skp run,start
ldax adcl
or 0x001000	; just to ensure it is really non-zero
wrax lfsrl,1.0
wrax lfsrh,0
;
;
start:
ldax lfsrh	; get the "high" 24-bits
and 0x000001	; grab bit 48
wrax temp,0	; save it and clear acc
rdax lfsrh,0.5	; read the high again and shift 1 bit
and 0x7fffff	; clear the msb
wrax lfsrh,1.0	; save the shifted result
and 0x000001	; grab the bit 47
rdax temp,1.0	; add it to the previous bit (doing an xor by adding, the lsb is the result)
wrax temp,0	; save it
rdax lfsrl, 1.0	; get the "low" 24-bits
and 0x000001	; get the lsb
skp zro,nada	; if 0 do nothing
ldax lfsrh	; get the upper bits
or 0x800000	; set the msb
wrax lfsrh,0
nada:
;
;at this point the upper 24 bits are done
;
rdax lfsrl, 0.5	; get the "low" 24-bits and shift 1 bit
and 0x7fffff	; clear msb
wrax lfsrl,0.25	; save shifted value and shift 2 more bits
and 0x000001	; grab bit 21
rdax temp,1.0	; add it to the previous result
wrax temp,0	; save it
rdax lfsrl,0.125	; read the low again and shift (already did 1 bit shift above)
and 0x000001	; grab the bit 20
rdax temp,1.0	; add it to the previous bit (doing an xor by adding, the lsb is the result)
and 0x000001	; only care about lsb
skp zro,shftzro
; if here the bit was a 1
sof 0,0		; clear acc
rdax lfsrl,1.0	; get the low
or 0x800000	; set the bit
wrax lfsrl,0	; save it
;
shftzro:
; low 24-bits done
; use low 24 for output, could use upper or even middle points
ldax lfsrl
wrax dacl,0
I think it works properly, only just wrote it so hope it is correct. Sounds like noise, don't hear any tones.
Frank Thomson
Experimental Noize
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

24-bit lfsr, shorter cycle time but not hearing any tones

Code: Select all

; ; Frank Thomson - OCT Distribution
; V2 of 24-bit
; 2011
;
; reg 0 : lfsr register
; reg 1 : copy lfsr
; reg 1 : temp register
;
equ lfsr reg0
equ lfsr2 reg1
equ temp reg2
;
; seed the lfsr with a non-zero value
skp run,start
ldax adcl
or 0x001000	; just to ensure it is really non-zero
wrax lfsr,0
;
;
start:
ldax lfsr		; get lfsr reg
and 0x00ffff	; get rid of upper bits to avoid saturating
wrax lfsr2,1.0	; save the result and keep in acc
rdax lfsr2,0.5	; get lfsr shifted 1 bit and add it
rdax lfsr2,0.25	; get lfsr shifted 2 bits and add
rdax lfsr2,0.0078125	; get lfsr shifted 7 bits and add
and 0x000001	; only care about lsb of result
wrax temp,0	; save result
rdax lfsr,0.5	; get lfsr reg shifted right
and 0x7fffff	; clear msb
wrax lfsr,0	; save result
ldax temp	; get the result back
skp zro,shftzro	; if 0 jump
; if here the bit was a 1
sof 0,0		; clear acc
rdax lfsr,1.0	; get the low
or 0x800000	; set the bit
wrax lfsr,0	; save it
;
shftzro:
ldax lfsr
wrax dacl,0
note: code was edited after initial post to make it shorter
Frank Thomson
Experimental Noize
peterv
Posts: 17
Joined: Fri Nov 20, 2009 3:43 am
Location: Netherlands
Contact:

Post by peterv »

A deep bow to Frank, Sean and Slacker!!
I'll get it in my code and put the hardware (PIC processor) back on the shelf. I believe that a LP filter is to be added see:

http://www.imeko.org/publications/wc-20 ... C-008u.pdf


Thanks!

Piet
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Interesting paper, will need to get time to read it in depth. I think the only reason they have the low pass filter in their design is because it is acting as a single-bit DAC to turn the digital bit stream into an analog value so we don't need it in the code here and the DAC in the FV-1 has any required filtering.
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Frank codes are listed in your last message, I do not work: (. Only the noise, the adjustment of potentiometers is not responding. There are thought to make it work?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Alex MAK wrote:Frank codes are listed in your last message, I do not work: (. Only the noise, the adjustment of potentiometers is not responding. There are thought to make it work?
The above code does not use any of the pot inputs, it is purely a noise generator so you would need to add additional code like filters or use the value to add noise to a SIN wave, etc.
Frank Thomson
Experimental Noize
Alex MAK
Posts: 89
Joined: Fri Nov 05, 2010 1:00 pm

Post by Alex MAK »

Ok, thank you. How to make these pieces of work as the finished product?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Well, it depends, what is the target product?
Frank Thomson
Experimental Noize
Post Reply