Example #1
0
static USC_Status Reinit(const USC_Modes *modes, USC_Handle handle )
{
    Ipp32s bitrate_idx;
    G722SB_Handle_Header *g722sb_header;

    USC_CHECK_PTR(modes);
    USC_CHECK_HANDLE(handle);

    g722sb_header = (G722SB_Handle_Header*)handle;

    bitrate_idx = CheckRate_G722SB(modes->bitrate);
    if(bitrate_idx < 0) return USC_UnsupportedBitRate;
    g722sb_header->hpf = modes->hpf;
    g722sb_header->pf = modes->pf;
    g722sb_header->bitrate = modes->bitrate;

    if (g722sb_header->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 (g722sb_header->direction == USC_DECODE) /* decode only */
    {
      G722SB_Decoder_Obj *DecObj = (G722SB_Decoder_Obj *)((Ipp8s*)handle + sizeof(G722SB_Handle_Header));
      apiG722SBDecoder_Init(DecObj, g722sb_header->pf);
    } else {
        return USC_NoOperation;
    }
    return USC_NoError;
}
Example #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;
}
Example #3
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;
}