⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voipadpcm.asm

📁 Cypress 的VOIP DEMO 研究VOIP终端的朋友可以研究研究
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;;------------------------------------------------------------------
;;
;; TABLES GIVE 15-BIT PCM TO 4-BIT ADPCM
;;
;;------------------------------------------------------------------


export   adpcmEncode
export   adpcmDecode

include "memory.inc"
include "voip.inc"
include "voipAdpcm.inc"
 

area InterruptRAM (RAM, REL, CON)
_AdpcmSpace:
_bEncStepSizePtr::	BLK 1
_iEncPredict::		BLK 2
_bDecStepSizePtr::	BLK 1
_iDecPredict::		BLK 2
_iDiff:			BLK 2	; Scratchpad 
_iStep:			BLK 2	; Scratchpad

area UserModules (ROM, REL)   
.literal
StepSizeTableHB: ;Step Size Values in about 10% increments
    db   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db   0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  3
    db   3,  3,  4,  4,  4,  5,  5,  6,  7,  7,  8,  9, 10, 11, 12, 13
    db  15, 16, 18, 20, 22, 24, 27, 29, 32, 36, 39, 43, 48, 52, 58, 63
StepSizeTableLB:
    db   4,  5,  6,  7,  8,  9, 10, 12, 14, 16, 18, 20, 23, 26, 29, 32
    db  36, 40, 44, 49, 54, 60, 66, 73, 81, 90,100,110,122,135,149,164
    db 181,200,220,242, 11, 38, 68,101,137,177,221, 13, 66,124,188,  3
    db  81,166,  4,107,221, 90,228,123, 33,216,161,126,114,126,165,233
    db  78,214,134, 97,107,169, 33,216,213, 30,187,181, 20,227, 45,255
.endliteral

