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

📄 owng723.c

📁 G.729 and G.723.1 codecs x86 (and x86_64) Linux and FreeBSD source code for Asterisk open source PBX
💻 C
📖 第 1 页 / 共 4 页
字号:
/*/////////////////////////////////////////////////////////////////////////////////                  INTEL CORPORATION PROPRIETARY INFORMATION//     This software is supplied under the terms of a license agreement or//     nondisclosure agreement with Intel Corporation and may not be copied//     or disclosed except in accordance with the terms of that agreement.//          Copyright(c) 2005-2007 Intel Corporation. All Rights Reserved.////     Intel(R) Integrated Performance Primitives//     USC - Unified Speech Codec interface library//// By downloading and installing USC codec, you hereby agree that the// accompanying Materials are being provided to you under the terms and// conditions of the End User License Agreement for the Intel(R) Integrated// Performance Primitives product previously accepted by you. Please refer// to the file ippEULA.rtf or ippEULA.txt located in the root directory of your Intel(R) IPP// product installation for more information.//// A speech coding standards promoted by ITU, ETSI, 3GPP and other// organizations. Implementations of these standards, or the standard enabled// platforms may require licenses from various entities, including// Intel Corporation.////// Purpose: G.723.1 speech codec: internal functions and tables.//*/#include "owng723.h"typedef enum {   G723_Rate63Frame = 0,   G723_Rate53Frame,   G723_SIDFrame,   G723_UntransmittedFrame}G723_Info_Bit;static Ipp32s  ExtractBits( const Ipp8s **pBitStrm, Ipp32s *currBitstrmOffset, Ipp32s numParamBits ){    Ipp32s  i ;    Ipp32s  unpackedParam = 0 ;    for ( i = 0 ; i < numParamBits ; i ++ ){        Ipp32s  lTemp;        lTemp = ((*pBitStrm)[(i + *currBitstrmOffset)>>3] >> ((i + *currBitstrmOffset) & 0x7)) & 1;        unpackedParam +=  lTemp << i ;    }    *pBitStrm += (numParamBits + *currBitstrmOffset)>>3;    *currBitstrmOffset = (numParamBits + *currBitstrmOffset) & 0x7;    return unpackedParam ;}void GetParamFromBitstream( const Ipp8s *pSrcBitStream, ParamStream_G723 *Params){   Ipp32s   i;   Ipp32s  lTmp ;   Ipp16s InfoBit;   Ipp16s Bound_AcGn;   const Ipp8s **pBitStream = &pSrcBitStream;   Ipp32s nBit = 0;   /* Extract the frame type and rate info */   InfoBit = (Ipp16s)ExtractBits(pBitStream, &nBit, 2);   if ( InfoBit == G723_UntransmittedFrame ) {      Params->FrameType = G723_UntransmittedFrm; Params->lLSPIdx = 0;      return;   }   if ( InfoBit == G723_SIDFrame ) { /* SID frame*/      Params->lLSPIdx = ExtractBits(pBitStream, &nBit, 24);/* LspId */      Params->sAmpIndex[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 6); /* Gain */      Params->FrameType = G723_SIDFrm; return;   }   if ( InfoBit == G723_Rate53Frame ) {      Params->FrameType = G723_ActiveFrm;      Params->currRate = G723_Rate53;      Params->lLSPIdx = ExtractBits(pBitStream, &nBit, 24);/* LspId */      Params->PitchLag[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 7);      Params->AdCdbkLag[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 2);      Params->PitchLag[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 7);      Params->AdCdbkLag[3] = (Ipp16s)ExtractBits(pBitStream, &nBit, 2);      Params->AdCdbkLag[0] = Params->AdCdbkLag[2] = 1;      Params->AdCdbkGain[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 12);      Params->AdCdbkGain[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 12);      Params->AdCdbkGain[2] = (Ipp16s)ExtractBits(pBitStream, &nBit, 12);      Params->AdCdbkGain[3] = (Ipp16s)ExtractBits(pBitStream, &nBit, 12);      Params->sGrid[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 1);      Params->sGrid[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 1);      Params->sGrid[2] = (Ipp16s)ExtractBits(pBitStream, &nBit, 1);      Params->sGrid[3] = (Ipp16s)ExtractBits(pBitStream, &nBit, 1);      Params->sPosition[0] = ExtractBits(pBitStream, &nBit, 12);      Params->sPosition[1] = ExtractBits(pBitStream, &nBit, 12);      Params->sPosition[2] = ExtractBits(pBitStream, &nBit, 12);      Params->sPosition[3] = ExtractBits(pBitStream, &nBit, 12);      Params->sAmplitude[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 4);      Params->sAmplitude[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 4);      Params->sAmplitude[2] = (Ipp16s)ExtractBits(pBitStream, &nBit, 4);      Params->sAmplitude[3] = (Ipp16s)ExtractBits(pBitStream, &nBit, 4);      /* Frame erasure concealment and parameters scaling*/      if( Params->PitchLag[0] <= 123) {        Params->PitchLag[0] += G723_MIN_PITCH ;      } else {        Params->isBadFrame = 1; /* transmission error */        return;      }      if( Params->PitchLag[1] <= 123) {        Params->PitchLag[1] += G723_MIN_PITCH ;      } else {        Params->isBadFrame = 1; /* transmission error */        return;      }      for ( i = 0 ; i < 4 ; i ++ ) {         Params->sTrainDirac[i] = 0 ;         Bound_AcGn = AdCdbkSizeLowRate;         lTmp = Params->AdCdbkGain[i];         Params->AdCdbkGain[i] = (Ipp16s)(lTmp/N_GAINS) ;         if(Params->AdCdbkGain[i] < Bound_AcGn ) {            Params->sAmpIndex[i] = (Ipp16s)(lTmp % N_GAINS) ;         } else {            Params->isBadFrame = 1; /* transmission error */            return ;         }      }      return;   }   if (InfoBit == G723_Rate63Frame) {      Params->FrameType = G723_ActiveFrm;      Params->currRate = G723_Rate63;      Params->lLSPIdx = ExtractBits(pBitStream, &nBit, 24);/* LspId */      Params->PitchLag[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 7);      Params->AdCdbkLag[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 2);      Params->PitchLag[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 7);      Params->AdCdbkLag[3] = (Ipp16s)ExtractBits(pBitStream, &nBit, 2);      Params->AdCdbkLag[0] = Params->AdCdbkLag[2] = 1;      Params->AdCdbkGain[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 12);      Params->AdCdbkGain[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 12);      Params->AdCdbkGain[2] = (Ipp16s)ExtractBits(pBitStream, &nBit, 12);      Params->AdCdbkGain[3] = (Ipp16s)ExtractBits(pBitStream, &nBit, 12);      Params->sGrid[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 1);      Params->sGrid[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 1);      Params->sGrid[2] = (Ipp16s)ExtractBits(pBitStream, &nBit, 1);      Params->sGrid[3] = (Ipp16s)ExtractBits(pBitStream, &nBit, 1);      ExtractBits(pBitStream, &nBit, 1);/* Skip the reserved bit for align pack*/      lTmp = ExtractBits(pBitStream, &nBit, 13); /*Exract the position,s MSB*/                                         /* lTmp = 810*x0 + 90*x1 + 9*x2 + x3*/      Params->sPosition[0] = lTmp / 810;      lTmp -= Params->sPosition[0]*810;       /* lTmp =          90*x1 + 9*x2 + x3*/      Params->sPosition[1] = lTmp / 90;      lTmp -= Params->sPosition[1]*90;        /* lTmp =                  9*x2 + x3*/      Params->sPosition[2] = lTmp / 9;      Params->sPosition[3] = lTmp - (Params->sPosition[2]*9);      /* Extract all the pulse positions */      Params->sPosition[0] = ( Params->sPosition[0] << 16 ) + ExtractBits(pBitStream, &nBit, 16) ;      Params->sPosition[1] = ( Params->sPosition[1] << 14 ) + ExtractBits(pBitStream, &nBit, 14) ;      Params->sPosition[2] = ( Params->sPosition[2] << 16 ) + ExtractBits(pBitStream, &nBit, 16) ;      Params->sPosition[3] = ( Params->sPosition[3] << 14 ) + ExtractBits(pBitStream, &nBit, 14) ;      /* Extract pulse amplitudes */      Params->sAmplitude[0] = (Ipp16s)ExtractBits(pBitStream, &nBit, 6);      Params->sAmplitude[1] = (Ipp16s)ExtractBits(pBitStream, &nBit, 5);      Params->sAmplitude[2] = (Ipp16s)ExtractBits(pBitStream, &nBit, 6);      Params->sAmplitude[3] = (Ipp16s)ExtractBits(pBitStream, &nBit, 5);      /* Frame erasure concealment and parameters scaling*/      if( Params->PitchLag[0] <= 123) {        Params->PitchLag[0] += G723_MIN_PITCH ;      } else {        Params->isBadFrame = 1; /* transmission error */        return;      }      if( Params->PitchLag[1] <= 123) {        Params->PitchLag[1] += G723_MIN_PITCH ;      } else {        Params->isBadFrame = 1; /* transmission error */        return;      }      for ( i = 0 ; i < 4 ; i ++ ) {         lTmp = Params->AdCdbkGain[i];         Params->sTrainDirac[i] = 0 ;         Bound_AcGn = AdCdbkSizeLowRate ;         if (Params->PitchLag[i>>1] < (G723_SBFR_LEN-2)) {            Params->sTrainDirac[i] = (Ipp16s)(lTmp >> 11) ;            lTmp &= 0x7ff ;            Bound_AcGn = AdCdbkSizeHighRate ;         }         Params->AdCdbkGain[i] = (Ipp16s)(lTmp/N_GAINS) ;         if(Params->AdCdbkGain[i] < Bound_AcGn ) {            Params->sAmpIndex[i] = (Ipp16s)(lTmp % N_GAINS) ;         } else {            Params->isBadFrame = 1; /* transmission error */            return ;         }      }      return;   }   return;}static Ipp16s* Parm2Bits( Ipp32s param, Ipp16s *pBitStrm, Ipp32s ParamBitNum ){   Ipp32s i;   for ( i = 0 ; i < ParamBitNum ; i ++ ) {      *pBitStrm ++ = (Ipp16s) (param & 0x1);      param >>= 1;   }   return pBitStrm;}void    SetParam2Bitstream(G723Encoder_Obj* encoderObj, ParamStream_G723 *Params, Ipp8s *pDstBitStream){    Ipp32s  i;    Ipp16s *pBitStream, *pB;    Ipp32s  MSBs;    LOCAL_ARRAY(Ipp16s, Bits,192,encoderObj);    pBitStream = Bits;    switch (Params->FrameType) {    case 0 :  /* untransmitted */       pBitStream = Parm2Bits( G723_UntransmittedFrame, pBitStream, 2 );       pDstBitStream[0] = (Ipp8s)(Bits[0] ^ (Bits[1] << 1));       break;    case 2 :  /* SID */       ippsZero_8u((Ipp8u *)pDstBitStream, 4);       pBitStream = Parm2Bits( G723_SIDFrame, pBitStream, 2 );       pBitStream = Parm2Bits( Params->lLSPIdx, pBitStream, 24 ); /* 24 bit lLSPIdx */       pBitStream = Parm2Bits( Params->sAmpIndex[0], pBitStream, 6 );/* Do Sid frame gain */       pB = Bits;       for ( i = 0 ; i < 4 ; i ++, pB+=8 )          pDstBitStream[i]=(Ipp8s)(pB[0]^(pB[1]<<1)^(pB[2]<<2)^(pB[3]<<3)^(pB[4]<<4)^(pB[5]<<5)^(pB[6]<<6)^(pB[7]<<7));       break;    default :       if ( Params->currRate == G723_Rate63 ){            ippsZero_8u((Ipp8u *)pDstBitStream, 24);            pBitStream = Parm2Bits( G723_Rate63Frame, pBitStream, 2 );            pBitStream = Parm2Bits( Params->lLSPIdx, pBitStream, 24 ) ; /* 24 bit LspId */            pBitStream = Parm2Bits( Params->PitchLag[0] -  G723_MIN_PITCH, pBitStream, 7 ) ; /* Adaptive codebook lags */            pBitStream = Parm2Bits( Params->AdCdbkLag[1], pBitStream, 2 ) ;            pBitStream = Parm2Bits( Params->PitchLag[1] -  G723_MIN_PITCH, pBitStream, 7 ) ;            pBitStream = Parm2Bits( Params->AdCdbkLag[3], pBitStream, 2 ) ;            /* Write gains indexes of 12 bit */            for ( i = 0 ; i < 4 ; i ++ ) {               pBitStream = Parm2Bits( Params->AdCdbkGain[i]*N_GAINS + Params->sAmpIndex[i] + (Params->sTrainDirac[i] << 11), pBitStream, 12 ) ;            }            for ( i = 0 ; i < 4 ; i ++ )               *pBitStream ++ = Params->sGrid[i] ; /* Write all the Grid indices */            *pBitStream ++ = 0 ; /* reserved bit */            /* Write 13 bit combined position index, pack 4 MSB from each pulse position. */            MSBs = (Params->sPosition[0] >> 16) * 810 + ( Params->sPosition[1] >> 14)*90 +                   (Params->sPosition[2] >> 16) * 9 + ( Params->sPosition[3] >> 14 );            pBitStream = Parm2Bits(MSBs, pBitStream, 13);            /* Write all the pulse positions */            pBitStream = Parm2Bits(Params->sPosition[0] & 0xffff, pBitStream, 16);            pBitStream = Parm2Bits(Params->sPosition[1] & 0x3fff, pBitStream, 14);            pBitStream = Parm2Bits(Params->sPosition[2] & 0xffff, pBitStream, 16);            pBitStream = Parm2Bits(Params->sPosition[3] & 0x3fff, pBitStream, 14);            /* Write pulse amplitudes */            pBitStream = Parm2Bits(Params->sAmplitude[0], pBitStream, 6);            pBitStream = Parm2Bits(Params->sAmplitude[1] , pBitStream, 5);            pBitStream = Parm2Bits(Params->sAmplitude[2], pBitStream, 6);            pBitStream = Parm2Bits(Params->sAmplitude[3], pBitStream, 5);            pB = Bits;            for ( i = 0 ; i < 24 ; i ++, pB+=8 )               pDstBitStream[i]=(Ipp8s)(pB[0]^(pB[1]<<1)^(pB[2]<<2)^(pB[3]<<3)^(pB[4]<<4)^(pB[5]<<5)^(pB[6]<<6)^(pB[7]<<7));       }else{            ippsZero_8u((Ipp8u *)pDstBitStream, 20);            pBitStream = Parm2Bits( G723_Rate53Frame, pBitStream, 2 );            pBitStream = Parm2Bits( Params->lLSPIdx, pBitStream, 24 ) ; /* 24 bit lLSPIdx */            pBitStream = Parm2Bits( Params->PitchLag[0] -  G723_MIN_PITCH, pBitStream, 7 ) ; /* Adaptive codebook lags */            pBitStream = Parm2Bits( Params->AdCdbkLag[1], pBitStream, 2 ) ;            pBitStream = Parm2Bits( Params->PitchLag[1] -  G723_MIN_PITCH, pBitStream, 7 ) ;            pBitStream = Parm2Bits( Params->AdCdbkLag[3], pBitStream, 2 ) ;            /* Write gains indexes of 12 bit */            for ( i = 0 ; i < 4 ; i ++ )               pBitStream = Parm2Bits( Params->AdCdbkGain[i]*N_GAINS + Params->sAmpIndex[i], pBitStream, 12 );            for ( i = 0 ; i < 4 ; i ++ )               *pBitStream ++ = Params->sGrid[i] ; /* Write all the Grid indices */            /* Write positions */            for ( i = 0 ; i < 4 ; i ++ ) {                pBitStream = Parm2Bits( Params->sPosition[i], pBitStream, 12 ) ;            }            /* Write Pamps */            for ( i = 0 ; i < 4 ; i ++ ) {                pBitStream = Parm2Bits( Params->sAmplitude[i], pBitStream, 4 ) ;            }            pB = Bits;            for ( i = 0 ; i < 20 ; i ++, pB+=8 )               pDstBitStream[i]=(Ipp8s)(pB[0]^(pB[1]<<1)^(pB[2]<<2)^(pB[3]<<3)^(pB[4]<<4)^(pB[5]<<5)^(pB[6]<<6)^(pB[7]<<7));       }       break;    }    LOCAL_ARRAY_FREE(Ipp16s, Bits,192,encoderObj);    return;}void   UpdateSineDetector(Ipp16s *SineWaveDetector, Ipp16s *isNotSineWave){   Ipp32s i, x, lNumTimes;   *SineWaveDetector &= 0x7fff ;   *isNotSineWave = 1;   x= *SineWaveDetector;   lNumTimes = 0;   for ( i = 0 ; i < 15 ; i ++ ) {       lNumTimes += x&1;       x >>= 1;   }   if ( lNumTimes >= 14 ) /* Sine wave is detected*/       *isNotSineWave = -1;}/*Usage GenPostFiltTable(Tbl, 0.65); GenPostFiltTable(Tbl+10, 0.75);#define SATURATE_fs(dVal,dRez)\   if (dVal >= 0.0) dVal += 0.5;\   else  dVal -= 0.5;\   dRez = (Ipp16s)dVal;static void GenPostFiltTable(Ipp16s *Tbl, Ipp64f dInit){

⌨️ 快捷键说明

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