home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / PASSDK30.ZIP;1 / DISK1.ZIP / PAS / SUBS / MISC / HISTO.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-10-20  |  6.4 KB  |  282 lines

  1. ;$Author:   DCODY  $
  2. ;$Date:   20 Oct 1992 09:59:26  $
  3. ;$Header:   X:/sccs/misc/histo.asv   1.2   20 Oct 1992 09:59:26   DCODY  $
  4. ;$Log:   X:/sccs/misc/histo.asv  $
  5. ;  
  6. ;     Rev 1.2   20 Oct 1992 09:59:26   DCODY
  7. ;  adjusted tiny model .data declaration
  8. ;  
  9. ;     Rev 1.1   23 Jun 1992 16:32:18   DCODY
  10. ;  PAS2 update
  11. ;  
  12. ;     Rev 1.0   15 Jun 1992 09:39:52   BCRANE
  13. ;  Initial revision.
  14. ;$Logfile:   X:/sccs/misc/histo.asv  $
  15. ;$Modtimes$
  16. ;$Revision:   1.2  $
  17.  
  18.     Title Media Vision Histogram routines
  19.     page    64,131
  20.  
  21. ;   /*\
  22. ;---|*|----====< HISTO.ASM >====----
  23. ;---|*|
  24. ;---|*| These routines create a histogram from the block of PCM samples
  25. ;---|*|
  26. ;---|*| MakeHistoGram      (char far *, int-1, int-2)
  27. ;---|*| MakeHalfHistoGram (char far *, int-1, int-2)
  28. ;---|*|
  29. ;---|*|   char far * (wParm1) is the buffer pointer
  30. ;---|*|   int-1      (wParm2) is the buffer length in bytes
  31. ;---|*|   int-2      (wParm3) is the offset from the center line to accumulate
  32. ;---|*|
  33. ;---|*| The Return value is the count of samples over the offset
  34. ;---|*|
  35. ;   \*/
  36.  
  37.     .xlist
  38.     include model.inc
  39.         include masm.inc
  40. ;;;;;;;;include target.inc
  41.         .list
  42.  
  43. if MODELSIZE eq 0
  44.     .code
  45. else
  46.     .data
  47. endif
  48.  
  49.     public    HistoGram256
  50. HistoGram256    dw    256 dup(0)    ; 256 word table for histogram accum
  51.  
  52.     extrn    __pcmdatasize:byte    ; data size - 8 or 16 bit PCM
  53.  
  54.     .code
  55.  
  56. ;   /*\
  57. ;---|*|------------------=============================------------------
  58. ;---|*|------------------====< MakeHalfHistoGram >====------------------
  59. ;---|*|------------------=============================------------------
  60. ;   \*/
  61. ;
  62. ;   This routine folds the high order samples into the low order, via
  63. ;   ones compliment. Since it uses ones compliment, the folded values
  64. ;   will shift down one value (an effective increase in aplituded by
  65. ;   a factor of 1/256). The benefit is a faster accumulation. This
  66. ;   routine is used to find how many samples pass the threshold of noise.
  67. ;   This "noise" is wParm3, the offset from the center line.
  68. ;
  69.         public MakeHalfHistoGram
  70. MakeHalfHistoGram proc
  71.     push    bp
  72.     mov    bp,sp
  73. ;
  74. ; save the critcals
  75. ;
  76.     push    es
  77.     push    di
  78.     push    si
  79. ;
  80. ; flush the table
  81. ;
  82.     push    ds            ; clear the block
  83.     pop    es
  84.     lea    di,HistoGram256
  85.     sub    ax,ax
  86.     mov    cx,100h
  87.     cld
  88.     rep    stosw
  89.     lea    di,HistoGram256     ; es:di point to the table
  90. ;
  91. ; get the two parameters
  92. ;
  93.     if @datasize
  94.     les    si,wParm1        ; get the target buffer pointer
  95.     mov    cx,wParm3        ; get the buffer length
  96.     else
  97.     mov    si,wParm1        ; get the target buffer pointer
  98.     mov    cx,wParm2        ; get the buffer length
  99.     endif
  100. ;
  101. ; handle the 16 bit data as 8 bit
  102. ;
  103.     sub    dx,dx            ; dx has an XOR mask to convert 16 to 8
  104.     cmp    __pcmdatasize,8     ; 8 bit data?
  105.     jz    @F            ; yes, continue on...
  106.         mov     dx,0180h                ; to flip the data byte to 8 bits
  107.     shr    cx,1            ; cut the buffer in half
  108.     inc    si            ; point to the most significant byte
  109.     ;
  110.     @@:
  111. ;
  112. ; make the histogram
  113. ;
  114. mhhg05:
  115.     if @datasize
  116.     lods    byte ptr es:[si]    ; get the next byte of data
  117.     else
  118.     lodsb
  119.     endif
  120.  
  121.     neg    dh            ; set the carry if 16 bit data
  122.     adc    si,0            ; adjust si to the next high byte
  123.     xor    al,dl            ; if 16 bit data, convert to 8 bit
  124.  
  125.     cbw                ; if al > 7f, do a 1s compliment
  126.     xor    al,ah
  127.     cbw                ; clear ah
  128.  
  129.         mov     bx,ax
  130.     add    bx,ax
  131.     inc    wptr [di+bx]        ; increment the word
  132.  
  133.         loop    mhhg05
  134.     mov    bx,cx            ; clear bx
  135. ;
  136. ; count all the entries starting at the offset
  137. ;
  138.     mov    cl,80h
  139.     if @datasize
  140.     sub    cl,bptr wParm4        ; cx holds the count
  141.     else
  142.         sub     cl,bptr wParm3          ; cx holds the count
  143.     endif
  144.     lea    si,HistoGram256     ; si points to the start of the table
  145. ;
  146. mhhg20:
  147.     lodsw
  148.     add    bx,ax
  149.     loop    mhhg20
  150.  
  151.     mov    ax,bx            ; return the count
  152. ;
  153. ; all done, exit home...
  154. ;
  155.     pop    si
  156.     pop    di
  157.     pop    es
  158.     pop    bp
  159.     ret
  160.  
  161. MakeHalfHistoGram endp
  162.  
  163. ;   /*\
  164. ;---|*|---------------------=========================---------------------
  165. ;---|*|---------------------====< MakeHistoGram >====---------------------
  166. ;---|*|---------------------=========================---------------------
  167. ;   \*/
  168. ;
  169. ;   This routine builds a full histogram of the caller's buffer.
  170. ;
  171.         public   MakeHistoGram
  172. MakeHistoGram    proc
  173.     push    bp
  174.     mov    bp,sp
  175. ;
  176. ; save the critcals
  177. ;
  178.     push    es
  179.     push    di
  180.     push    si
  181. ;
  182. ; flush the table
  183. ;
  184.         push    ds                      ; clear the block
  185.     pop    es
  186.     lea    di,HistoGram256
  187.     sub    ax,ax
  188.     mov    cx,100h
  189.     cld
  190.     rep    stosw
  191.     lea    di,HistoGram256     ; es:di point to the table
  192. ;
  193. ; get the two parameters
  194. ;
  195.     if @datasize
  196.     les    si,wParm1        ; get the target buffer pointer
  197.     mov    cx,wParm3        ; get the buffer length
  198.     else
  199.     mov    si,wParm1        ; get the target buffer pointer
  200.     mov    cx,wParm2        ; get the buffer length
  201.     endif
  202. ;
  203. ; handle the 16 bit data as 8 bit
  204. ;
  205.         sub     dx,dx                   ; dx has an XOR mask to convert 16 to 8
  206.     cmp    __pcmdatasize,8     ; 8 bit data?
  207.     jz    @F            ; yes, continue on...
  208.         mov     dx,0180h                ; to flip the data byte to 8 bits
  209.     shr    cx,1            ; cut the buffer in half
  210.     inc    si            ; point to the most significant byte
  211.     ;
  212.     @@:
  213. ;
  214. ; make the histogram
  215. ;
  216. mhg05:
  217.     if @datasize
  218.     lods    byte ptr es:[si]
  219.     else
  220.     lodsb
  221.     endif
  222.  
  223.     neg    dh            ; set the carry if 16 bit data
  224.     adc    si,0            ; adjust si to the next high byte
  225.     xor    al,dl            ; if 16 bit data, convert to 8 bit
  226.  
  227.         mov     bx,ax
  228.     shl    bx,1
  229.     inc    wptr [di+bx]
  230.         loop    mhg05
  231. ;
  232. ; count all high entries based upon the offset
  233. ;
  234.     if @datasize
  235.     sub    cl,bptr wParm4        ; cx holds the count
  236.     else
  237.         sub     cl,bptr wParm3          ; cx holds the count
  238.     endif
  239.     lea    si,HistoGram256     ; si points to the start of the table
  240.     add    si,100h         ; move to the centerline
  241.     add    si,cx            ; adjust to the starting index
  242.     add    si,cx
  243.     sub    cx,80h            ; cx will hold an index from 80h to ffh
  244.     neg    cx
  245.     and    cx,07fh         ; make sure its valid
  246.     sub    bx,bx            ; bx holds the accumulated value
  247. ;
  248. mhg10:
  249.     lodsw
  250.     add    bx,ax
  251.     loop    mhg10
  252. ;
  253. ; count all the low entries based upon the offset
  254. ;
  255.     mov    cl,80h
  256.     if @datasize
  257.     sub    cl,bptr wParm4        ; cx holds the count
  258.     else
  259.         sub     cl,bptr wParm3          ; cx holds the count
  260.     endif
  261.         lea     si,HistoGram256         ; si points to the start of the table
  262. ;
  263. mhg20:
  264.     lodsw
  265.     add    bx,ax
  266.     loop    mhg20
  267.  
  268.     mov    ax,bx            ; return the count
  269. ;
  270. ; all done, exit home...
  271. ;
  272.     pop    si
  273.     pop    di
  274.     pop    es
  275.     pop    bp
  276.     ret
  277.  
  278. MakeHistoGram    endp
  279. ;
  280.         end
  281. ;
  282.