.SECTION
;;------------------------------------------------------------------
;;  _bEncode: 335 CPU cycles (lcall included)
;;  X,A is the new data that is used with iPredict and bStepSizeTablePtr to
;;  calculate the compressed value.  It also:
;;
;;     Calculates a next iPredict
;;     Calculate a new pStepSizeTable
;;
;;  The compressed value is returned in A
;;-----------------------------------------------------------------
adpcmEncode:
;    RAM_PROLOGUE  RAM_USE_CLASS_4
;    RAM_SETPAGE_CUR (>_Space)
    sub   A, [_iEncPredict + LSB]	; iDiffLow = Input-iEncodePredict
    mov   [_iDiff + LSB], A
    mov   A, X
    sbb   A, [_iEncPredict + MSB]
    mov   [_iDiff + MSB], A
    mov   A, [_bEncStepSizePtr]		; iStep =f(iStepPtr)
    mov   X, A
    index StepSizeTableLB
    mov   [_iStep + LSB], A
    mov   A, X
    index StepSizeTableHB
    mov   [_iStep + MSB], A
    cmp   [_iDiff + MSB], 128               
    jnc   Nxxx

   Pxxx:
      PosDiffMinusStep			; iDiff -= iStep
      jnc  P0xx
      P1xx: 
         ShiftStepRight			; iStep = iStep/2
         PosDiffMinusStep		; iDiff -= iStep
         jnc  P10x
         P11x:
            ShiftStepRight		; iStep = iStep/4
            PosDiffMinusStepCmp		; iDiff - iStep
            jnc  P110
            P111:
               UpdateEncodePos  Table7		; New Predict Value
               IncrementSP _bEncStepSizePtr,8	; Adjust StepSizePtr
               mov   A, 7			; return(7)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
            P110:
               UpdateEncodePos  Table6		; New Predict Value
               IncrementSP _bEncStepSizePtr,6	; Adjust StepSizePtr
               mov   A, 6			; return(6)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
         P10x:
            ShiftStepRight			; iStep = iStep/4
            PosDiffPlusStepCmp			; iDiff +c iStep?
            jnc  P100
            P101:
               UpdateEncodePos  Table5		; New Predict Value
               IncrementSP  _bEncStepSizePtr,4	; Adjust StepSizePtr
               mov   A,5			; return(5)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
            P100:
               UpdateEncodePos  Table4		;New Predict Value
               IncrementSP  _bEncStepSizePtr,2	;Adjust StepSizePtr
               mov   A,4			; return(4)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
      P0xx:
         ShiftStepRight				; iStep = iStep/2
         PosDiffPlusStep			; iDiff +c= iStep
         jnc  P00x
         P01x:
            ShiftStepRight			; iStep = iStep/4
            PosDiffMinusStepCmp			; iDiff -= iStep
            jnc  P010
            P011:
               UpdateEncodePos  Table3		; New Predict Value
               DecrementSP  _bEncStepSizePtr	; Adjust StepSizePtr
               mov   A,3			; return(3)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
            P010:
               UpdateEncodePos  Table2		; New Predict Value
               DecrementSP  _bEncStepSizePtr	; Adjust StepSizePtr
               mov   A,2			; return(2)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
         P00x:
            ShiftStepRight			; iStep = iStep/4
            PosDiffPlusStepCmp			; iDiff +c= iStep
            jnc  P000
            P001:
               UpdateEncodePos  Table1		; New Predict Value
               DecrementSP  _bEncStepSizePtr	; Adjust StepSizePtr
               mov   A,1			; return(1)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
            P000:
               UpdateEncodePos  Table0		; New Predict Value
               DecrementSP  _bEncStepSizePtr	; Adjust StepSizePtr
               mov   A,0			; return(0)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
   Nxxx:
      dec [_iDiff + LSB]			; iDiff--
      sbb [_iDiff + MSB],0
      NegDiffPlusStep			; iDiff = iStep
      jc  N0xx
      N1xx:
         ShiftStepRight			; iStep = iStep/2
         NegDiffPlusStep		; iDiff += iStep 
         jc  N10x
         N11x:
            ShiftStepRight		; iStep = iStep/4
            NegDiffPlusStepCmp		; iDiff + iStep?
            jc  N110
            N111:
               UpdateEncodeNeg  Table7	; New Predict Value
               IncrementSP  _bEncStepSizePtr,8	; Adjust StepSizePtr
               mov   A,(8+7)			; return(15)
;               RAM_EPILOGUE RAM_USE_CLASS_4
            ret
            N110:
               UpdateEncodeNeg  Table6		; New Predict Value
               IncrementSP  _bEncStepSizePtr,6	; Adjust StepSizePoint
               mov   A,(8+6)			; return(14)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
         N10x:
            ShiftStepRight			; iStep = iStep/4
            NegDiffPlusStepCmp			; iDiff -b= iStep
            jc  N100
            N101:
               UpdateEncodeNeg  Table5		; New Predict Value
               IncrementSP  _bEncStepSizePtr,4	; Adjust StepSizePoint
               mov   A,(8+5)			; return(13)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
            N100:
               UpdateEncodeNeg  Table4		; New Predict Value
               IncrementSP  _bEncStepSizePtr,2	; Adjust StepSizePoint
               mov   A,(8+4)			; return(12)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
      N0xx:
         ShiftStepRight				; iStep = iStep/2
         NegDiffMinusStep			; iDiff -b= iStep
         jc N00x
            N01X:
            ShiftStepRight			; iStep = iStep/4
            NegDiffPlusStepCmp			; iDiff + iStep?
            jc  N010
            N011:
               UpdateEncodeNeg  Table3		; New Predict Value
               DecrementSP  _bEncStepSizePtr	; Adjust StepSizePoint
               mov   A,(8+3)			; return(11)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
            N010:
               UpdateEncodeNeg  Table2		; New Predict Value
               DecrementSP  _bEncStepSizePtr	; Adjust StepSizePoint
               mov   A,(8+2)			; return(10)
