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

📄 g7231_lsp.c

📁 G723.1语音压缩解压在tms320c54系列上的实现代码,本人已在CCS上仿真通过. 包含全部源代码,主函数请自已写(本人的就不奉送了:
💻 C
📖 第 1 页 / 共 2 页
字号:
  * constant component removed.
  */
            for ( j = 0 ; j < G7231BandInfoTable[k][1] ; j ++ )
                Tmp[j] = G7231mult_r( Wvect[G7231BandInfoTable[k][0]+j],
                                                            LspQntPnt[j] ) ;

            Acc0 = (Word32) 0 ;
            for ( j = 0 ; j < G7231BandInfoTable[k][1] ; j ++ )
                Acc0 = G7231L_mac( Acc0, Tv[G7231BandInfoTable[k][0]+j], Tmp[j] ) ;
            Acc0 = G7231L_shl( Acc0, (Word16) 1 ) ;
            for ( j = 0 ; j < G7231BandInfoTable[k][1] ; j ++ )
                Acc0 = G7231L_msu( Acc0, LspQntPnt[j], Tmp[j] ) ;

            LspQntPnt += G7231BandInfoTable[k][1] ;

 /*
  * Compare the metric to the previous maximum and select the
  * new index
  */
            if ( Acc0 > Acc1 ) {
                Acc1 = Acc0 ;
                Indx = (Word32) i ;
            }
        }

 /*
  * Pack the result with the optimum index for this band
  */
        Rez = G7231L_shl( Rez, (Word16) G7231LspCbBits ) ;
        Rez = G7231L_add( Rez, Indx ) ;
    }

    return Rez ;
}

void G7231Lsp_Inq( Word16 *Lsp, Word16 *PrevLsp, Word32 LspId, Word16 Crc )
{
    int  i,j   ;

    Word16  *LspQntPnt  ;


    Word16   Scon  ;
    Word16   Lprd  ;

    Word16   Tmp   ;
    Flag     Test  ;


 /*
  * Check for frame erasure.  If a frame erasure has occurred, the
  * resulting VQ table entries are zero.  In addition, a different
  * fixed predictor and minimum frequency separation are used.
  */
    if ( Crc == (Word16) 0 ) {
        Scon = (Word16) 0x0100 ;
        Lprd = G7231LspPrd0 ;
    }
    else {
        LspId = (Word32) 0 ;
        Scon = (Word16) 0x0200 ;
        Lprd = G7231LspPrd1 ;
    }


 /*
  * Inverse quantize the 10th-order LSP vector.  Each band is done
  * separately.
  */
    for ( i = G7231LspQntBands-1; i >= 0 ; i -- ) {

 /*
  * Get the VQ table entry corresponding to the transmitted index
  */
        Tmp = (Word16) ( LspId & (Word32) 0x000000ff ) ;
        LspId >>= 8 ;

        LspQntPnt = G7231BandQntTable[i] ;

        for ( j = 0 ; j < G7231BandInfoTable[i][1] ; j ++ )
            Lsp[G7231BandInfoTable[i][0] + j] =
                                LspQntPnt[Tmp*G7231BandInfoTable[i][1] + j] ;
    }

 /*
  * Subtract the DC component from the previous frame's quantized
  * vector
  */
    for ( j = 0 ; j < G7231LpcOrder ; j ++ )
        PrevLsp[j] = G7231sub(PrevLsp[j], G7231LspDcTable[j] ) ;

 /*
  * Generate the prediction vector using a fixed first-order
  * predictor based on the previous frame's (DC-free) quantized
  * vector
  */
    for ( j = 0 ; j < G7231LpcOrder ; j ++ ) {
        Tmp = G7231mult_r( PrevLsp[j], Lprd ) ;
        Lsp[j] = G7231add( Lsp[j], Tmp ) ;
    }

 /*
  * Add the DC component back to the previous quantized vector,
  * which is needed in later routines
  */
    for ( j = 0 ; j < G7231LpcOrder ; j ++ ) {
        PrevLsp[j] = G7231add( PrevLsp[j], G7231LspDcTable[j] ) ;
        Lsp[j] = G7231add( Lsp[j], G7231LspDcTable[j] ) ;
    }


 /*
  * Perform a stability test on the quantized LSP frequencies.  This
  * test checks that the frequencies are ordered, with a minimum
  * separation between each.  If the test fails, the frequencies are
  * iteratively modified until the test passes.  If after 10
  * iterations the test has not passed, the previous frame's
  * quantized LSP vector is used.
  */
    for ( i = 0 ; i < G7231LpcOrder ; i ++ ) {

        /* Check the first frequency */
        if ( Lsp[0] < (Word16) 0x180 )
            Lsp[0] = (Word16) 0x180 ;

        /* Check the last frequency */
        if ( Lsp[G7231LpcOrder-1] > (Word16) 0x7e00 )
            Lsp[G7231LpcOrder-1] = (Word16) 0x7e00 ;

        /* Perform the modification */
        for ( j = 1 ; j < G7231LpcOrder ; j ++ ) {

            Tmp = G7231add( Scon, Lsp[j-1] ) ;
            Tmp = G7231sub( Tmp, Lsp[j] ) ;
            if ( Tmp > (Word16) 0 ) {
                Tmp = G7231shr( Tmp, (Word16) 1 ) ;
                Lsp[j-1] = G7231sub( Lsp[j-1], Tmp ) ;
                Lsp[j] = G7231add( Lsp[j], Tmp ) ;
            }
        }

        Test = False ;

 /*
  * Test the modified frequencies for stability.  Break out of
  * the loop if the frequencies are stable.
  */
        for ( j = 1 ; j < G7231LpcOrder ; j ++ ) {
            Tmp = G7231add( Lsp[j-1], Scon ) ;
            Tmp = G7231sub( Tmp, (Word16) 4 ) ;
            Tmp = G7231sub( Tmp, Lsp[j] ) ;
            if ( Tmp > (Word16) 0 )
                Test = True ;
        }

        if ( Test == False )
            break ;
    }


 /*
  * Return the result of the stability check.  True = not stable,
  * False = stable.
  */
    if ( Test == True) {
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Lsp[j] = PrevLsp[j] ;
    }

    return;
}

