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

📄 player.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: Speech sample. Main program file.
//
////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ippcore.h"
#include "ipps.h"
#include "ippsc.h"

#ifdef USE_PLUGINS
#include "vm_shared_object.h"
#endif /*USE_PLUGINS*/

#include "usc.h"

#include "util.h"
#include "loadcodec.h"
#include "wavfile.h"
#include "usccodec.h"
#include "platform.h"

#define LOAD_CODEC_FAIL     1
#define FOPEN_FAIL          2
#define MEMORY_FAIL         3
#define UNKNOWN_FORMAT      4
#define USC_CALL_FAIL       5


#define COPYRIGHT_STRING "Copyright (c) 2005 Intel Corporation. All Rights Reserved."
MeasureIt measure;
int ProcessOneFrameOneChannel(USCParams *uscPrms, char *inputBuffer,
                              char *outputBuffer, int *pSrcLenUsed, int *pDstLenUsed, int channel)
{
   int frmlen, infrmLen, FrmDataLen;
   USC_PCMStream PCMStream;
   USC_Bitstream Bitstream;
   if(uscPrms->pInfo.params.direction==0) {
      /*Do the pre-procession of the frame*/
      infrmLen = USCEncoderPreProcessFrame(uscPrms, inputBuffer,
                                             outputBuffer,&PCMStream,&Bitstream);
      /*Encode one frame*/
      measure_start(&measure);
      FrmDataLen = USCCodecEncode(uscPrms, &PCMStream,&Bitstream,channel);
      measure_pause(&measure);
      if(FrmDataLen < 0) return USC_CALL_FAIL;
      infrmLen += FrmDataLen;
      /*Do the post-procession of the frame*/
      frmlen = USCEncoderPostProcessFrame(uscPrms, inputBuffer,
                                             outputBuffer,&PCMStream,&Bitstream);
      *pSrcLenUsed = infrmLen;
      *pDstLenUsed = frmlen;
   } else {
      /*Do the pre-procession of the frame*/
      infrmLen = USCDecoderPreProcessFrame(uscPrms, inputBuffer,
                                             outputBuffer,&Bitstream,&PCMStream);
      /*Decode one frame*/
      measure_start(&measure);
      FrmDataLen = USCCodecDecode(uscPrms, &Bitstream,&PCMStream,channel);
      measure_pause(&measure);
      if(FrmDataLen < 0) return USC_CALL_FAIL;
      infrmLen += FrmDataLen;
      /*Do the post-procession of the frame*/
      frmlen = USCDecoderPostProcessFrame(uscPrms, inputBuffer,
                                             outputBuffer,&Bitstream,&PCMStream);
      *pSrcLenUsed = infrmLen;
      *pDstLenUsed = frmlen;
   }
   return 0;
}
#define MAX_LEN(a,b) ((a)>(b))? (a):(b)
int ProcessOneChannel(LoadedCodec *codec, WaveFileParams *wfOutputParams, char *inputBuffer,
                              int inputLen, char *outputBuffer, int *pDuration, int *dstLen)
{
   int duration=0, outLen = 0, currLen;
   char *pInputBuffPtr = inputBuffer;
   int frmlen, infrmLen, cvtLen;
   int lLowBound;
   currLen = inputLen;

   USCCodecGetTerminationCondition(&codec->uscParams, &lLowBound);

   while(currLen > lLowBound) {
      ProcessOneFrameOneChannel(&codec->uscParams, pInputBuffPtr,
                              outputBuffer, &infrmLen, &frmlen,SINGLE_CHANNEL);
      /* Write encoded data to the output file*/
      cvtLen = frmlen;
      if((wfOutputParams->waveFmt.nFormatTag==ALAW_PCM)||(wfOutputParams->waveFmt.nFormatTag==MULAW_PCM)) {
         USC_CvtToLaw(&codec->uscParams, wfOutputParams->waveFmt.nFormatTag, outputBuffer, &cvtLen);
      }
      WavFileWrite(wfOutputParams, outputBuffer, cvtLen);
      /* Move pointer to the next position*/
      currLen -= infrmLen;
      pInputBuffPtr += infrmLen;
      duration += MAX_LEN(infrmLen,frmlen);
      outLen += frmlen;
   }

   *pDuration = duration;
   *dstLen = outLen;
   return 0;
}

#if defined( _WIN32_WCE )
#define WINCE_CMDLINE_SIZE 512
#define WINCE_EXENAME_SIZE 128
#define WINCE_NCMD_PARAMS   16
int parseCmndLine( char* exename, const char* cmndline, char* line, int linelen, char** argv, int argvlen ) {
   int i;
   char* token;
   char* seps = " ,";                     /* argement separators */
   int argc = 1;                          /* number of parameters */
   for (i=0; i<argvlen; i++) argv[i] = NULL;
   argv[0] = exename;                     /* the first standard argument */
   memset( line, 0, linelen );
   strncpy( line, cmndline, linelen-1 );
   token = strtok( line, seps );          /* the first true argument */
   while( token != NULL && argc <= argvlen ) {
      argv[argc++] = token;
      token = strtok( NULL, seps );
   }
   return argc;
}

