Beispiel #1
0
static USC_Status Encode(USC_Handle handle, USC_PCMStream *in, USC_Bitstream *out)
{
    AMRWB_Handle_Header *amrwb_header;
    int bitrate_idx;
    AMRWBEncoder_Obj *EncObj;
    unsigned short work_buf[AMRWB_Frame];
    int WrkRate, out_WrkRate;

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

    amrwb_header = (AMRWB_Handle_Header*)handle;

    if(amrwb_header == NULL) return USC_InvalidHandler;
     bitrate_idx = CheckRate_AMRWB(in->bitrate);
     if(bitrate_idx < 0) return USC_UnsupportedBitRate;
     amrwb_header->bitrate = in->bitrate;

    EncObj = (AMRWBEncoder_Obj *)((char*)handle + sizeof(AMRWB_Handle_Header));

    /* check for homing frame */
    amrwb_header->reset_flag = ownTestPCMFrameHoming((short*)in->pBuffer);

    if (amrwb_header->trunc) {
       /* Delete the LSBs */
       ippsAndC_16u((Ipp16u*)in->pBuffer, (Ipp16u)IO_MASK, work_buf, AMRWB_Frame);
//       int i;
//       short *pPCM = (short *)in->pBuffer;
//       for (i = 0; i < AMRWB_Frame; i ++) work_buf[i] = (IO_MASK & pPCM[i]);
    } else {
       ippsCopy_16s((const Ipp16s*)in->pBuffer, (Ipp16s*)work_buf, AMRWB_Frame);
    }

    WrkRate = usc2amrwb[bitrate_idx];
    if(apiAMRWBEncode(EncObj,(const unsigned short*)work_buf,(unsigned char*)out->pBuffer,(AMRWB_Rate_t *)&WrkRate,EncObj->iDtx) != APIAMRWB_StsNoErr){
       return USC_NoOperation;
    }
    /* include frame type and mode information in serial bitstream */
    ownSidSync(&amrwb_header->sid_state, WrkRate, (TXFrameType *)&out->frametype);

     out->nbytes = getBitstreamSize(bitrate_idx, out->frametype, &out_WrkRate);
     out->bitrate = CheckIdxRate_AMRWB(out_WrkRate);

    if (amrwb_header->reset_flag != 0) {
        ownSidSyncInit(&amrwb_header->sid_state);
        apiAMRWBEncoder_Init(EncObj, EncObj->iDtx);
    }

    in->nbytes = AMRWB_Frame*sizeof(short);
    return USC_NoError;
}
Beispiel #2
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;
}
Beispiel #3
0
static USC_Status Decode(USC_Handle handle, USC_Bitstream *in, USC_PCMStream *out)
{
    AMRWB_Handle_Header *amrwb_header;
    AMRWBDecoder_Obj *DecObj;
    int bitrate_idx;
    int mode;
    RXFrameType rx_type;
    short prm[56];

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

    amrwb_header = (AMRWB_Handle_Header*)handle;
    DecObj = (AMRWBDecoder_Obj *)((char*)handle + sizeof(AMRWB_Handle_Header));

    if(in == NULL) {
       bitrate_idx = CheckRate_AMRWB(amrwb_header->bitrate_old);
       if(bitrate_idx < 0) return USC_UnsupportedBitRate;

       amrwb_header->bitrate = amrwb_header->bitrate_old;
       out->bitrate = amrwb_header->bitrate_old;
       rx_type = RX_SPEECH_LOST;

       if(apiAMRWBDecode(DecObj,(const unsigned char*)LostFrame, usc2amrwb[bitrate_idx],rx_type,(unsigned short*)out->pBuffer) != APIAMRWB_StsNoErr){
            return USC_NoOperation;
      }
      if(amrwb_header->trunc) {
          ippsAndC_16u_I((Ipp16u)IO_MASK, (unsigned short*)out->pBuffer, AMRWB_Frame);
//          int i;
//          short *pPCM = (short *)out->pBuffer;
//          for (i = 0; i < AMRWB_Frame; i ++) pPCM[i] &= IO_MASK;
      }
      amrwb_header->reset_flag = 0;
      amrwb_header->reset_flag_old = 1;

      out->nbytes = AMRWB_Frame*sizeof(short);

    } else {
       if(in->nbytes<=0) return USC_NoOperation;
       bitrate_idx = CheckRate_AMRWB(in->bitrate);
       if(bitrate_idx < 0) return USC_UnsupportedBitRate;
       amrwb_header->bitrate = in->bitrate;
      out->bitrate = in->bitrate;
      rx_type = ownTX2RX((TXFrameType)in->frametype);

      if ((rx_type == RX_SID_BAD) || (rx_type == RX_SID_UPDATE) || (rx_type == RX_NO_DATA)) {
         mode = AMRWB_RATE_DTX;
      } else {
           mode = bitrate_idx;
      }
      if ((rx_type == RX_SPEECH_LOST)) {
         out->bitrate = amrwb_header->usedRate;
         amrwb_header->reset_flag = 0;
      } else {
         amrwb_header->usedRate = out->bitrate;
         /* if homed: check if this frame is another homing frame */
         ownConvert15(mode,in->pBuffer, prm);
         amrwb_header->reset_flag = ownTestBitstreamFrameHoming(prm, mode);
      }

      /* produce encoder homing frame if homed & input=decoder homing frame */
      if ((amrwb_header->reset_flag != 0) && (amrwb_header->reset_flag_old != 0))
      {
         ippsSet_16s(EHF_MASK, (short*)out->pBuffer, AMRWB_Frame);
      }
      else
      {
         if(apiAMRWBDecode(DecObj,(const unsigned char*)in->pBuffer,usc2amrwb[bitrate_idx],rx_type,(unsigned short*)out->pBuffer) != APIAMRWB_StsNoErr){
            return USC_NoOperation;
         }
         if (amrwb_header->trunc) {
            /* Truncate LSBs */
            ippsAndC_16u_I((Ipp16u)IO_MASK, (unsigned short*)out->pBuffer, AMRWB_Frame);
//            int i;
//            short *pPCM = (short *)out->pBuffer;
//            for (i = 0; i < AMRWB_Frame; i ++) pPCM[i] &= IO_MASK;
         }
      }
      /* reset decoder if current frame is a homing frame */
      if (amrwb_header->reset_flag != 0)
      {
         apiAMRWBDecoder_Init((AMRWBDecoder_Obj*)DecObj);
           amrwb_header->usedRate = 6600;
      }
      amrwb_header->reset_flag_old = amrwb_header->reset_flag;

       out->nbytes = AMRWB_Frame*sizeof(short);
       {
          int foo;
          in->nbytes = getBitstreamSize(bitrate_idx, in->frametype, &foo);
       }
    }

   return USC_NoError;
}