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

📄 uscg729i.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 2 页
字号:

   if(modes==NULL) return USC_BadDataPointer;
   if(handle==NULL) return USC_InvalidHandler;

    g729_header = (G729_Handle_Header*)handle;

    bitrate_idx = CheckRate_G729I(modes->bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;

    g729_header->vad = modes->vad;
    g729_header->bitrate = modes->bitrate;

    if (g729_header->direction == 0) /* encode only */
    {
        G729Encoder_Obj *EncObj = (G729Encoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));
        apiG729Encoder_Init((G729Encoder_Obj*)EncObj, G729I_CODEC, (G729Encode_Mode)modes->vad);
    }
    else if (g729_header->direction == 1) /* decode only */
    {
        G729Decoder_Obj *DecObj = (G729Decoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));
        apiG729Decoder_Init((G729Decoder_Obj*)DecObj, G729I_CODEC);
    } else {
        return USC_NoOperation;
    }
    return USC_NoError;
}

static USC_Status Reinit_G729A(const USC_Modes *modes, USC_Handle handle )
{
    G729_Handle_Header *g729_header;
    int bitrate_idx;

   if(modes==NULL) return USC_BadDataPointer;
   if(handle==NULL) return USC_InvalidHandler;

    g729_header = (G729_Handle_Header*)handle;

    bitrate_idx = CheckRate_G729A(modes->bitrate);
     if(bitrate_idx < 0) return USC_UnsupportedBitRate;

     g729_header->vad = modes->vad;
     g729_header->bitrate = modes->bitrate;

    if (g729_header->direction == 0) /* encode only */
    {
        G729Encoder_Obj *EncObj = (G729Encoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));
        apiG729Encoder_Init((G729Encoder_Obj*)EncObj, (G729Codec_Type)bitrate_idx, (G729Encode_Mode)modes->vad);
    }
    else if (g729_header->direction == 1) /* decode only */
    {
        G729Decoder_Obj *DecObj = (G729Decoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));
        apiG729Decoder_Init((G729Decoder_Obj*)DecObj, (G729Codec_Type)bitrate_idx);
    } else {
        return USC_NoOperation;
    }
    return USC_NoError;
}

static USC_Status Control_G729I(const USC_Modes *modes, USC_Handle handle )
{
   G729_Handle_Header *g729_header;
   int bitrate_idx;

   if(modes==NULL) return USC_BadDataPointer;
   if(handle==NULL) return USC_InvalidHandler;

   g729_header = (G729_Handle_Header*)handle;

   bitrate_idx = CheckRate_G729I(modes->bitrate);
   if(bitrate_idx < 0) return USC_UnsupportedBitRate;

   g729_header->vad = modes->vad;
   g729_header->bitrate = modes->bitrate;

   if (g729_header->direction == 0) /* encode only */
   {
        G729Encoder_Obj *EncObj = (G729Encoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));
        apiG729Encoder_Mode((G729Encoder_Obj*)EncObj, (G729Encode_Mode)modes->vad);
   }
   return USC_NoError;
}

static USC_Status Control_G729A(const USC_Modes *modes, USC_Handle handle )
{
   G729_Handle_Header *g729_header;
   int bitrate_idx;

   if(modes==NULL) return USC_BadDataPointer;
   if(handle==NULL) return USC_InvalidHandler;

   g729_header = (G729_Handle_Header*)handle;

   bitrate_idx = CheckRate_G729A(modes->bitrate);
   if(bitrate_idx < 0) return USC_UnsupportedBitRate;

   g729_header->vad = modes->vad;
   g729_header->bitrate = modes->bitrate;

   if (g729_header->direction == 0) /* encode only */
   {
        G729Encoder_Obj *EncObj = (G729Encoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));
        apiG729Encoder_Mode((G729Encoder_Obj*)EncObj, (G729Encode_Mode)modes->vad);
   }
   return USC_NoError;
}

static int getBitstreamSize(int frametype)
{

    switch (frametype) {
      case 0: return 0;
      case 1: return 2;
      case 2: return 8;
      case 3: return 10;
      case 4: return 15;
      default: return 0;
    }
}

