static int codec_decoder(const struct PluginCodec_Definition * codec, void * context, const void * from, unsigned * fromLen, void * to, unsigned * toLen, unsigned int * flag) { if (*fromLen < BYTES_PER_FRAME || *toLen < SAMPLES_PER_FRAME*2) return 0; #ifdef _WIN32_WCE { UWord8 buffer[BYTES_PER_FRAME+1]; buffer[0] = 2; memcpy(&buffer[1], from, BYTES_PER_FRAME); if (D_IF_g729ab_decode(context, buffer, (Word16 *)to, 0) != 0) return 0; } #else va_g729a_decoder((unsigned char *)from, (short *)to, 0); #endif *fromLen = BYTES_PER_FRAME; *toLen = SAMPLES_PER_FRAME*2; return 1; }
HRESULT CG729Codec::DecodeMedia(IMediaSample *pSource, IMediaSample *pDest) const { // Copy the sample data BYTE *pSourceBuffer, *pDestBuffer; long lSourceSize = pSource->GetActualDataLength(); pSource->GetPointer( &pSourceBuffer ); pDest->GetPointer( &pDestBuffer ); long ldddSize = pDest->GetActualDataLength(); for ( BYTE *pSrc = pSourceBuffer, *pDst = pDestBuffer; pSrc - pSourceBuffer < lSourceSize; pSrc += L_FRAME_COMPRESSED * sizeof(BYTE) ) { va_g729a_decoder( pSrc, (SHORT *)pDst, 0 ); pDst += L_FRAME * sizeof(WORD); } // Copy the actual data length long nDestLength = long( pDst - pDestBuffer ); pDest->SetActualDataLength( nDestLength ); return S_OK; }
static int codec_decoder(const struct PluginCodec_Definition * codec, void * context, const void * from, unsigned * fromLen, void * to, unsigned * toLen, unsigned int * flag) { //if (!decoderInUse) // return 0; if (*fromLen < L_FRAME_COMPRESSED || *toLen < SAMPLES_PER_FRAME*2) return 0; va_g729a_decoder((unsigned char *)from, (short *)to, 0); *fromLen = L_FRAME_COMPRESSED; *toLen = SAMPLES_PER_FRAME * 2; return 1; }
//---------------------------------------------------------------------------------------------------- bool EEWaveCoder::WaveDecode(char *_dataIn, int _inLen, char *_dataOut, int *_outLen) { InitializeWaveCoder(); if (!_dataIn || _inLen != 60 || !_dataOut) return false; va_g729a_decoder((BYTE*)_dataIn, (short*)(_dataOut), 0); va_g729a_decoder((BYTE*)_dataIn + 10, (short*)(_dataOut + 160), 0); va_g729a_decoder((BYTE*)_dataIn + 20, (short*)(_dataOut + 320), 0); va_g729a_decoder((BYTE*)_dataIn + 30, (short*)(_dataOut + 480), 0); va_g729a_decoder((BYTE*)_dataIn + 40, (short*)(_dataOut + 640), 0); va_g729a_decoder((BYTE*)_dataIn + 50, (short*)(_dataOut + 800), 0); if (_outLen) *_outLen = 960; return true; }
BOOL CAudioCode::DecodeAudioData(char *pin,int len,char* pout,int* lenr) { BOOL bRet=FALSE; if(!pin||len!=SIZE_AUDIO_PACKED||!pout) goto RET; va_g729a_decoder((BYTE*)pin,(short*)(pout),0); va_g729a_decoder((BYTE*)pin+10,(short*)(pout+160),0); va_g729a_decoder((BYTE*)pin+20,(short*)(pout+320),0); va_g729a_decoder((BYTE*)pin+30,(short*)(pout+480),0); va_g729a_decoder((BYTE*)pin+40,(short*)(pout+640),0); va_g729a_decoder((BYTE*)pin+50,(short*)(pout+800),0); if(lenr) *lenr=SIZE_AUDIO_FRAME; bRet=TRUE; RET: return bRet; }
void main(int argc, char *argv[]) { int nb_frame; clock_t start, finish; double duration; FILE* fp_in; FILE* fp_out; unsigned char serial[L_FRAME_COMPRESSED]; short synth[L_FRAME]; int bfi; printf("\n************** VoiceAge Corporation **************"); printf("\n"); printf("\n------------- G729 floating-point Decoder ------------"); printf("\n"); /*-----------------------------------------------------------------------* * Open all files. * *-----------------------------------------------------------------------*/ if (argc != 3) { printf("Usage: %s infile outfile\n", argv[0]); return; } if ( (fp_in = fopen(argv[1], "rb")) == NULL) { printf("\nError opening input file %s!", argv[1]); return; } if ( (fp_out = fopen(argv[2], "wb")) == NULL) { printf("\nError opening output file %s!", argv[2]); return; } /*-----------------------------------------------------------------------* * Decode * *-----------------------------------------------------------------------*/ va_g729a_init_decoder(); nb_frame = 0; start = clock(); while (fread(serial, sizeof(char), L_FRAME_COMPRESSED, fp_in) == L_FRAME_COMPRESSED) { printf("Decode frame %d\r", ++nb_frame); /*--------------------------------------------------------------* * Bad frame * * * * bfi = 0 to indicate that we have a correct frame * * bfi = 1 to indicate that we lost the current frame * *--------------------------------------------------------------*/ bfi = 0; /*--------------------------------------------------------------* * Call the decoder. * *--------------------------------------------------------------*/ va_g729a_decoder(serial, synth, bfi); /*--------------------------------------------------------------* * Output synthesis to disk * *--------------------------------------------------------------*/ fwrite(synth, sizeof(short), L_FRAME, fp_out); } finish = clock(); duration = (double)(finish - start) / CLOCKS_PER_SEC; printf( "\n%2.1f seconds\n", duration ); fclose(fp_out); fclose(fp_in); } /* end of main() */