int WINAPI WinMain( HINSTANCE hinst, HINSTANCE xxx, LPWSTR lpCmdLine, int yyy )
{
   char line[WINCE_CMDLINE_SIZE];                     /* to copy command line */
   char* argvv[WINCE_NCMD_PARAMS];
   char** argv=argvv;

   wchar_t wexename[WINCE_EXENAME_SIZE];
   char exename[WINCE_EXENAME_SIZE];
   char cmdline[WINCE_CMDLINE_SIZE];

   /* simulate argc and argv parameters */
   int argc;
#else /*Other OS*/
int main(int argc, char *argv[])
{
#endif /*_WIN32_WCE*/
   int lCallResult, encode;
   int PCMType = -1;
   LoadedCodec codec;
   WaveFileParams wfInputParams;
   WaveFileParams wfOutputParams;
   CommandLineParams clParams;
   char *inputBuffer=NULL;
   char *outputBuffer=NULL;
   int currLen, duration;
   const  IppLibraryVersion *verIppSC;
   float spSeconds;
   FILE *f_log=NULL;

#if defined( _WIN32_WCE )

   GetModuleFileName( hinst, wexename, WINCE_EXENAME_SIZE );
   sprintf( exename, "%ls", wexename );
   sprintf( cmdline, "%ls", lpCmdLine );
   argc = parseCmndLine( exename, cmdline, line, WINCE_CMDLINE_SIZE, argv, WINCE_NCMD_PARAMS );

#endif
   /*
      Dynamic re-linkage from PX to target IPP library,
      need only if codec was linked with ippmerged lib
   */

   ippStaticInit();

#ifdef USE_PLUGINS
   codec.handleCodecDLL = NULL;
   codec.handleFormatDLL = NULL;
#endif /*USE_PLUGINS*/

   SetCommandLineByDefault(&clParams);
   /*Get params from comman line.*/
   ReadCommandLine(&clParams, argc, argv);
   if(clParams.puttologfile) {
      f_log=fopen(clParams.logFileName,"a");
      if(f_log==NULL) {
         printf("Cannot open %s log file for writing\n",clParams.logFileName);
         printf("Log file ignored.\n");
         clParams.puttologfile = 0;
      }
   }

   if(clParams.optionReport) {
      verIppSC = ippscGetLibVersion();
      if(clParams.puttologfile) {
         fprintf(f_log,"%s\n",COPYRIGHT_STRING);
         fprintf(f_log,"Intel Unified Speech Codec interface based console player\n");
         fprintf(f_log,"The Intel(R) IPPSC library used:  %d.%d.%d Build %d, name %s\n",
             verIppSC->major,verIppSC->minor,verIppSC->majorBuild,verIppSC->build,verIppSC->Name);
      } else {
         printf("%s\n",COPYRIGHT_STRING);
         printf("Intel Unified Speech Codec interface based console player\n");
         printf("The Intel(R) IPPSC library used:  %d.%d.%d Build %d, name %s\n",
             verIppSC->major,verIppSC->minor,verIppSC->majorBuild,verIppSC->build,verIppSC->Name);
      }
   }

   if(clParams.enumerate) {
      EnumerateStaticLinkedCodecs(f_log);
      if(f_log) fclose(f_log);
      return 0;
   }

   if((!clParams.inputFileName[0]) ||(!clParams.outputFileName[0])) {
      PrintUsage();
      return 0;
   }
   /*Open inpuit file and read header*/
   InitWavFile(&wfInputParams);
   lCallResult = OpenWavFile(&wfInputParams, clParams.inputFileName, FILE_READ);
   if(lCallResult==-1) {
      if(clParams.puttologfile) {
         fprintf(f_log,"Cannot open %s file for reading\n",clParams.inputFileName);
      } else {
         printf("Cannot open %s file for reading\n",clParams.inputFileName);
      }
      if(f_log) fclose(f_log);
      return FOPEN_FAIL;
   }
   /*Read WAVE file header*/
   lCallResult = WavFileReadHeader(&wfInputParams);
   if(lCallResult<0) {
      if(clParams.puttologfile) {
         if(lCallResult==-1) fprintf(f_log,"Couldn't read from the %s file\n",clParams.inputFileName);
         if(lCallResult==-2) fprintf(f_log,"File %s isn't in RIFF format\n",clParams.inputFileName);
         if(lCallResult==-3) fprintf(f_log,"File %s is in RIFF format but not in a WAVE foramt\n",
                                       clParams.inputFileName);
      } else {
         if(lCallResult==-1) printf("Couldn't read from the %s file\n",clParams.inputFileName);
         if(lCallResult==-2) printf("File %s isn't in RIFF format\n",clParams.inputFileName);
         if(lCallResult==-3) printf("File %s is in RIFF format but not in a WAVE foramt\n",
                                       clParams.inputFileName);

⌨️ 快捷键说明

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