Sorceress

Shift Register Simulator with sound output

Jan 25th, 2021
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Shift Register Simulator: Noise Generator with sound output
  2. '(c)2021, @_sorceress
  3.  
  4. DEFLNG A-Z
  5. DIM y AS SINGLE
  6.  
  7. 'bitmasks for each tap
  8. DIM SHARED Q(8): Q(1) = 1: FOR i = 2 TO 8: Q(i) = 2 * Q(i - 1): NEXT
  9.  
  10. SR1 = 1 'pre-load the first register
  11.  
  12. SampleRate = _SNDRATE 'generator frequency determined by soundcard
  13.  
  14. DO
  15. FOR i = 1 TO SampleRate
  16.  
  17. 'select an output tap
  18. y = Tap(SR3, 8)
  19.  
  20. 'output to soundcard * volume
  21. _SNDRAW y * 0.125
  22.  
  23. 'wiring the registers together
  24. SR1Data = Tap(SR3, 2) XOR Tap(SR3, 7) 'feedback
  25. SR2Data = Tap(SR1, 8) 'chaining SR1 and SR2
  26. SR3Data = Tap(SR2, 8) 'chaining SR2 and SR3
  27.  
  28. 'clock
  29. SR1 = (SR1 AND 127%) * 2 + SR1Data
  30. SR2 = (SR2 AND 127%) * 2 + SR2Data
  31. SR3 = (SR3 AND 127%) * 2 + SR3Data
  32.  
  33. NEXT
  34. _LIMIT 1
  35. LOOP UNTIL INKEY$ = CHR$(27) 'escape key halts the program
  36. END
  37.  
  38. FUNCTION Tap (SR%, bit%)
  39. Tap = SGN(SR% AND Q(bit%))
  40. END FUNCTION
RAW Paste Data