;               RAM_EPILOGUE RAM_USE_CLASS_4
               ret
         N00x:
            ShiftStepRight			; iStep = iStep/4
            NegDiffMinusStep			; iDiff -b iStep?
            jc N000
            N001:
               UpdateEncodeNeg  Table1		; New Predict Value
               DecrementSP  _bEncStepSizePtr	; Adjust StepSizePoint
               mov   A,(8+1)			; return(9)
;               RAM_EPILOGUE RAM_USE_CLASS_4	; 207
               ret
         N000:
            UpdateEncodeNeg  Table0		; New Predict Value; 210
            DecrementSP  _bEncStepSizePtr	; Adjust StepSizePoint; 211
            mov A,(8+0)				; return(8); 212
;            RAM_EPILOGUE RAM_USE_CLASS_4
            ret
.ENDSECTION
.literal
   Table0:
   Table0HB:

    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1
    db      1,  2,  2,  2,  2,  3,  3,  3,  4,  4,  4,  5,  6,  6,  7,  7
   Table0LB:
    db      0,  0,  0,  0,  1,  1,  1,  1,  1,  2,  2,  2,  2,  3,  3,  4
    db      4,  5,  5,  6,  6,  7,  8,  9, 10, 11, 12, 13, 15, 16, 18, 20
    db     22, 25, 27, 30, 33, 36, 40, 44, 49, 54, 59, 65, 72, 79, 87, 96
    db    106,116,128,141,155,171,188,207,228,251, 20, 47, 78,111,148,189
    db    233, 26, 80,140,205, 21,100,187, 26,131,247,118,  2,156, 69,255
   Table1:
   Table1HB:
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1
    db      1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  3,  3,  3,  4,  4,  5
    db      5,  6,  6,  7,  8,  9, 10, 11, 12, 13, 14, 16, 18, 19, 21, 23
   Table1LB:
    db      1,  1,  1,  1,  3,  3,  3,  4,  4,  6,  6,  7,  7,  9, 10, 12
    db     13, 15, 16, 18, 19, 22, 24, 27, 30, 33, 37, 40, 45, 49, 55, 61
    db     67, 75, 82, 90, 99,109,121,133,147,162,178,196,216,238,  6, 32
    db     62, 93,129,167,210,  1, 53,109,172,241, 60,142,234, 78,189, 55
    db    188, 79,241,164,103, 63, 44, 49, 79,138,229, 99,  7,212,208,254
   Table2:
   Table2HB:
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1
    db      2,  2,  2,  2,  3,  3,  3,  4,  4,  4,  5,  5,  6,  7,  7,  8
    db      9, 10, 11, 12, 14, 15, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39

   Table2LB:
    db      2,  2,  3,  3,  5,  5,  6,  7,  8, 10, 11, 12, 13, 16, 17, 20
    db     22, 25, 27, 30, 33, 37, 41, 45, 50, 56, 62, 68, 76, 83, 92,102
    db    112,125,137,151,166,183,202,222,245, 14, 41, 71,105,141,181,225
    db     18, 71,130,194,  9, 88,174, 12,116,231,100,238,135, 46,230,177
    db    144,133,147,188,  2,105,244,167,132,146,212, 80, 12, 13, 91,254


Table3:
   Table3HB:
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
    db      0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2
    db      2,  3,  3,  3,  4,  4,  5,  5,  6,  6,  7,  8,  9, 10, 11, 12
    db     13, 14, 16, 17, 19, 21, 23, 26, 28, 31, 34, 38, 42, 46, 50, 55
   Table3LB:
    db      3,  3,  4,  4,  7,  7,  8, 10, 11, 14, 15, 17, 18, 22, 24, 28
    db     31, 35, 38, 42, 46, 52, 57, 63, 70, 78, 87, 95,106,116,129,143
    db    157,175,192,211,232,  0, 27, 55, 87,122,160,202,249, 44,100,161
    db    230, 48,131,220, 64,174, 39,170, 60,221,140, 77, 35, 13, 15, 43
    db     99,186, 52,212,156,147,188, 29,185,153,194, 61, 17, 69,230,253

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -