www.pudn.com > va_g729.zip > va_g729a_encoder.c


/*--------------------------------------------------------------------------------* 
 *                                                                                * 
 * Copyright © 1995-2001 VoiceAge Corporation. All Rights Reserved.               * 
 *                                                                                * 
 * All warranties implied or expressed, including but not limited to implied      * 
 * warranties of merchantability, or fitness for purpose, are excluded.           * 
 *                                                                                * 
 * ACELP and VoiceAge are a registered trademark and trademark of VoiceAge        * 
 * Corporation in Canada and / or other countries. Any unauthorized use is        * 
 * strictly prohibited.                                                           * 
 *                                                                                * 
 *--------------------------------------------------------------------------------* 
 *                                                                                * 
 * VoiceAge Corporation                                                           * 
 * www.voiceage.com                                                               * 
 *                                                                                * 
 *--------------------------------------------------------------------------------* 
 *                         va_g729a_encoder.c                                     * 
 *                         ~~~~~~~~~~~~~~~~~~                                     * 
 * Example of the ITU G.729 CS-ACELP 8.0kbps speech coder                         * 
 *                                                                                * 
 *--------------------------------------------------------------------------------*/ 
 
#include "stdio.h" 
#include "va_g729a.h" 
 
void main(int argc, char *argv[]) 
{ 
	int nb_frame; 
 
	FILE* fp_in; 
	FILE* fp_out; 
 
	short			speech[L_FRAME]; 
	unsigned char	serial[L_FRAME_COMPRESSED]; 
 
	/*-----------------------------------------------------------------------* 
	 * Open all files.                                                       * 
	 *-----------------------------------------------------------------------*/ 
	printf("\n-----------------      VoiceAge Corporation      ----------------"); 
	printf("\n                         www.voiceage.com                        "); 
	printf("\n"); 
	printf("\n-------------      G729a floating-point Encoder      ------------"); 
	printf("\n"); 
 
	if (argc != 3) 
	{ 
		printf("\nUsage: %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; 
	} 
  
	/*-----------------------------------------------------------------------* 
	 * Encode                                                                * 
	 *-----------------------------------------------------------------------*/ 
 
	va_g729a_init_encoder(); 
 
	nb_frame = 0; 
 
	while (fread(speech, sizeof(short), L_FRAME, fp_in) == L_FRAME)  
	{ 
 
		printf("Encode frame %d\r", ++nb_frame); 
 
		/*--------------------------------------------------------------* 
		 * Call the encoder.                                            * 
		 *--------------------------------------------------------------*/ 
 
		va_g729a_encoder(speech, serial); 
 
		/*--------------------------------------------------------------* 
		 * Output serial stream to disk                                 * 
		 *--------------------------------------------------------------*/ 
 
		fwrite(serial, sizeof(char), L_FRAME_COMPRESSED, fp_out); 
 
	} 
    
	fclose(fp_out); 
	fclose(fp_in); 
 
} /* end of main() */