int codec_g729a_decode(void *context, const void *input, int inputSizeBytes, void *output, int *outputSizeBytes) { struct g729a_context *ctx = (struct g729a_context*)context; const unsigned char *bitstream = (const unsigned char*)input; short *speech = (short*)output; int decodedBytes = 0; if (!ctx) return 0; if ((inputSizeBytes % L_G729A_FRAME_COMPRESSED) != 0) return 0; if (!output) return (inputSizeBytes / L_G729A_FRAME_COMPRESSED) * L_G729A_FRAME * sizeof(short); while ((inputSizeBytes >= L_G729A_FRAME_COMPRESSED) && ((*outputSizeBytes - decodedBytes) >= L_G729A_FRAME * sizeof(short))) { if (EasyG729A_decoder(ctx->handle, (unsigned char*)bitstream, ctx->speach_buffer)) { memcpy(speech, ctx->speach_buffer, L_G729A_FRAME * sizeof(short)); speech += L_G729A_FRAME; decodedBytes += L_G729A_FRAME * sizeof(short); } bitstream += L_G729A_FRAME_COMPRESSED; inputSizeBytes -= L_G729A_FRAME_COMPRESSED; } return decodedBytes; }
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_G729A_FRAME_COMPRESSED]; short synth[L_G729A_FRAME]; CODER_HANDLE hDecoder; printf("\n************** Imtelephone.com **************"); printf("\n"); printf("\n------------- G729A 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 * *-----------------------------------------------------------------------*/ hDecoder = EasyG729A_init_decoder( ); nb_frame = 0; start = clock(); while (fread(serial, sizeof(char), L_G729A_FRAME_COMPRESSED, fp_in) == L_G729A_FRAME_COMPRESSED) { printf("Decode frame %d\r", ++nb_frame); /*--------------------------------------------------------------* * Call the decoder. * *--------------------------------------------------------------*/ EasyG729A_decoder(hDecoder, serial, synth ); /*--------------------------------------------------------------* * Output synthesis to disk * *--------------------------------------------------------------*/ fwrite(synth, sizeof(short), L_G729A_FRAME, fp_out); } EasyG729A_release_decoder( hDecoder ); 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() */