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

📄 acb_parm.c

📁 手机加密通话软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright 2001,2002,2003 NAH6
 * All Rights Reserved
 *
 * Parts Copyright DoD, Parts Copyright Starium
 *
 */
#include "main.h"
#include "acb_parm.h"
#include "calc_cor_eng_adapt.h"
#include "calc_adapt_conv.h"
#include "end_correct_adapt.h"
#include "replicate_short_to_full_calc_cor_eng_adapt.h"
#include "move_array16.h"
#include <assert.h>


#if 0  /* routine now implemented in its own file */
STATIC void CalcAdaptConv(
fxpt_16 pc_imp[],
int     len_trunc,
fxpt_16 Exc[],
int     Exc_len,
fxpt_16 conv[]);
#endif

#if 0 /* now implemented in its own file */
STATIC void EndCorrectAdapt(
fxpt_16 conv[],
fxpt_16 Exc[],
int     Exc_len,
fxpt_16 pc_imp[],
int     len_trunc);
#endif

#if 0  /* Routine no longer called */
STATIC void ReplicateShortToFull(
int     delay,
fxpt_16 Conv[],
fxpt_16 FullConv[]);
#endif

#if 0  /* function now implemented in another file */
STATIC void CalcCorEngAdapt(
fxpt_16 y2[MAX_A_LEN],
fxpt_16 residual[RES_LEN],
int     ex_len,
fxpt_32 *cor,
fxpt_32 *eng);
#endif

STATIC void CompGainErrAdapt(
fxpt_32 correlation,
fxpt_32 energy,
fxpt_32 *gain,
fxpt_32 *match);

/**************************************************************************
*
* ROUTINE
*               CalcACBParms
*
* FUNCTION
*               Find ACB gain and error (match score)
*
* SYNOPSIS
*               CalcACBParms(Exc, Exc_len, pc_imp, first, delay, trunc_len,
*                       residual, gain, match)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*       Exc             fxpt_16 i       excitation vector
*       Exc_len         int     i       size of ex
*       pc_imp          fxpt_16 i       impulse response of PCs
*       first           int     i       first call flag
*       delay           int     i       pitch lag
*       trunc_len       int     i       length to truncate impulse response
*       residual        fxpt_16 i       residual from LPC analysis
*       match           fxpt_32 o       negative partial squared error
*       gain            fxpt_32 o       optimal gain for excitation vector
*
*==========================================================================
*
* DESCRIPTION
*
* (The calculations below may be valid for version 3.2, but may not be
*  correct for version 3.3).
*
*       For each delay:
*          a.  Filter excitation vector through truncated
*              impulse response of perceptual weighting filter
*              (LPC filter with bandwidth broadening).
*          b.  Correlate filtered result with residual
*          c.  Compute first order pitch filter coefficient (gain)
*              and error (match) for each lag.
*
*       Note:  Proper selection of the convolution length depends on
*              the perceptual weighting filter's expansion factor (gamma)
*              which controls the damping of the impulse response.
*
*               This is one of CELP's most computationally intensive
*               routines.  Neglecting overhead, the approximate number of
*               DSP instructions (add, multiply, multiply accumulate, or
*               compare) per second (IPS) is:
*
*               C:  convolution (recursive truncated end-point correction)
*               C': convolution (recursive truncated end-point correction)
*               R = E:  full correlation & energy
*               R'= E': delta correlation & energy
*               G:      gain quantization
*               G':     delta gain quantization
*
*               IPS = 2.34 M (for integer delays)
*
*       ACB search complexity for integer delays:
*       implicit undefined(a-z)
*
*       DSP chip instructions/operation:
*       integer MUL, ADD, SUB, MAC, MAD, CMP
*       parameter (MUL=1)       !multiply
*       parameter (ADD=1)       !add
*       parameter (SUB=1)       !subtract
*       parameter (MAC=1)       !multiply & accumulate
*       parameter (MAD=2)       !multiply & add
*       parameter (CMP=1)       !compare
*
*       CELP algorithm parameters:
*       integer L, len, K, Kp, Np, dmin
*       real F
*       parameter (L=60)        !subframe length
*       parameter (len=30)      !length to truncate calculations (<= L)
*       parameter (K=2)         !number of full search subframes
*       parameter (Kp=2)        !number of delta search subframes
*       parameter (F=30.e-3)    !time (seconds)/frame
*       parameter (Np=32)       !number of delta subframe delays
*       parameter (dmin=20)     !minimum delay
*
*       integer j
*       parameter (j=4)
*       integer N(j), i
*       real C, R, E, G, Cp, Rp, Ep, Gp, IPS
*       data N/32, 64, 128, 256/
*       print 1
*1      format(10x,'N',10x,'C',13x,'R',12x,'E',15x,'G',13x,'MIPS')
*       do i = 1, j
*          C = (len*(len+1)/2 + len*len)*MAC + (N(i)-1)*len*MAD
C     &      + min(L-dmin,N(i))*(L-dmin)*ADD + (L/2-dmin)*(L-2*dmin)*ADD
C          Cp= (len*(len+1)/2 + len*len)*MAC + (Np-1)*len*MAD
C     &      + min(L-dmin,Np)*(L-dmin)*ADD + (L/2-dmin)*(L-2*dmin)*ADD
C          R = N(i)*L*MAC
C          Rp= Np*L*MAC
C          E = R
C          Ep= Rp
C          G = N(i)*(1*CMP+1*MUL + 1*MUL)
C          Gp= Np*(1*CMP+1*MUL + 1*MUL)
C          IPS = ((C+R+E+G)*K + (Cp+Rp+Ep+Gp)*Kp)/F
C          print *,N(i),C*K/1.e6/F,R*K/1.e6/F,E*K/1.e6/F,G*K/1.e6/F,IPS/1.e6
C          print *,Np,Cp*Kp/1.e6/F,Rp*Kp/1.e6/F,Ep*Kp/1.e6/F,Gp*Kp/1.e6/F
C       end do
C       end
C
C  N          C             R            E               G             MIPS
C  32  0.3136667      0.1280000      0.1280000      6.4000003E-03   1.152133
C  32  0.3136667      0.1280000      0.1280000      6.4000003E-03
C  64  0.4630000      0.2560000      0.2560000      1.2800001E-02   1.563867
C  32  0.3136667      0.1280000      0.1280000      6.4000003E-03
C 128  0.7190000      0.5120000      0.5120000      2.5600001E-02   2.344667
C  32  0.3136667      0.1280000      0.1280000      6.4000003E-03
C 256   1.231000       1.024000       1.024000      5.1200002E-02   3.906267
C  32  0.3136667      0.1280000      0.1280000      6.4000003E-03
C
**************************************************************************
*
*       Compute gain and error:
*         NOTE: Actual MSPE = e0.e0 - gain(2*correlation-gain*energy)
*               since e0.e0 is independent of the code word,
*               minimizing MSPE is equivalent to maximizing:
*                    match = gain(2*correlation-gain*energy)   (1)
*               If unquantized gain is used, this simplifies:
*                    match = correlation*gain
*
*         NOTE: Inferior results were obtained when quantized
*               gain was used in equation (1)???
*
*         NOTE: When the delay is less than the frame length, "match"
*               is only an approximation to the actual error.
*
*       Independent (open-loop) quantization of gain and match (index):

***************************************************************************/

