⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 g792codec.c

📁 G.729 video compresion program example file includes : G729codec.c va_g729.h va_g729.lib
💻 C
字号:
#include "stdio.h"
#include "va_g729.h"
#include "time.h"

void userinterface();
void encoder();
void decoder();

void main()
{
	printf("*********************************************\n");
	printf("*  ITU G.729 CS-ACELP 8.0kbps speech coder  *\n");
	printf("*   Desinged by YZU CSE s932212 Josh Kao    *\n");
	printf("*                27.11.2006                 *\n");
	printf("*********************************************\n");
	userinterface();
	
}

void userinterface()
{
	int select;

	printf("\nchoose the selection to run ");
	printf("\n1) Encode the source voice file");
	printf("\n2) Decode the encoded file");
	printf("\n3) Exit this program\n : ");
	scanf("%d",&select);
	switch(select)
	{
	case 1:
		encoder();
		break;
	case 2:
		decoder();
		break;
	default:
		printf("\nThis program is closed\n");
		break;
	}
}

void encoder()
{
	char			infile_name[100], outfile_name[100];

	FILE			*fp_in, *fp_out;

	int				nb_frame, select = 0;
	clock_t			start, finish;
	double			duration;

	short			speech[L_FRAME];
	unsigned char	serial[L_FRAME_COMPRESSED];

	/* Open the original file and encoded file */

	printf("infile name : ");
	scanf("%s",&infile_name);
	printf("outfile name : ");
	scanf("%s",&outfile_name);

	if( (fp_in = fopen(infile_name, "rb")) == NULL)
	{
		printf("\nError for opening %s!\n", infile_name);
		return 0;
	}
	if( (fp_out = fopen(outfile_name, "wb")) == NULL)
	{
		printf("\nError for opening %s!\n", outfile_name);
		return 0;
	}

	/* Encoded the original file */

	va_g729a_init_encoder();

	nb_frame = 0;

	start = clock();

	while (fread(speech, sizeof(short), L_FRAME, fp_in) == L_FRAME) 
	{

		printf("Encode frame %d\r", ++nb_frame);

		/* call encoder */

		va_g729a_encoder(speech, serial);

		/* Output serial stream to disk */

		fwrite(serial, sizeof(char), L_FRAME_COMPRESSED, fp_out);

	}

   
   finish = clock();
   
   duration = (double)(finish - start) / CLOCKS_PER_SEC;
   printf( "\n%2.1f seconds\n", duration );


   fclose(fp_out);
   fclose(fp_in);

   printf("\nDo you want to decode the encoded row file ?\n");
   printf("1) Yes\n");
   printf("2) No, exit this program : ");
   scanf("%d",&select);
   switch(select)
   {
   case 1:
	   decoder();
	   break;
   default:
	   printf("Program closed!\n");
	   break;
   }

}
void decoder()
{
	char			infile_name[100], outfile_name[100];

	FILE			*fp_in, *fp_out;

	int				nb_frame;
	int				bfi;
	clock_t			start, finish;
	double			duration;

	short			synth[L_FRAME];
	unsigned char	serial[L_FRAME_COMPRESSED];

	/* Open the original file and encoded file */

	printf("infile name : ");
	scanf("%s",&infile_name);
	printf("outfile name : ");
	scanf("%s",&outfile_name);

	if( (fp_in = fopen(infile_name, "rb")) == NULL)
	{
		printf("\nError for opening %s!\n", infile_name);
		return 0;
	}
	if( (fp_out = fopen(outfile_name, "wb")) == NULL)
	{
		printf("\nError for opening %s!\n", outfile_name);
		return 0;
	}

	/* Decode the encoded file */

	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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -