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

📄 encode.dsp

📁 用AD的16位定点DSP作音频压缩器
💻 DSP
字号:
.module/boot=4        encode_parameters; 

{ ENCODE.DSP - truncates/compresses  the lpc parameters.

  INPUT:
     i1 -> k  (reflection coeffs) l1 = 0
     ar =  pitch
     si =  gain     
  
  OUTPUT:
     k's encoded inplace       
     ar =  pitch
     si =  gain     
  
  The parameters are truncated into the required nr of bits,
  either by linearly (gain) or logarithmic (k's) quantization.

  Logarithmic:   g[i] = log10((1+k[i])/(1-k[i]))/4

}
#include "lpc.h"

.const  LOG_ORDER = 8; 
.var/pm log_coeffs[2*LOG_ORDER]; {Ci lsb, Ci msb, Ci-1 lsb .....}
.init   log_coeffs: <log.cff>;   {scaled down by 512 = 2^9}

.const  LAR_ORDER = 16; 
.var/pm lar_coeffs[2*LAR_ORDER]; {Ci lsb, Ci msb, Ci-1 lsb .....}
.init   lar_coeffs: <enc.cff>;   {scaled down by 512 = 2^9}

.var/pm round[WORDS_PR_LPCFRAME];
.init   round: 
               0x000900, {pitch,  7 bit, (9=16-7) shifting NOT rounding}
               0x000600, {gain,   6 bit}
               0x000600, {k1,     6 bit}
               0x000600, {k2,     6 bit}
               0x000500, {k3,     5 bit}
               0x000500, {k4,     5 bit}
               0x000400, {k5,     4 bit}
               0x000400, {k6,     4 bit}
               0x000300, {k7,     3 bit}
               0x000300, {k8,     3 bit}
               0x000300, {k9,     3 bit}
               0x000200; {k10,    2 bit}
                         {      -------
                                 54 bit/frame
                                =============}

.var/dm   temp_pitch;
.var/dm   temp_gain;

.entry    encode;

.external poly_approx;

encode:

  {encode parameters}
    i4 = ^round;       l4 = 0;
    
     {ar = pitch}
    se = pm(i4,m5); {nr of bits to shift}
    sr = lshift ar (lo);
    dm(temp_pitch) = sr0;

     {si = gain}
    sr0 = si;
    ar  = pass sr0;
    if eq jump zero_gain;    
      my0 = 0x0000; {gain lsb}
      my1 = si;     {gain msb}
      ax0 = LOG_ORDER - 1;
      i6  = ^log_coeffs;   l6 = 0;
      call poly_approx;  {log10 function}
      si = mx0;
      sr = lshift si by 9 (lo);  {scale up by 512, comes with the coeff's}
      sr = sr or ashift ar by 9 (hi);
      si = sr1;
      se = pm(i4,m5); {nr of bits to round to}
      call do_round;
    zero_gain:
    dm(temp_gain) = sr0;

    cntr = 2 {N};
    do enc2_k until ce;
      my0 = 0x0000;    {k lsb}
      my1 = dm(i1,m0); {k msb}
      ax0 = LAR_ORDER - 1;
      i6  = ^lar_coeffs;   l6 = 0;
      call poly_approx;  {log area ratio function}
      si = mx0;
      sr = lshift si by 9 (lo);  {scale up by 512, comes with the coeff's}
      sr = sr or ashift ar by 9 (hi);
      si = sr1;
      se = pm(i4,m5);
      call do_round;
    enc2_k:  dm(i1,m1) = sr0;

    cntr = N-2;
    do enc_k until ce;
      si = dm(i1,m0); 
      se = pm(i4,m5);           
      call do_round;
    enc_k:  dm(i1,m1) = sr0;

   {setup return parameters}
   ar = dm(temp_pitch);
   si = dm(temp_gain);

    
rts;
    
    { ROUNDING routine

     Input  si = value to be rounded
            se = nr of bits to round to

     Output sr0 = rounded value}

do_round:
  
  sr  = ashift si (lo);
  mr0 = sr0;
  mr1 = sr1;
  mr  = mr (rnd), ay0 = se;
  ar  = -ay0;
  se  = ar;
  sr  = ashift mr1 (hi);

rts;


.endmod;

⌨️ 快捷键说明

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