Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Shift Register Simulator: Noise Generator with file output
- '(c)2021, @_sorceress
- DEFLNG A-Z
- DIM b AS _UNSIGNED _BYTE
- samplerate = 44100 'generator frequency
- filename$ = "C:\noise.raw" 'where you want the noise saved
- seconds = 10 'and the amount of noise to generate
- 'the sound will be saved as unsigned 8-bit mono PCM at the given samplerate
- ' you will need to specify this when you import the file into a sound editing program
- ' because the format isn't saved in the file
- 'bitmasks for each tap
- DIM SHARED Q(8): Q(1) = 1: FOR i = 2 TO 8: Q(i) = 2 * Q(i - 1): NEXT
- SR1 = 1 'pre-load the first register
- OPEN filename$ FOR BINARY AS #1
- FOR j = 1 TO seconds
- LOCATE 1, 1: PRINT j; "/"; seconds; " seconds"
- FOR i = 1 TO samplerate
- 'select an output tap
- b = Tap(SR3, 8)
- 'set level and zero-offset for unsigned 8-bit
- b = 96 + 64 * b
- 'output byte to file
- PUT #1, , b
- 'wiring the registers together
- SR1Data = Tap(SR3, 2) XOR Tap(SR3, 7) 'feedback
- SR2Data = Tap(SR1, 8) 'chaining SR1 and SR2
- SR3Data = Tap(SR2, 8) 'chaining SR2 and SR3
- 'clock
- SR1 = (SR1 AND 127%) * 2 + SR1Data
- SR2 = (SR2 AND 127%) * 2 + SR2Data
- SR3 = (SR3 AND 127%) * 2 + SR3Data
- NEXT
- NEXT
- CLOSE #1
- END
- FUNCTION Tap (SR%, bit%)
- Tap = SGN(SR% AND Q(bit%))
- END FUNCTION
Add Comment
Please, Sign In to add comment