void CalcACBParms(
fxpt_16 Exc[],                          /* 15.0 format */
fxpt_16 pc_imp[],                       /* 3.12 format */
int     first,
int     delay,
fxpt_16 residual[RES_LEN],              /* 15.0 format */
fxpt_32 *match,                         /* 30.1 format */
fxpt_32 *gain)                          /* 17.14 format */
{
        static fxpt_32  Conv1[MAX_A_LEN];       /* 18.13 format */	/* used to be 15.0 format */
        //fxpt_16               FullConv[MAX_A_LEN];
        fxpt_32         correlation, energy;


FXPT_PUSHSTATE("CalcACBParms", -1.0, -1.0);
        if (first) {
                /* Calculate and save convolution of truncated impulse
                 * response for first delay
                 */
                CalcAdaptConv(pc_imp, Exc, Conv1);
        }
        else {
                /* End correct the convulution sum on subsequent delays */
                EndCorrectAdapt(Conv1, Exc, pc_imp);
        }

        if (delay < SF_LEN) {  /* this conditional is a "DaveH" optimization */
          /* For lags shorter than frame size, replicate the short adaptive
           * codeword to the full codeword length
           */
          ReplicateShortToFullCalCorEngAdapt(delay, Conv1, residual, &correlation, &energy);

          /* Calculate Correlation and Energy */
          //CalcCorEngAdapt(FullConv, residual, &correlation, &energy);
        }
        else {
          CalcCorEngAdapt(Conv1, residual, &correlation, &energy);
        }

LOGFIXED(1,correlation);
LOGFIXED(1,energy);

        /* Compute gain and match score */
        CompGainErrAdapt(correlation, energy, gain, match);

FXPT_POPSTATE();
}

/**************************************************************************
*
* ROUTINE
*               CalcAdaptConv
*
* FUNCTION
*               Calculate and save convolution of truncated impulse
*               response.
* SYNOPSIS
*               CalcAdaptConv(pc_imp, len_trunc, Exc, Exc_len, conv);
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*       pc_imp          fxpt_16  i      Impulse response of PCs
*       len_trunc       int      i      Length to truncate impulse response
*       Exc             fxpt_16  i      Excitation vector

⌨️ 快捷键说明

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