Esempio n. 1
0
static USC_Status Reinit_VAD_G729FP(const USC_FilterModes *modes, USC_Handle handle )
{
    G729_Handle_Header *g729_header;
    VADmemory *VadObj;

    Ipp32s i;
    Ipp32s fltsize;
    void* pBuf;
    Ipp8s* oldMemBuff;

    USC_CHECK_PTR(modes);
    USC_CHECK_HANDLE(handle);
    USC_BADARG(modes->vad > 1, USC_UnsupportedVADType);
    USC_BADARG(modes->vad < 0, USC_UnsupportedVADType);

    g729_header = (G729_Handle_Header*)handle;

    g729_header->vad = modes->vad;
    VadObj = (VADmemory *)((Ipp8s*)handle + sizeof(G729_Handle_Header));
   if(NULL==VadObj)
      return USC_BadArgument;

   oldMemBuff = VadObj->Mem.base; /* if Reinit */
   ippsZero_32f(VadObj->OldSpeechBuffer, SPEECH_BUFF_LEN);

   ippsZero_16s((Ipp16s*)VadObj,sizeof(VADmemory)>>1) ;

   VadObj->objPrm.objSize = vadObjSize();
   VadObj->objPrm.mode = g729_header->vad;
   VadObj->objPrm.key = ENC_KEY;

   pBuf = (Ipp8s*)VadObj + sizeof(VADmemory);
   ippsIIRGetStateSize_32f(2,&fltsize);
   VadObj = (VADmemory *)((Ipp8s*)pBuf + fltsize);
   VADGetSize(&fltsize);

   /* Static vectors to zero */
   for(i=0; i<MOVING_AVER_ORDER; i++)
   VadObj->sFrameCounter = 0;
   /* For G.729B */
   /* Initialize VAD/DTX parameters */
   //if(mode == G729Encode_VAD_Enabled) {
      VadObj->prevVADDec = 1;
      VadObj->prevPrevVADDec = 1;
      VADInit((Ipp8s*)VadObj);
   //}

    if(oldMemBuff==NULL) return USC_BadArgument;
    if(VadObj==NULL) return USC_BadArgument;

    if(NULL==VadObj || NULL==oldMemBuff)
       return USC_BadArgument;

    VadObj->Mem.base = oldMemBuff;
    VadObj->Mem.CurPtr = VadObj->Mem.base;
    VadObj->Mem.VecPtr = (Ipp32s *)(VadObj->Mem.base+VAD_G729FP_LOCAL_MEMORY_SIZE);

    return USC_NoError;
}
Esempio n. 2
0
static USC_Status Init(const USC_Option *options, const USC_MemBank *pBanks, USC_Handle *handle)
{
    Ipp32s bitrate_idx;
    G722SB_Handle_Header *g722sb_header;

    USC_CHECK_PTR(options);
    USC_CHECK_PTR(pBanks);
    USC_CHECK_PTR(pBanks->pMem);
    USC_BADARG(pBanks->nbytes<=0, USC_NotInitialized);
    USC_CHECK_HANDLE(handle);
    USC_BADARG(options->pcmType.bitPerSample!=G722SB_BITS_PER_SAMPLE, USC_UnsupportedPCMType);
    USC_BADARG(options->pcmType.sample_frequency!=G722SB_SAMPLE_FREQ, USC_UnsupportedPCMType);
    USC_BADARG(options->pcmType.nChannels!=G722SB_NCHANNELS, USC_UnsupportedPCMType);

    if((options->framesize != G722SB_SPEECH_FRAME_10MS*sizeof(Ipp16s)) &&
       (options->framesize != G722SB_SPEECH_FRAME_20MS*sizeof(Ipp16s))) return USC_UnsupportedFrameSize;

    bitrate_idx = CheckRate_G722SB(options->modes.bitrate);
    USC_BADARG(bitrate_idx < 0, USC_UnsupportedBitRate);

    *handle = (USC_Handle*)pBanks->pMem;
    g722sb_header = (G722SB_Handle_Header*)*handle;

    g722sb_header->hpf = options->modes.hpf;
    g722sb_header->pf = options->modes.pf;
    g722sb_header->bitrate = options->modes.bitrate;
    g722sb_header->direction = options->direction;
    g722sb_header->framesize = options->framesize;

    if (options->direction == USC_ENCODE) /* encode only */
    {
      G722SB_Encoder_Obj *EncObj = (G722SB_Encoder_Obj *)((Ipp8s*)*handle + sizeof(G722SB_Handle_Header));
      apiG722SBEncoder_Init(EncObj, g722sb_header->hpf);
    }
    else if (options->direction == USC_DECODE) /* decode only */
    {
      G722SB_Decoder_Obj *DecObj = (G722SB_Decoder_Obj *)((Ipp8s*)*handle + sizeof(G722SB_Handle_Header));
      apiG722SBDecoder_Init(DecObj, g722sb_header->pf, g722sb_header->framesize);

    } else {
      *handle = NULL;
      return USC_NoOperation;
    }
    return USC_NoError;
}
Esempio n. 3
0
static USC_Status Control_VAD_G729FP(const USC_FilterModes *modes, USC_Handle handle )
{
   G729_Handle_Header *g729_header;
   VADmemory *VadObj;

   USC_CHECK_PTR(modes);
   USC_CHECK_HANDLE(handle);
   USC_BADARG(modes->vad > 1, USC_UnsupportedVADType);
   USC_BADARG(modes->vad < 0, USC_UnsupportedVADType);

   g729_header = (G729_Handle_Header*)handle;

   g729_header->vad = modes->vad;
   VadObj = (VADmemory *)((Ipp8s*)handle + sizeof(G729_Handle_Header));
   if(G729Encode_VAD_Enabled != modes->vad && G729Encode_VAD_Disabled != modes->vad){
      return USC_BadArgument;
   }
   VadObj->objPrm.mode = modes->vad;
   return USC_NoError;
}
Esempio n. 4
0
static USC_Status VAD_G729FP(USC_Handle handle, USC_PCMStream *in, USC_PCMStream *out, USC_FrameType *pVADDecision)
{
    VADmemory *VadObj;
    Ipp32s *pVD;

    USC_CHECK_PTR(in);
    USC_CHECK_PTR(out);
    USC_CHECK_PTR(pVADDecision);
    USC_CHECK_HANDLE(handle);
    USC_BADARG(in->nbytes<G729_SPEECH_FRAME*sizeof(Ipp16s), USC_NoOperation);
    USC_BADARG(in->pcmType.bitPerSample!=G729_BITS_PER_SAMPLE, USC_UnsupportedPCMType);
    USC_BADARG(in->pcmType.sample_frequency!=G729_SAMPLE_FREQUENCY, USC_UnsupportedPCMType);
    USC_BADARG(in->nbytes<G729_SPEECH_FRAME*sizeof(Ipp16s), USC_BadDataPointer);

    pVD = (Ipp32s*)pVADDecision;

    VadObj = (VADmemory *)((Ipp8s*)handle + sizeof(G729_Handle_Header));

    if(G729FPVAD(VadObj,(const Ipp16s*)in->pBuffer,(Ipp16s*)out->pBuffer,pVD) != 0){
      return USC_NoOperation;
    }

   if (*pVD == 0){
      *pVADDecision = NODECISION;
       ippsZero_8u((Ipp8u*)out->pBuffer, G729_SPEECH_FRAME*sizeof(Ipp16s));
   } else if (*pVD == 1){
      *pVADDecision = INACTIVE;
      ippsZero_8u((Ipp8u*)out->pBuffer, G729_SPEECH_FRAME*sizeof(Ipp16s));
   } else if (*pVD == 3) {
      ippsCopy_8u((Ipp8u*)in->pBuffer,(Ipp8u*)out->pBuffer, G729_SPEECH_FRAME*sizeof(Ipp16s));
      *pVADDecision = ACTIVE;
   }

    out->bitrate = in->bitrate;

    in->nbytes = G729_SPEECH_FRAME*sizeof(Ipp16s);
    out->nbytes = G729_SPEECH_FRAME*sizeof(Ipp16s);

    return USC_NoError;
}
Esempio n. 5
0
static USC_Status Decode(USC_Handle handle, USC_Bitstream *in, USC_PCMStream *out)
{
    G722SB_Handle_Header *g722sb_header;
    G722SB_Decoder_Obj *DecObj;
    Ipp32s bitrate_idx, length, i, j;
    Ipp8s bit[2];
    Ipp16s *in_buff, *out_buff;
    Ipp32s PLC = 0;

    USC_CHECK_PTR(out);
    USC_CHECK_HANDLE(handle);
    USC_BADARG( NULL==out->pBuffer, USC_NoOperation );

    g722sb_header = (G722SB_Handle_Header*)handle;

    if(g722sb_header->direction != USC_DECODE) return USC_NoOperation;

    DecObj = (G722SB_Decoder_Obj *)((Ipp8s*)handle + sizeof(G722SB_Handle_Header));

    if(in == NULL) {
      PLC = 1;
    } else if(in->pBuffer == NULL) {
      PLC = 1;
    }

    if(PLC) {
       /* Lost frame */
       bitrate_idx = CheckRate_G722SB(g722sb_header->bitrate);
       if(bitrate_idx < 0) return USC_UnsupportedBitRate;

      if(g722sb_header->pf) {
        if(apiG722SBDecode(DecObj, 0, (Ipp16s)bitrate_idx, NULL, (Ipp16s*)out->pBuffer) != API_G722SB_StsNoErr){
          return USC_NoOperation;
        }
        out->nbytes = g722sb_header->framesize;
      } else {
        if(g722sb_header->framesize == (G722SB_SPEECH_FRAME_10MS*sizeof(short))) length = BITSTREAM_SIZE_10MS;
        else length = BITSTREAM_SIZE_20MS;
        in_buff = (Ipp16s*)LostFrame;
        out_buff = (Ipp16s*)out->pBuffer;
        for(i=0,j=0; i<length; i++) {
          bit[0] = (Ipp8s)((in_buff[i] >> 8) & 0x00FF);
          if(apiG722SBDecode(DecObj, 1, (Ipp16s)bitrate_idx, (Ipp8s *)&bit[0], (Ipp16s*)&out_buff[j]) != API_G722SB_StsNoErr){
            return USC_NoOperation;
          }
          j+=2;
        }
        out->nbytes = j*sizeof(Ipp16s);
      }

    } else {
Esempio n. 6
0
static USC_Status Encode(USC_Handle handle, USC_PCMStream *in, USC_Bitstream *out)
{
    Ipp32s bitrate_idx, lenSamples, i;
    Ipp8s pOutBuff[2];
    Ipp16s *in_buff, *out_buff;
    G722SB_Handle_Header *g722sb_header;
    G722SB_Encoder_Obj *EncObj;

    USC_CHECK_PTR(in);
    USC_CHECK_PTR(out);
    USC_CHECK_HANDLE(handle);

    USC_BADARG(in->pcmType.bitPerSample!=G722SB_BITS_PER_SAMPLE, USC_UnsupportedPCMType);
    USC_BADARG(in->pcmType.sample_frequency!=G722SB_SAMPLE_FREQ, USC_UnsupportedPCMType);
    USC_BADARG(in->pcmType.nChannels!=G722SB_NCHANNELS, USC_UnsupportedPCMType);

    USC_BADARG( NULL==in->pBuffer, USC_NoOperation );
    USC_BADARG( NULL==out->pBuffer, USC_NoOperation );

    g722sb_header = (G722SB_Handle_Header*)handle;

    if(g722sb_header->direction != USC_ENCODE) return USC_NoOperation;

    bitrate_idx = CheckRate_G722SB(in->bitrate);
    USC_BADARG( bitrate_idx < 0, USC_UnsupportedBitRate );
    USC_BADARG( in->nbytes <= 0, USC_NoOperation );

    g722sb_header->bitrate = in->bitrate;
    EncObj = (G722SB_Encoder_Obj *)((Ipp8s*)handle + sizeof(G722SB_Handle_Header));

    if(g722sb_header->hpf) {
      if(in->nbytes < g722sb_header->framesize) lenSamples = in->nbytes/sizeof(Ipp16s);
      else lenSamples = g722sb_header->framesize/sizeof(Ipp16s);

      if(apiG722SBEncode(EncObj, lenSamples, (Ipp16s*)in->pBuffer, out->pBuffer) != API_G722SB_StsNoErr){
        return USC_NoOperation;
      }
      in->nbytes = lenSamples*sizeof(Ipp16s);
      out->nbytes = getBitstreamSize(in, g722sb_header->hpf);
    } else {

      lenSamples = in->nbytes/sizeof(Ipp16s);

      in_buff = (Ipp16s*)in->pBuffer;
      out_buff = (Ipp16s*)out->pBuffer;
      for(i=0; i<lenSamples; i++) {
        if((in_buff[i] & 1) == 1) {
          apiG722SBEncoder_Init(EncObj, g722sb_header->hpf);
          out_buff[i] = 1;
        } else {
          if(apiG722SBEncode(EncObj, 1, (Ipp16s*)&in_buff[i], (Ipp8s *)&pOutBuff[0]) != API_G722SB_StsNoErr){
            return USC_NoOperation;
          }
          out_buff[i] = (Ipp16s)((Ipp16s)(pOutBuff[0] << 8) & 0xFF00);
        }
      }
      out->nbytes = in->nbytes;
    }

    out->frametype = 0;
    out->bitrate = in->bitrate;

    return USC_NoError;
}
Esempio n. 7
0
static USC_Status Init_VAD_G729FP(const USC_FilterOption *options, const USC_MemBank *pBanks, USC_Handle *handle)
{
    G729_Handle_Header *g729_header;
    VADmemory *VadObj;

    Ipp32s i;
    Ipp32s fltsize;
    void* pBuf;

    USC_CHECK_PTR(options);
    USC_CHECK_PTR(pBanks);
    USC_CHECK_PTR(pBanks[0].pMem);
    USC_BADARG(pBanks[0].nbytes<=0, USC_NotInitialized);
    USC_CHECK_PTR(pBanks[1].pMem);
    USC_BADARG(pBanks[1].nbytes<=0, USC_NotInitialized);
    USC_CHECK_HANDLE(handle);

    USC_BADARG(options->modes.vad > 1, USC_UnsupportedVADType);
    USC_BADARG(options->modes.vad < 0, USC_UnsupportedVADType);

    USC_BADARG(options->pcmType.sample_frequency < 1, USC_UnsupportedPCMType);
    USC_BADARG(options->pcmType.bitPerSample < 1, USC_UnsupportedPCMType);

    *handle = (USC_Handle*)pBanks[0].pMem;
    g729_header = (G729_Handle_Header*)*handle;

    g729_header->vad = options->modes.vad;
    VadObj = (VADmemory *)((Ipp8s*)*handle + sizeof(G729_Handle_Header));
    ippsZero_16s((Ipp16s*)VadObj,sizeof(VADmemory)>>1) ;

    if(pBanks[1].pMem==NULL) return USC_BadArgument;
    if(VadObj==NULL) return USC_BadArgument;

    if(NULL==VadObj || NULL==pBanks[1].pMem)
       return USC_BadArgument;

    VadObj->Mem.base = pBanks[1].pMem;
    VadObj->Mem.CurPtr = VadObj->Mem.base;
    VadObj->Mem.VecPtr = (Ipp32s *)(VadObj->Mem.base+VAD_G729FP_LOCAL_MEMORY_SIZE);

   if(NULL==VadObj)
      return USC_BadArgument;

   ippsZero_32f(VadObj->OldSpeechBuffer, SPEECH_BUFF_LEN);

   VadObj->objPrm.objSize = vadObjSize();
   VadObj->objPrm.mode = g729_header->vad;
   VadObj->objPrm.key = ENC_KEY;

   pBuf = (Ipp8s*)VadObj + sizeof(VADmemory);
   ippsIIRGetStateSize_32f(2,&fltsize);
   VadObj = (VADmemory *)((Ipp8s*)pBuf + fltsize);
   VADGetSize(&fltsize);

   /* Static vectors to zero */
   for(i=0; i<MOVING_AVER_ORDER; i++)
   VadObj->sFrameCounter = 0;
   /* For G.729B */
   /* Initialize VAD/DTX parameters */
   //if(mode == G729Encode_VAD_Enabled) {
      VadObj->prevVADDec = 1;
      VadObj->prevPrevVADDec = 1;
      VADInit((Ipp8s*)VadObj);
   //}

    if(pBanks[1].pMem==NULL) return USC_BadArgument;
    if(VadObj==NULL) return USC_BadArgument;

    if(NULL==VadObj || NULL==pBanks[1].pMem)
       return USC_BadArgument;

    VadObj->Mem.base = pBanks[1].pMem;
    VadObj->Mem.CurPtr = VadObj->Mem.base;
    VadObj->Mem.VecPtr = (Ipp32s *)(VadObj->Mem.base+VAD_G729FP_LOCAL_MEMORY_SIZE);

    return USC_NoError;
}