📄 player11.c
字号:
/*//////////////////////////////////////////////////////////////////////////// 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-2007 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 ippEULA.rtf or ippEULA.txt 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"#include "usc.h"#include "util.h"#include "loadcodec.h"#include "wavfile.h"#include "usccodec.h"#include "vm_time.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-2007 Intel Corporation. All Rights Reserved."vm_time measure;vm_time_handle handle;Ipp64f dTime = 0.;Ipp32s ProcessOneFrameOneChannel(USCParams *uscPrms, Ipp8s *inputBuffer, Ipp8s *outputBuffer, Ipp32s *pSrcLenUsed, Ipp32s *pDstLenUsed){ Ipp32s frmlen, infrmLen, FrmDataLen; USC_PCMStream PCMStream; USC_Bitstream Bitstream; if(uscPrms->pInfo->params.direction==USC_ENCODE) { /*Do the pre-procession of the frame*/ infrmLen = USCEncoderPreProcessFrame(uscPrms, inputBuffer, outputBuffer,&PCMStream,&Bitstream); /*Encode one frame*/ vm_time_start(handle, &measure); FrmDataLen = USCCodecEncode(uscPrms, &PCMStream,&Bitstream); dTime = vm_time_stop(handle, &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*/ vm_time_start(handle, &measure); FrmDataLen = USCCodecDecode(uscPrms, &Bitstream,&PCMStream); dTime = vm_time_stop(handle, &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)Ipp32s ProcessOneChannel(LoadedCodec *codec, WaveFileParams *wfOutputParams, Ipp8s *inputBuffer, Ipp32s inputLen, Ipp8s *outputBuffer, Ipp32s *pDuration, Ipp32s *dstLen){ Ipp32s duration=0, outLen = 0, currLen; Ipp8s *pInputBuffPtr = inputBuffer; Ipp32s frmlen, infrmLen, cvtLen; Ipp32s lLowBound; currLen = inputLen; USCCodecGetTerminationCondition(&codec->uscParams, &lLowBound); while(currLen > lLowBound) { ProcessOneFrameOneChannel(&codec->uscParams, pInputBuffPtr, outputBuffer, &infrmLen, &frmlen); /* 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;}extern USC_Fxns USC_G723_Fxns; /* this time linked for example to G729Icodec */USC_Fxns *USC_Gxxx_Fnxs = &USC_G723_Fxns;#define PCMDATA_LEN 10000 /* some input PCM data length */static char* outputBuffer = NULL;static unsigned char foo[PCMDATA_LEN]={0}; /* foo: supposed to be filledwith input PCM data */static char* inputBuffer = NULL;static unsigned char fooUncompressed[PCMDATA_LEN]; typedef struct { USC_Direction direction; Ipp32s bitrate; Ipp32s vad; Ipp32s hpf; Ipp32s pf; Ipp32s reserved0; // for future extension Ipp32s reserved1; // for future extension Ipp32s reserved2; // for future extension} G723_Handle_Header;int WriteLog(int use){ if ( use ){ printf("Usage : g723encoder <options> <inFile> <outFile> \n" ); printf(" encode 16bit 8000 Hz PCM speech input file\n"); printf("to bitstream output file\n"); printf("contains octets written in transmitting order.\n"); printf("[-r63|r53] bit rate 6.3 or 5.3 kbit/s\n"); } return 0;}int main(Ipp32s argc, Ipp8s *argv[]){ /* Locals */ USC_CodecInfo *pInfo; int infoSize; int i, nbanksEnc,nbanksDec; USC_MemBank* pBanksEnc; USC_MemBank* pBanksDec; USC_Handle hUSCEncoder; USC_Handle hUSCDecoder; int lenDst, bytesRemaining; char* tmpInputBuff=NULL; char* tmpOutputBuff=NULL; char* tmpOutputPCMBuff=NULL; static int lenSrc = 0; FILE *f_in=NULL; /* input File */ FILE *f_out=NULL; /* output File */ int mRat = 0; G723_Handle_Header g723handle; int usage = 0; g723handle.bitrate = 6300; g723handle.direction = USC_ENCODE; g723handle.vad = 0; g723handle.hpf = 0; g723handle.pf = 1; if(argc <4) { usage = 1; WriteLog(1); return 0 ; } if(strcmp(argv[1],"r53") == 0) { g723handle.bitrate = 5300; mRat = 0; } else if(strcmp(argv[1],"r63") == 0) { g723handle.bitrate = 6300; mRat = 1; } else { WriteLog(1); return 0 ; } printf("inputfile =%s \r\n",argv[2]); printf("outfile =%s \r\n",argv[3]); if((f_in = fopen(argv[2], "rb")) == NULL) { return (2); } if((f_out = fopen(argv[3], "wb")) == NULL) { return (2); } fseek(f_in,0,SEEK_END); lenSrc = ftell(f_in); lenSrc = lenSrc -46; inputBuffer = (char*)malloc(lenSrc); rewind(f_in); fread(inputBuffer,1,46,f_in); fread(inputBuffer,1,lenSrc,f_in); ippStaticInit(); if(USC_NoError != USC_Gxxx_Fnxs->std.GetInfoSize(&infoSize)) { exit(1); } pInfo = (USC_CodecInfo *)malloc(infoSize); if(USC_NoError != USC_Gxxx_Fnxs->std.GetInfo((USC_Handle)&g723handle, pInfo)) { exit(1); } if(USC_NoError != USC_Gxxx_Fnxs->std.NumAlloc(&pInfo->params, &nbanksEnc)) exit(2); pBanksEnc = (USC_MemBank*)malloc(sizeof(USC_MemBank)*nbanksEnc); if(USC_NoError != USC_Gxxx_Fnxs->std.MemAlloc(&pInfo->params, pBanksEnc)) exit(3); for(i=0; i<nbanksEnc;i++) { pBanksEnc[i].pMem = (unsigned char*)malloc(pBanksEnc[i].nbytes); } if(USC_NoError != USC_Gxxx_Fnxs->std.Init(&pInfo->params, pBanksEnc, &hUSCEncoder)) exit(4); if(USC_NoError != USC_Gxxx_Fnxs->std.GetInfo(hUSCEncoder, pInfo)) exit(1); printf("bitrate =%d ,bitPerSample =%d,nChannels=%d,sample_frequency =%d \r\n", pInfo->params.modes.bitrate, pInfo->params.pcmType.bitPerSample, pInfo->params.pcmType.nChannels, pInfo->params.pcmType.sample_frequency); if(USC_NoError != USC_Gxxx_Fnxs->GetOutStreamSize(&pInfo->params,pInfo->params.modes.bitrate, lenSrc, &lenDst)) exit(5); outputBuffer = (char*)malloc(lenDst); bytesRemaining = lenSrc; tmpInputBuff = inputBuffer; tmpOutputBuff = outputBuffer; printf("wait..."); while(bytesRemaining >= pInfo->params.framesize) { USC_PCMStream in ; USC_Bitstream out; in.bitrate = pInfo->params.modes.bitrate; in.nbytes = bytesRemaining; in.pBuffer = tmpInputBuff; in.pcmType.bitPerSample = pInfo->params.pcmType.bitPerSample; in.pcmType.nChannels = pInfo->params.pcmType.nChannels; in.pcmType.sample_frequency = pInfo->params.pcmType.sample_frequency; out.pBuffer = tmpOutputBuff; if(USC_NoError != USC_Gxxx_Fnxs->Encode (hUSCEncoder, &in, &out)) exit(6); printf("."); tmpInputBuff += in.nbytes; tmpOutputBuff += out.nbytes; bytesRemaining -= in.nbytes; } fwrite(outputBuffer, 1, lenDst, f_out); if(f_out) fclose(f_out); if(f_in) fclose(f_in); for(i=0; i<nbanksEnc;i++) { free(pBanksEnc[i].pMem); } free(pBanksEnc); free(pInfo); printf("conver ok \r\n"); return 0;}#if defined( _WIN32_WCE )#define WINCE_CMDLINE_SIZE 512#define WINCE_EXENAME_SIZE 128#define WINCE_NCMD_PARAMS 16Ipp32s parseCmndLine( Ipp8s* exename, const Ipp8s* cmndline, Ipp8s* line, Ipp32s linelen, Ipp8s** argv, Ipp32s argvlen ) { Ipp32s i; Ipp8s* token; Ipp8s* seps = " ,"; /* argement separators */ Ipp32s 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 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -