home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / sfa7.bas < prev    next >
BASIC Source File  |  1994-05-13  |  3KB  |  119 lines

  1. DEFINT A-Z
  2.  
  3.     CONST BPORT = &H220  'Base Port address
  4.     CONST XPORT = &H226  'Reset port address
  5.     CONST WPORT = &H22C  'Write port address
  6.     CONST RPORT = &H22A  'Read port address
  7.     CONST APORT = &H22E  'Data Available port address
  8.  
  9.     DIM chgarray(40) 'change
  10.     DIM peakarray(30)    'peak leng
  11.     lenp = 0
  12.     lastd = 0   'last direction
  13.     lastgot = 128
  14.     lch0 = 0
  15.     tz0 = 0
  16.  
  17.     DEF SEG = &HA000
  18.     SCREEN 13
  19.  
  20.     lens = 0: lasts = 0
  21.     
  22.     DO
  23.         OUT WPORT, &H20           'Tell SoundBlaster you wanna read a byte.
  24.         gotit = INP(RPORT)
  25.         gg = (gotit - 128)
  26.         dir = gotit - lastgot
  27.  
  28.         IF dir > 1 THEN currentd = 1 ELSE IF dir < -1 THEN currentd = -1 ELSE currentd = lastd
  29.  
  30.         IF currentd <> lastd THEN
  31.             IF lenp > 309 THEN lenp = 309
  32.             lenp = lenp \ 10
  33.             peakarray(lenp) = peakarray(lenp) + (lenp \ 2)
  34.             lenp = 0
  35.         ELSE
  36.             lenp = lenp + 1
  37.         END IF
  38.         
  39.         lastd = currentd
  40.         lastgot = gotit
  41.  
  42.         IF ABS(gg) > 4 THEN
  43.             chng = ABS(gotit - last)
  44.             IF chng > 39 THEN chng = 39
  45.             IF chng = 0 THEN
  46.                 tz0 = tz0 + 1
  47.                 lch0 = 1
  48.             ELSE
  49.                 IF lch0 = 1 THEN
  50.                     xx = 41 - tz0
  51.                     IF xx < 0 THEN xx = 0
  52.                     chgarray(xx \ 2) = chgarray(xx \ 2) + 1
  53.                     tz0 = 0
  54.                     lch0 = 0
  55.                 ELSE
  56.                     chgarray((chng + 40) \ 2) = chgarray((chng + 40) \ 2) + 1
  57.                 END IF
  58.             END IF
  59.         END IF
  60.         
  61.         at1 = at1 + 1
  62.         at = at + 1
  63.  
  64.         last = gotit
  65.         
  66.         IF at1 = 750 THEN
  67.             at1 = 0
  68.             FOR r = 0 TO 40
  69.                 xx = chgarray(r)
  70.                 chgarray(r) = 0
  71.                 IF xx > 94 THEN xx = 94
  72.  
  73.                     IF xx < 94 THEN
  74.                         FOR rr = xx + 1 TO 94
  75.                             POKE (((94 - rr) * 320) + r) * 2 + 1, &H0
  76.                         NEXT
  77.                     END IF
  78.  
  79.                     FOR rr = 0 TO xx
  80.                         POKE (((94 - rr) * 320) + r) * 2 + 1, &HF
  81.                     NEXT
  82.             NEXT
  83.         END IF
  84.  
  85.         IF at = 2500 THEN
  86.             at = 0
  87.             FOR r = 0 TO 30
  88.                 xx = peakarray(30 - r)
  89.                 peakarray(30 - r) = 0
  90.                 IF xx > 94 THEN xx = 94
  91.  
  92.                     IF xx < 94 THEN
  93.                         FOR rr = xx + 1 TO 94
  94.                             POKE (((94 - rr) * 320) + r) * 2 + 331, &H0
  95.                         NEXT
  96.                     END IF
  97.  
  98.                     FOR rr = 0 TO xx
  99.                         POKE (((94 - rr) * 320) + r) * 2 + 331, &HC
  100.                     NEXT
  101.             NEXT
  102.  
  103.         END IF
  104.     LOOP UNTIL INP(&H60) = 1    'esc pressed
  105.  
  106.     SCREEN 0
  107.  
  108.     PRINT "Realtime Frequency Analysis"
  109.     PRINT
  110.     PRINT " -based on angles from sample point to sample point (white)"
  111.     PRINT " -ie: high frequency / high volume --> high angle"
  112.     PRINT "      low frequency / low volume ----> low angle"
  113.     PRINT "                 combined with"
  114.     PRINT " -based on time between wave peaks (red)"
  115.     PRINT " -ie: high frequency / complex frequency --> high peakrate"
  116.     PRINT "      low frequency / simple frequency ----> low peakrate"
  117.     END
  118.  
  119.