📄 g723_api.c
字号:
/* Standard definitions */#include <stdio.h>#include <time.h>/* Ipp definitions */#include <g723_def.h>#include <g723_codec.h>#include <g723_api.h>/* Timer globals */performanceTimer timer[TIMER_NUM_MAX];int totalTimers;// Add timer n, including all necessary memory allocation int timerInit(int n, char *label){ int i=0; while(label[i]!='\0') timer[n].label[i]=label[i++]; timer[n].label[i]='\0'; timerSetFreq(n,0); timer[n].acc=0; timer[n].blockCount=0; return(1);}// Set number of performance timers int timerSetNum(int numTimers){ totalTimers=numTimers; return(1);}// Get number of performance timers int timerGetNum(int *numTimers){ *numTimers=totalTimers; return(1);}// Reset timer n int timerReset(int n){ timer[n].acc=0; timerSetNumBlocks(n,0); return(1);}// Record start time, timer n int timerStart(int n){ timer[n].tStart=clock(); return(1);}// Record stop time, timer n int timerStop(int n){ timer[n].tStop=clock(); return(1);}// Accumulate tStop-tStart, increment block counter int timerDeltaAcc(int n){ timer[n].acc+=(timer[n].tStop-timer[n].tStart); timer[n].blockCount++; return(1);}// Set block size for timer n int timerSetBlockSize(int n, int size){ timer[n].blockSize = size; return(1);}// Query block size for timer n int timerGetBlockSize(int n, int *blockSize){ *blockSize=timer[n].blockSize; return(1);}// Set number blocks for timer nint timerSetNumBlocks(int n, int newBlockCount){ timer[n].blockCount=newBlockCount; return(1);}// Get number blocks for timer nint timerGetNumBlocks(int n, int *blockCount){ *blockCount=timer[n].blockCount; return(1);}// Query accumulator for timer nint timerGetAcc(int n, int *timerAcc){ *timerAcc = timer[n].acc; return(1);}// Get label of timer n int timerGetLabel(int n, void *label){ strcpy((char *)label,timer[n].label); return(1);}// Set timer n frequencyint timerSetFreq(int n, int freq){ timer[n].freq=freq; return(1);}// Get timer n frequencyint timerGetFreq(int n, int *timerFreq){ *timerFreq = (int)timer[n].freq; return(1);}// Compute CPU utilization (%) given sample rate, block size, and timer measurementsfloat getCpuUtilization(int n, int sampleRate){ int acc; int blkSize; int numBlocks; int freq; float percentCpu=0; /* %CPU = Avg CPU time per frame / frame duration tcpu (seconds) = acc/(frameNum*timerFreq) = avg frame CPU time tframe (seconds) = # samples / fs %CPU = 100 * (tcpu/tframe) = 100 * acc * fs / (frameNum * # samples per frame * timerFreq) */ timerGetAcc(n,&acc); timerGetNumBlocks(n,&numBlocks); timerGetBlockSize(n,&blkSize); timerGetFreq(n,&freq); if (numBlocks>0) { percentCpu = ( (float) 100.0 * (float) acc * (float) sampleRate ) / ( (float) numBlocks * (float) blkSize * (float) freq ); } return(percentCpu);}int destroyCodec_G723(IppPcmStream *inputSpeech, IppPcmStream *outputSpeech, IppBitstream *bitstream){ /* Free all stream and string buffers */ free(inputSpeech->pBuf); free(outputSpeech->pBuf); free(bitstream->pBuf); return(1);}int initCodec_G723(IppG723EncoderState *encState, IppG723DecoderState *decState, IppPcmStream *inputSpeech, IppPcmStream *outputSpeech, IppBitstream *bitstream, int pcmBufLen, int bitstreamBufLen){ /* Init codec */ EncoderInit_G723(encState); DecoderInit_G723(decState); /* Init streams */ inputSpeech->pBuf = (Ipp16s *) malloc(sizeof(Ipp16s)*pcmBufLen); inputSpeech->len = pcmBufLen; outputSpeech->pBuf = (Ipp16s *) malloc(sizeof(Ipp16s)*pcmBufLen); outputSpeech->len = pcmBufLen; bitstream->pBuf = (Ipp8u *) malloc(sizeof(Ipp8u)*bitstreamBufLen); if ((inputSpeech->pBuf==NULL)||(outputSpeech->pBuf==NULL)||(bitstream->pBuf==NULL)) { printf("initCodec() - memory allocation failure.\n"); exit(0); } else return(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -