OsStatus MpeIPPG729::initEncode(void) { int lCallResult; ippStaticInit(); strcpy((char*)codec->codecName, "IPP_G729A"); codec->lIsVad = 1; // Load codec by name from command line lCallResult = LoadUSCCodecByName(codec, NULL); if (lCallResult < 0) { return OS_FAILED; } // Get USC codec params lCallResult = USCCodecAllocInfo(&codec->uscParams, NULL); if (lCallResult < 0) { return OS_FAILED; } lCallResult = USCCodecGetInfo(&codec->uscParams, NULL); if (lCallResult < 0) { return OS_FAILED; } // Get its supported format details lCallResult = GetUSCCodecParamsByFormat(codec, BY_NAME, NULL); if (lCallResult < 0) { return OS_FAILED; } // Set params for encode USC_PCMType streamType; streamType.bitPerSample = getInfo()->getNumBitsPerSample(); streamType.nChannels = getInfo()->getNumChannels(); streamType.sample_frequency = getInfo()->getSamplingRate(); lCallResult = SetUSCEncoderPCMType(&codec->uscParams, LINEAR_PCM, &streamType, NULL); if (lCallResult < 0) { return OS_FAILED; } // instead of SetUSCEncoderParams(...) codec->uscParams.pInfo->params.direction = USC_ENCODE; codec->uscParams.pInfo->params.law = 0; codec->uscParams.pInfo->params.modes.vad = ms_bEnableVAD ? 1 : 0; // Alloc memory for the codec lCallResult = USCCodecAlloc(&codec->uscParams, NULL); if (lCallResult < 0) { return OS_FAILED; } // Init decoder lCallResult = USCEncoderInit(&codec->uscParams, NULL, NULL); if (lCallResult < 0) { return OS_FAILED; } // Allocate memory for the output buffer. Size of output buffer is equal // to the size of 1 frame inputBuffer = (Ipp8s *)ippsMalloc_8s(codec->uscParams.pInfo->params.framesize); outputBuffer = (Ipp8u *)ippsMalloc_8u(codec->uscParams.pInfo->maxbitsize + 10); return OS_SUCCESS; }
int main(int argc, char *argv[]) { char *buf_in; char *bitstream_buf; char *p; char *f; long file_size; int i; if(argc != 3) { fprintf(stderr, "Usage: my_enc audio.raw audio.g729\n"); exit(-1); } fprintf(stderr, "Converting %s to %s\n", argv[1], argv[2]); USC_Fxns *USC_CODEC_Fxns; USC_CodecInfo pInfo; USC_Handle encoder; USC_PCMStream in; USC_Bitstream out; USC_MemBank* pBanks; int nbanks = 0; int maxbitsize; int inFrameSize; int outFrameSize = 0; USC_CODEC_Fxns = USC_GetCodecByName_xx2 (); USC_CODEC_Fxns->std.GetInfo((USC_Handle)NULL, &pInfo); /* codec info */ ((USC_Option*)pInfo.params)->modes.truncate = 1; ((USC_Option*)pInfo.params)->direction = 0; ((USC_Option*)pInfo.params)->modes.vad = 0; FILE *f_in = fopen(argv[1], "r"); FILE *f_out = fopen(argv[2], "w"); fseek(f_in, 0, SEEK_END); file_size = ftell(f_in); fseek(f_in, 0, SEEK_SET); buf_in = ippsMalloc_8s(file_size); fread(buf_in, file_size, 1, f_in); p = buf_in; f = buf_in + file_size; USC_CODEC_Fxns->std.NumAlloc(pInfo.params, &nbanks); pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*nbanks); USC_CODEC_Fxns->std.MemAlloc(pInfo.params, pBanks); for(i=0; i<nbanks;i++) { if(!(pBanks[i].pMem = ippsMalloc_8u(pBanks->nbytes))) { printf("\nLow memory: %d bytes not allocated\n",pBanks->nbytes); return -1; } } inFrameSize = getInFrameSize(); outFrameSize = getOutFrameSize_xx3(); bitstream_buf = ippsMalloc_8s(pInfo.maxbitsize); in.bitrate = pInfo.params->modes.bitrate; maxbitsize = pInfo.maxbitsize; USC_CODEC_Fxns->std.Init(pInfo.params, pBanks, &encoder); ippCoreSetFlushToZero( 1, NULL ); in.pcmType.bitPerSample = pInfo.pcmType->bitPerSample; in.pcmType.sample_frequency = pInfo.pcmType->sample_frequency; out.nbytes = maxbitsize; out.pBuffer = bitstream_buf; USC_CODEC_Fxns->std.Reinit(&((USC_Option*)pInfo.params)->modes, encoder); while(p < f) { in.pBuffer = p; USC_CODEC_Fxns->std.Encode (encoder, &in, &out); fwrite(out.pBuffer, 10, 1, f_out); p += inFrameSize; } fclose(f_out); fclose(f_in); return 0; }