static USC_Status Encode_G729I(USC_Handle handle, USC_PCMStream *in, USC_Bitstream *out)
{
    G729_Handle_Header *g729_header;
    G729Encoder_Obj *EncObj;
    int bitrate_idx;

    if(in==NULL) return USC_BadDataPointer;
    if(in->nbytes<G729_SPEECH_FRAME*sizeof(short)) return USC_BadDataPointer;

    bitrate_idx = CheckRate_G729I(in->bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;

    g729_header = (G729_Handle_Header*)handle;
    g729_header->bitrate = in->bitrate;
    EncObj = (G729Encoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));

    if(apiG729Encode(EncObj,(const short*)in->pBuffer,out->pBuffer,(G729Codec_Type)bitrate_idx,&out->frametype) != APIG729_StsNoErr){
       return USC_NoOperation;
    }
     out->nbytes = getBitstreamSize(out->frametype);
     out->bitrate = in->bitrate;

     in->nbytes = G729_SPEECH_FRAME*sizeof(short);

    return USC_NoError;
}

static USC_Status Encode_G729A(USC_Handle handle, USC_PCMStream *in, USC_Bitstream *out)
{
    G729_Handle_Header *g729_header;
    G729Encoder_Obj *EncObj;
    int bitrate_idx;

    if(in==NULL) return USC_BadDataPointer;
    if(in->nbytes<G729_SPEECH_FRAME*sizeof(short)) return USC_BadDataPointer;

    bitrate_idx = CheckRate_G729A(in->bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;

    g729_header = (G729_Handle_Header*)handle;
    g729_header->bitrate = in->bitrate;
    EncObj = (G729Encoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));

    if(apiG729Encode(EncObj,(const short*)in->pBuffer,out->pBuffer,(G729Codec_Type)bitrate_idx,&out->frametype) != APIG729_StsNoErr){
       return USC_NoOperation;
    }
    out->nbytes = getBitstreamSize(out->frametype);
    out->bitrate = in->bitrate;

    in->nbytes = G729_SPEECH_FRAME*sizeof(short);

    return USC_NoError;
}


static USC_Status Decode_G729I(USC_Handle handle, USC_Bitstream *in, USC_PCMStream *out)
{
    G729_Handle_Header *g729_header;
    G729Decoder_Obj *DecObj;
    int bitrate_idx;

   if(out==NULL) return USC_BadDataPointer;
   if(handle==NULL) return USC_InvalidHandler;

    g729_header = (G729_Handle_Header*)handle;
    DecObj = (G729Decoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));

    if(in == NULL) {
       /* Lost frame */
       if(apiG729Decode(DecObj,(const unsigned char*)LostFrame,(-1),(unsigned short*)out->pBuffer) != APIG729_StsNoErr){
         return USC_NoOperation;
      }
      out->bitrate = g729_header->bitrate;
    } else {
      bitrate_idx = CheckRate_G729I(in->bitrate);
      if(bitrate_idx < 0) return USC_UnsupportedBitRate;

       g729_header->bitrate = in->bitrate;
      if(apiG729Decode(DecObj,(const unsigned char*)in->pBuffer,in->frametype,(unsigned short*)out->pBuffer) != APIG729_StsNoErr){
         return USC_NoOperation;
      }
      in->nbytes = getBitstreamSize(in->frametype);
      in->bitrate = g729_header->bitrate;
    }
    out->nbytes = G729_SPEECH_FRAME*sizeof(short);

    return USC_NoError;
}


static USC_Status Decode_G729A(USC_Handle handle, USC_Bitstream *in, USC_PCMStream *out)
{
    G729_Handle_Header *g729_header;
    G729Decoder_Obj *DecObj;
    int bitrate_idx;

   if(out==NULL) return USC_BadDataPointer;
   if(handle==NULL) return USC_InvalidHandler;

    g729_header = (G729_Handle_Header*)handle;
    DecObj = (G729Decoder_Obj *)((char*)handle + sizeof(G729_Handle_Header));

    if(in == NULL) {
      /* Lost frame */
      if(apiG729Decode(DecObj,(const unsigned char*)LostFrame,(-1),(unsigned short*)out->pBuffer) != APIG729_StsNoErr){
        return USC_NoOperation;
      }
      out->bitrate = g729_header->bitrate;
    } else {
      bitrate_idx = CheckRate_G729A(in->bitrate);
      if(bitrate_idx < 0) return USC_UnsupportedBitRate;
      g729_header->bitrate = in->bitrate;
      if(apiG729Decode(DecObj,(const unsigned char*)in->pBuffer,in->frametype,(unsigned short*)out->pBuffer) != APIG729_StsNoErr){
        return USC_NoOperation;
      }
      in->nbytes = getBitstreamSize(in->frametype);
      out->bitrate = in->bitrate;
    }
    out->nbytes = G729_SPEECH_FRAME*sizeof(short);

    return USC_NoError;
}

