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

📄 usccodec.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*////////////////////////////////////////////////////////////////////////
//
// 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 Intel Corporation. All Rights Reserved.
//
//   Intel(R)  Integrated Performance Primitives
//
//     USC speech codec sample
//
// By downloading and installing this sample, 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 ipplic.htm located in the root directory of your Intel(R) IPP
// product installation for more information.
//
// Purpose: USC wrapper functions file.
//
////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#include <stdlib.h>
#include "usc.h"
#include "util.h"
#include "usccodec.h"
#include "ipps.h"

#define FRAME_HEADER_SIZE 6

static int checkBitrate(USCParams *uscPrms, int bitrate)
{
   int i;
   for(i=0;i<uscPrms->pInfo.nRates;i++) {
      if(uscPrms->pInfo.pRateTbl[i].bitrate==bitrate) return 1;
   }
   return 0;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCCodecGetInfo
//  Purpose:     Retrive info from USC codec.
//  Returns:     0 if success, -1 if fails.
//  Parameters:
//    uscPrms       pointer to the input USC codec parametres.
*/
int USCCodecGetInfo(USCParams *uscPrms)
{
   USC_Status status;
   status = uscPrms->USC_Fns->std.GetInfo((USC_Handle)NULL, &uscPrms->pInfo);
   if(status!=USC_NoError) return -1;
   return 0;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        SetUSCEncoderParams
//  Purpose:     Set encode params.
//  Returns:     None.
//  Parameters:
//    uscPrms       pointer to the input\output USC codec parametres.
//    cmdParams     pointer to the input parametres from command line.
*/
void SetUSCEncoderParams(USCParams *uscPrms, CommandLineParams *cmdParams)
{
   uscPrms->pInfo.params.direction = 0;
   if(cmdParams->Vad > uscPrms->pInfo.params.modes.vad) {
      printf("WARNING: Unsupported VAD type. Ignored\n");
      uscPrms->pInfo.params.modes.vad = 0;
   } else
      uscPrms->pInfo.params.modes.vad = cmdParams->Vad;

   uscPrms->pInfo.params.law = 0;

   if(checkBitrate(uscPrms, cmdParams->bitrate))
      uscPrms->pInfo.params.modes.bitrate = cmdParams->bitrate;
   else
      printf("WARNING: Unsupported rate. Used default: %d\n",uscPrms->pInfo.params.modes.bitrate);

   return;
}

/* /////////////////////////////////////////////////////////////////////////////
//  Name:        SetUSCDecoderParams
//  Purpose:     Set decode params.
//  Returns:     None.
//  Parameters:
//    uscPrms       pointer to the input\output USC codec parametres.
//    cmdParams     pointer to the input parametres from command line.
*/
void SetUSCDecoderParams(USCParams *uscPrms, CommandLineParams *cmdParams)
{
   uscPrms->pInfo.params.direction = 1;
   uscPrms->pInfo.params.law = 0;
   if(checkBitrate(uscPrms, cmdParams->bitrate))
      uscPrms->pInfo.params.modes.bitrate = cmdParams->bitrate;
   return;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCCodecAlloc
//  Purpose:     Alloc memory for USC codec.
//  Returns:     0 if success, -1 if fails.
//  Parameters:
//    uscPrms       pointer to the input\output USC codec parametres.
//    cmdParams     pointer to the input parametres from command line.
*/
USC_Status USCCodecAlloc(USCParams *uscPrms, CommandLineParams *cmdParams)
{
   int i,j;
   USC_Status status;
   status = uscPrms->USC_Fns->std.NumAlloc(&uscPrms->pInfo.params, &uscPrms->nbanks);
   if(status!=USC_NoError) return -1;

   for(j=0;j<uscPrms->nChannels;j++) {
      uscPrms->uCodec[j].pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*uscPrms->nbanks);
      if (!uscPrms->uCodec[j].pBanks)
         return -1;
      status = uscPrms->USC_Fns->std.MemAlloc(&uscPrms->pInfo.params, uscPrms->uCodec[j].pBanks);
      if(status!=USC_NoError) return -1;

      for(i=0; i<uscPrms->nbanks;i++){
         uscPrms->uCodec[j].pBanks[i].pMem = (unsigned char*)ippsMalloc_8u(uscPrms->uCodec[j].pBanks[i].nbytes);
      }
      for(i=0; i<uscPrms->nbanks;i++){
         if (!uscPrms->uCodec[j].pBanks[i].pMem)
            return -1;
      }
   }

   return 0;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCEncoderInit
//  Purpose:     Initialize USC encoder object.
//  Returns:     0 if success, -1 if fails.
//  Parameters:
//    uscPrms       pointer to the input\output USC codec parametres.
//    cmdParams     pointer to the input parametres from command line.
*/
int USCEncoderInit(USCParams *uscPrms, CommandLineParams *cmdParams)
{
   USC_Status status;
   int j;
   for(j=0;j<uscPrms->nChannels;j++) {
      status = uscPrms->USC_Fns->std.Init(&uscPrms->pInfo.params, uscPrms->uCodec[j].pBanks,
                                       &uscPrms->uCodec[j].hUSCCodec);
      if(status!=USC_NoError) return -1;
      /*How to change frame size:
         status = uscPrms->USC_Fns->SetFrameSize(&uscPrms->pInfo.params,uscPrms->uCodec[j].hUSCCodec,160);
         if(status!=USC_NoError) return -1;
         status = uscPrms->USC_Fns->std.GetInfo(uscPrms->uCodec[j].hUSCCodec, &uscPrms->pInfo);
         if(status!=USC_NoError) return -1;
      */
   }
   return 0;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCEncoderInit
//  Purpose:     Initialize USC decoder object.
//  Returns:     0 if success, -1 if fails.
//  Parameters:
//    uscPrms       pointer to the input\output USC codec parametres.
//    cmdParams     pointer to the input parametres from command line.
*/
int USCDecoderInit(USCParams *uscPrms, CommandLineParams *cmdParams)
{
   USC_Status status;
   int j;
   for(j=0;j<uscPrms->nChannels;j++) {
      status = uscPrms->USC_Fns->std.Init(&uscPrms->pInfo.params, uscPrms->uCodec[j].pBanks,
                                             &uscPrms->uCodec[j].hUSCCodec);
      if(status!=USC_NoError) return -1;
      /*How to change frame size:
         status = uscPrms->USC_Fns->SetFrameSize(&uscPrms->pInfo.params,uscPrms->uCodec[j].hUSCCodec,160);
         if(status!=USC_NoError) return -1;
         status = uscPrms->USC_Fns->std.GetInfo(uscPrms->uCodec[j].hUSCCodec, &uscPrms->pInfo);
         if(status!=USC_NoError) return -1;
      */
   }
   return 0;
}

/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCEncoderPreProcessFrame
//  Purpose:     Pre-process frame to encode.
//  Returns:     lenght of written data to the output stream.
//  Parameters:
//    uscPrms   pointer to the input USC codec parametres.
//    pSrc      pointer to the input PCM data.
//    pDst      pointer to the output bitstream data.
//    in        pointer to the output USC_PCMStream structure for the frame.
//    out       pointer to the output USC_Bitstream structure for the frame.
*/
int USCEncoderPreProcessFrame(USCParams *uscPrms, char *pSrc, char *pDst,USC_PCMStream *in,USC_Bitstream *out)
{
   in->bitrate = uscPrms->pInfo.params.modes.bitrate;
   in->nbytes = uscPrms->pInfo.framesize;
   in->pBuffer = pSrc;
   in->pcmType.bitPerSample = uscPrms->pInfo.pcmType.bitPerSample;
   in->pcmType.sample_frequency = uscPrms->pInfo.pcmType.sample_frequency;
   out->pBuffer = pDst+FRAME_HEADER_SIZE;
   return 0;
}

/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCEncoderPostProcessFrame
//  Purpose:     Post-process of encoded frame.
//  Returns:     lenght of written data to the output stream.
//  Parameters:
//    uscPrms   pointer to the input USC codec parametres.
//    pSrc      pointer to the input PCM data.
//    pDst      pointer to the output bitstream data.
//    in        pointer to the output USC_PCMStream structure for the frame.
//    out       pointer to the output USC_Bitstream structure for the frame.
*/
int USCEncoderPostProcessFrame(USCParams *uscPrms, char *pSrc, char *pDst,USC_PCMStream *in,USC_Bitstream *out)
{
   unsigned char tmp;
   tmp = ((unsigned int)out->bitrate)>>16;
   pDst[0] = (char)(tmp&0xFF);

⌨️ 快捷键说明

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