void  G7231Lsp_Int( Word16 *QntLpc, Word16 *CurrLsp, Word16 *PrevLsp )
{
    int   i,j   ;

    Word16   Tmp   ;
    Word16  *Dpnt  ;

    Word32   Acc0  ;


 /*
  * Initialize the interpolation factor
  */
    Tmp = (Word16) (G7231MIN_16 / G7231SubFrames ) ;

    Dpnt = QntLpc ;


 /*
  * Do for all subframes
  */
    for ( i = 0 ; i < G7231SubFrames ; i ++ ) {

 /*
  * Compute the quantized LSP frequencies by linear interpolation
  * of the frequencies from subframe 3 of the current and
  * previous frames
  */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ ) {
            Acc0 = G7231L_deposit_h( PrevLsp[j] ) ;
            Acc0 = G7231L_mac( Acc0, Tmp, PrevLsp[j] ) ;
            Acc0 = G7231L_msu( Acc0, Tmp, CurrLsp[j] ) ;
            Dpnt[j] = G7231round( Acc0 ) ;
        }

 /*
  * Convert the quantized LSP frequencies to quantized LPC
  * coefficients
  */
        G7231LsptoA( Dpnt ) ;
        Dpnt += G7231LpcOrder ;

        /* Update the interpolation factor */
        Tmp = G7231add( Tmp, (Word16) (G7231MIN_16 / G7231SubFrames ) ) ;
    }

}

