Advertisement
Guest User

Untitled

a guest
Nov 26th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 1.90 KB | None | 0 0
  1. OPTION BASE 0
  2.  
  3.  
  4. DIM nod AS INTEGER ' number of delays
  5.  
  6. nod = 100
  7.  
  8. DIM delayLength(nod) AS LONG, delayCounter(nod) AS LONG, delayFeedback(nod) AS _FLOAT
  9.  
  10. FOR d = 0 TO nod - 1
  11.     delayLength(d) = 5000 * RND + 500
  12. NEXT d
  13.  
  14.  
  15. FOR d = 0 TO nod - 1
  16.     delayFeedback(d) = 0.1 * RND + 0.8
  17. NEXT d
  18.  
  19. DIM delayBuffer(nod, 65536) AS _FLOAT
  20.  
  21.  
  22. DIM outputCounter AS LONG, outputSample AS _FLOAT, outputSampleInt AS INTEGER, outputLength AS LONG
  23. outputLength = 88200 * 2
  24.  
  25.  
  26. DIM inputLength AS LONG, inputCounter AS LONG
  27. inputLength = 5000
  28. inputCounter = 0
  29.  
  30. DIM inputBuffer(inputLength) AS _FLOAT
  31.  
  32. OPEN "delayinput.txt" FOR INPUT AS #1
  33. d = 0
  34. WHILE NOT EOF(1)
  35.     INPUT #1, inputBuffer(d)
  36.     d = d + 1
  37. WEND
  38. CLOSE #1
  39.  
  40. OPEN "delay.txt" FOR OUTPUT AS #1
  41.  
  42. DO
  43.  
  44.     outputSample = 0
  45.  
  46.     FOR d = 0 TO nod - 1
  47.  
  48.         ' 1) delay outputs the current sample in the delay buffer
  49.         outputSample = outputSample + delayBuffer(d, delayCounter(d))
  50.  
  51.         ' 2) current sample in the delay buffer is multiplied with the delay's internal feedback factor (0-1)
  52.         delayBuffer(d, delayCounter(d)) = delayBuffer(d, delayCounter(d)) * delayFeedback(d)
  53.  
  54.         ' 3) input signal sample is added to teh current sample
  55.         delayBuffer(d, delayCounter(d)) = delayBuffer(d, delayCounter(d)) + inputBuffer(inputCounter)
  56.  
  57.         ' 4) advance delayCounter by 1
  58.         delayCounter(d) = delayCounter(d) + 1
  59.  
  60.         ' 5) if reach the end of the delayBuffer, go to the beginning
  61.         IF delayCounter(d) = delayLength(d) THEN
  62.             delayCounter(d) = 0
  63.  
  64.             ' 6) apply possible filter to the whole delay buffer here?
  65.         END IF
  66.  
  67.  
  68.     NEXT d
  69.  
  70.     inputCounter = inputCounter + 1
  71.     IF inputCounter = inputLength THEN inputCounter = inputCounter - 1
  72.  
  73.     outputCounter = outputCounter + 1
  74.  
  75.     PRINT #1, outputSample
  76.  
  77. LOOP UNTIL outputCounter = outputLength OR INP(96) = 1
  78. CLOSE #1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement