home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / pas_sdk1 / pas / subs / misc / histo.asm < prev    next >
Encoding:
Assembly Source File  |  1992-06-23  |  6.3 KB  |  275 lines

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