void  G7231LsptoA( Word16 *Lsp )
{
    int   i,j   ;

    Word32   Acc0,Acc1   ;
    Word16   Tmp ;

    Word32   P[G7231LpcOrder/2+1] ;
    Word32   Q[G7231LpcOrder/2+1] ;


 /*
  * Compute the cosines of the LSP frequencies by table lookup and
  * linear interpolation
  */
    for ( i = 0 ; i < G7231LpcOrder ; i ++ ) {

 /*
  * Do the table lookup using bits [15:7] of the LSP frequency
  */
        j = (int) G7231shr( Lsp[i], (Word16) 7 ) ;
        Acc0 = G7231L_deposit_h( G7231CosineTable[j] ) ;

        Tmp = G7231sub(G7231CosineTable[j+1], G7231CosineTable[j] ) ;
        Acc0 = G7231L_mac( Acc0, Tmp, G7231add( G7231shl( (Word16)(Lsp[i] & 0x007f) ,
                                (Word16)8 ), (Word16) 0x0080 ) ) ;
        Acc0 = G7231L_shl( Acc0, (Word16) 1 ) ;
        Lsp[i] = G7231negate( G7231round( Acc0 ) ) ;
    }

    P[0] = (Word32) 0x10000000L ;
    P[1] = G7231L_mult( Lsp[0], (Word16) 0x2000 ) ;
    P[1] = G7231L_mac( P[1], Lsp[2], (Word16) 0x2000 ) ;
    P[2] = G7231L_mult( Lsp[0], Lsp[2] ) ;
    P[2] = G7231L_shr( P[2], (Word16) 1 ) ;
    P[2] = G7231L_add( P[2], (Word32) 0x20000000L ) ;

    Q[0] = (Word32) 0x10000000L ;
    Q[1] = G7231L_mult( Lsp[1], (Word16) 0x2000 ) ;
    Q[1] = G7231L_mac( Q[1], Lsp[3], (Word16) 0x2000 ) ;
    Q[2] = G7231L_mult( Lsp[1], Lsp[3] ) ;
    Q[2] = G7231L_shr( Q[2], (Word16) 1 ) ;
    Q[2] = G7231L_add( Q[2], (Word32) 0x20000000L ) ;

    for ( i = 2 ; i < G7231LpcOrder/2 ; i ++ ) {

        /* Compute coefficient (i+1) */
        Acc0 = P[i] ;
        Acc0 = G7231L_mls( Acc0, Lsp[2*i+0] ) ;
        Acc0 = G7231L_add( Acc0, P[i-1] ) ;
        P[i+1] = Acc0 ;

        Acc1 = Q[i] ;
        Acc1 = G7231L_mls( Acc1, Lsp[2*i+1] ) ;
        Acc1 = G7231L_add( Acc1, Q[i-1] ) ;
        Q[i+1] = Acc1 ;

        /* Compute coefficients i, i-1, ..., 2 */
        for ( j = i ; j >= 2 ; j -- ) {
            Acc0 = P[j-1] ;
            Acc0 = G7231L_mls( Acc0, Lsp[2*i+0] ) ;
            Acc0 = G7231L_add( Acc0, G7231L_shr(P[j], (Word16) 1 ) ) ;
            Acc0 = G7231L_add( Acc0, G7231L_shr(P[j-2], (Word16) 1 ) ) ;
            P[j] = Acc0 ;

            Acc1 = Q[j-1] ;
            Acc1 = G7231L_mls( Acc1, Lsp[2*i+1] ) ;
            Acc1 = G7231L_add( Acc1, G7231L_shr(Q[j], (Word16) 1 ) ) ;
            Acc1 = G7231L_add( Acc1, G7231L_shr(Q[j-2], (Word16) 1 ) ) ;
            Q[j] = Acc1 ;
        }

        /* Compute coefficients 1, 0 */
        P[0] = G7231L_shr( P[0], (Word16) 1 ) ;
        Q[0] = G7231L_shr( Q[0], (Word16) 1 ) ;

        Acc0 = G7231L_deposit_h( Lsp[2*i+0] ) ;
        Acc0 = G7231L_shr( Acc0, (Word16) i ) ;
        Acc0 = G7231L_add( Acc0, P[1] ) ;
        Acc0 = G7231L_shr( Acc0, (Word16) 1 ) ;
        P[1] = Acc0 ;

        Acc1 = G7231L_deposit_h( Lsp[2*i+1] ) ;
        Acc1 = G7231L_shr( Acc1, (Word16) i ) ;
        Acc1 = G7231L_add( Acc1, Q[1] ) ;
        Acc1 = G7231L_shr( Acc1, (Word16) 1 ) ;
        Q[1] = Acc1 ;
    }


    for ( i = 0 ; i < G7231LpcOrder/2 ; i ++ ) {
        Acc0 = P[i] ;
        Acc0 = G7231L_add( Acc0, P[i+1] ) ;
        Acc0 = G7231L_sub( Acc0, Q[i] ) ;
        Acc0 = G7231L_add( Acc0, Q[i+1] ) ;
        Acc0 = G7231L_shl( Acc0, (Word16) 3 ) ;
        Lsp[i] = G7231negate( G7231round( Acc0 ) ) ;

        Acc1 = P[i] ;
        Acc1 = G7231L_add( Acc1, P[i+1] ) ;
        Acc1 = G7231L_add( Acc1, Q[i] ) ;
        Acc1 = G7231L_sub( Acc1, Q[i+1] ) ;
        Acc1 = G7231L_shl( Acc1, (Word16) 3 ) ;
        Lsp[G7231LpcOrder-1-i] = G7231negate( G7231round( Acc1 ) ) ;
    }

}

⌨️ 快捷键说明

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