Slow Random Noise
Posted: Thu Jul 23, 2015 7:17 am
I posted a white noise generator in a previous post:
http://www.spinsemi.com/forum/viewtopic.php?t=528
However, I think that a different version that cycles more slowly would work better for filters, S-H, and other applications that could use the random numbers generated at a slower pace.
I've put a counter in the loop that only steps the random number generator on 8th notes (at 120 bpm). The timing is not critical on that so don't fret about it if your song is a different tempo. It only matters that the steps are happening at a slower pace.
Output is -1 to 1v so you can half-wave rectify or take the absolute value if you need a 0 to 1 cv.
The second instruction after the Start label can be changed to alter the tempo at which it spits out new random numbers.
I just wrote this code, so consider it untested as yet, and subject to errors.
Best regards, Jack
http://www.spinsemi.com/forum/viewtopic.php?t=528
However, I think that a different version that cycles more slowly would work better for filters, S-H, and other applications that could use the random numbers generated at a slower pace.
I've put a counter in the loop that only steps the random number generator on 8th notes (at 120 bpm). The timing is not critical on that so don't fret about it if your song is a different tempo. It only matters that the steps are happening at a slower pace.
Code: Select all
Code:
; Slow 24 bit maximal period Galois LFSR
; Example by Jack Orman
; http://www.muzique.com
; March 5, 2015 & July 23, 2015
; REG 0 : LFSR NOISE REGISTER
; REG 1 : OUTPUT BIT
;
EQU LFSR REG0
EQU TEMP REG1
EQU PRN REG3
;
; SEED THE LFSR WITH A NON-ZERO VALUE
SKP RUN,START
SOF 0,-1 ; JUST TO ENSURE IT IS REALLY NON-ZERO
WRAX LFSR,1 ; saves an instruction by using that value twice
WRAX PRN,0 ; initialize cycle counter
;
;
START:
LDAX PRN ; get cycle counter
SOF 1,0.000122 ; increment counter
; change to SOF 1,0.000244 for 16th notes
SKP NEG, SHFTZRO ; jump if negative
SOF 0,-1
WRAX PRN,0 ; reset cycle counter
LDAX LFSR ; GET LFSR REGISTER
AND 0x000001 ; GET LSB OF THE NOISE REGISTER
WRAX TEMP,0 ; SAVE BIT
RDAX LFSR,0.5 ; GET LFSR REG AND SHIFT RIGHT 1 PLACE
AND 0x7FFFFF ; CLEAR MSB
WRAX LFSR,0 ; SAVE RESULT
LDAX TEMP ; GET THE OUTPUT BIT
SKP ZRO,SHFTZRO ; IF 0 THEN JUMP
; IF LSB WAS SET THEN PROCESS
CLR ; CLEAR ACC
LDAX LFSR ; GET THE SAVED LFSR
XOR 0xD80000 ; TOGGLE THE MASK BITS
WRAX LFSR,0 ; SAVE IT
;
SHFTZRO:
LDAX LFSR
WRAX DACL,0
; ABSA the LFSR before using if you want a 0 to 1v output
The second instruction after the Start label can be changed to alter the tempo at which it spits out new random numbers.
I just wrote this code, so consider it untested as yet, and subject to errors.
Best regards, Jack