static __ALIGN32 CONST int pFrameSize_G729I[G729I_NUM_RATES]={
    15,
    10,
   8
};
static int RateToIndex_G729I(int rate_bps)
{
    int idx;

    switch(rate_bps) {
     case 11800:  idx = 0; break;
      case 8000:  idx = 1; break;
      case 6400: idx = 2; break;
      default: idx = -1; break;
    }
    return idx;
}

static int RateToIndex_G729A(int rate_bps)
{
    int idx;

    switch(rate_bps) {
     case 8000:  idx = 1; break;
      default: idx = -1; break;
    }
    return idx;
}

static USC_Status CalsOutStreamSize(const USC_Option *options, int bitrate_idx, int nbytesSrc, int *nbytesDst)
{
   int nBlocks, nSamples;

   if(options->direction==0) { /*Encode: src - PCMStream, dst - bitstream*/
      if(options->modes.vad>1) return USC_UnsupportedVADType;

      nSamples = nbytesSrc / (G729_BITS_PER_SAMPLE >> 3);
      nBlocks = nSamples / G729_SPEECH_FRAME;

      if (0 == nBlocks) return USC_NoOperation;

      if (0 != nSamples % G729_SPEECH_FRAME) {
         /* Add another block to hold the last compressed fragment*/
         nBlocks++;
      }

      *nbytesDst = nBlocks * pFrameSize_G729I[bitrate_idx];
   } else if(options->direction==1) {/*Decode: src - bitstream, dst - PCMStream*/
      if(options->modes.vad==0) { /*VAD off*/
         nBlocks = nbytesSrc / pFrameSize_G729I[bitrate_idx];
      } else if(options->modes.vad==1) { /*VAD on*/
         nBlocks = nbytesSrc / G729_SID_FRAMESIZE;
         nBlocks += nBlocks*G729_NUM_UNTR_FRAMES; /*Len of Untr frame  in bitstream==0, there are 2 untr frames after SID frame*/
      } else return USC_UnsupportedVADType;

      if (0 == nBlocks) return USC_NoOperation;

      nSamples = nBlocks * G729_SPEECH_FRAME;
      *nbytesDst = nSamples * (G729_BITS_PER_SAMPLE >> 3);
   } else if(options->direction==2) {/* Both: src - PCMStream, dst - PCMStream*/
      nSamples = nbytesSrc / (G729_BITS_PER_SAMPLE >> 3);
      nBlocks = nSamples / G729_SPEECH_FRAME;

      if (0 == nBlocks) return USC_NoOperation;

      if (0 != nSamples % G729_SPEECH_FRAME) {
         /* Add another block to hold the last compressed fragment*/
         nBlocks++;
      }
      *nbytesDst = nBlocks * G729_SPEECH_FRAME * (G729_BITS_PER_SAMPLE >> 3);
   } else return USC_NoOperation;

   return USC_NoError;
}
static USC_Status GetOutStreamSizeI(const USC_Option *options, int bitrate, int nbytesSrc, int *nbytesDst)
{
   int bitrate_idx;

   if(options==NULL) return USC_BadDataPointer;
   if(nbytesDst==NULL) return USC_BadDataPointer;
   if(nbytesSrc <= 0) return USC_NoOperation;

   bitrate_idx = RateToIndex_G729I(bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;

   return CalsOutStreamSize(options, bitrate_idx, nbytesSrc, nbytesDst);
}

static USC_Status GetOutStreamSizeA(const USC_Option *options, int bitrate, int nbytesSrc, int *nbytesDst)
{
   int bitrate_idx;

   if(options==NULL) return USC_BadDataPointer;
   if(nbytesDst==NULL) return USC_BadDataPointer;
   if(nbytesSrc <= 0) return USC_NoOperation;

   bitrate_idx = RateToIndex_G729A(bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;

   return CalsOutStreamSize(options, bitrate_idx, nbytesSrc, nbytesDst);
}

USC_Status SetFrameSize(const USC_Option *options, USC_Handle handle, int frameSize)
{
   if(options==NULL) return USC_BadDataPointer;
   if(handle==NULL) return USC_InvalidHandler;

   return USC_NoError;
}

⌨️ 快捷键说明

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