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

📄 decoder.c

📁 AMR-NB的解码程序,纯C, VC建立工程即可使用.标准测试序列通过测试,与编码配合使用.
💻 C
字号:
/*
 * ===================================================================
 *  TS 26.104
 *  R99   V3.3.0 2001-09
 *  REL-4 V4.2.0 2001-09
 *  3GPP AMR Floating-point Speech Codec
 * ===================================================================
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include "interf_dec.h"
#include "typedef.h"
#include "time.h"


void Copyright(void){
fprintf (stderr,
"===================================================================\n"
" TS 26.104                                                         \n"
" R99   V3.3.0 2001-09                                              \n"
" REL-4 V4.2.0 2001-09                                              \n"
" 3GPP AMR Floating-point Speech Decoder                            \n"
"===================================================================\n"
);
}
/*************************************************************************************
 * Function:         main
 *
 * description:
 *    Speech decoder main program
 *
 *    Usage: decoder bitstream_file synthesis_file
 *
 *    Format for ETSI bitstream file:
 *       1 word (2-byte) for the TX frame type
 *       244 words (2-byte) containing 244 bits.
 *          Bit 0 = 0x0000 and Bit 1 = 0x0001
 *       1 word (2-byte) for the mode indication
 *       4 words for future use, currently written as zero
 *
 *    Format for 3GPP bitstream file:
 *       Holds mode information and bits packed to octets.
 *       Size is from 1 byte to 31 bytes.
 *
 *    Format for synthesis_file:
 *       Speech is written to a 16 bit 8kHz file.
 *
 *    ETSI bitstream file format is defined using ETSI as preprocessor
 *    definition
 * Returns:
 *    0
 *************************************************************************************/
int main (int argc, char * argv[])
{

	FILE * file_speech, *file_analysis;

	short synth[160];
	int frames = 0;
	int * destate;
	int read_size;
	unsigned long t1= 0,t2= 0;

#ifndef ETSI
	unsigned char analysis[31];
	enum Mode dec_mode;
#else
	short analysis[250];
#endif

	/* Process command line options */
	if (argc == 3)
	{

		file_speech = fopen(argv[2], "wb");
		if (file_speech == NULL)
		{
			fprintf ( stderr, "%s%s%s\n","Use: ",argv[0], " input.file output.file " );
			return 1;
		}

		file_analysis = fopen(argv[1], "rb");
		if (file_analysis == NULL)
		{
			fprintf ( stderr, "%s%s%s\n","Use: ",argv[0], " input.file output.file " );
			fclose(file_speech);
			return 1;
		}

	}
	else 
	{
		fprintf ( stderr, "%s%s%s\n","Use: ",argv[0], " input.file output.file " );
		return 1;
	}
	/* init decoder */
	destate = Decoder_Interface_init();

#ifndef ETSI

	/* find mode, read file */
	while (fread(analysis, sizeof (unsigned char), 1, file_analysis ) > 0)
	{
		dec_mode = analysis[0] & 0x000F;
		switch (dec_mode)
		{
			case 0:
			read_size = 12;
			break;
			case 1:
			read_size = 13;
			break;
			case 2:
			read_size = 15;
			break;
			case 3:
			read_size = 17;
			break;
			case 4:
			read_size = 18;
			break;
			case 5:
			read_size = 20;
			break;
			case 6:
			read_size = 25;
			break;
			case 7:
			read_size = 30;
			break;
			case 8:
			read_size = 5;
			break;
			case 15:
			read_size = 0;
			default:
			read_size = 0;
			break;
		};
		
		fread(&analysis[1], sizeof (char), read_size, file_analysis );
	}
#else

	read_size = 250;
	/* read file */
	while (fread(analysis, sizeof (short), read_size, file_analysis ) > 0)
	{
#endif

		frames ++;

		/* call decoder */
		t1 = clock();
		Decoder_Interface_Decode(destate, analysis, synth, 0);
		t2 += clock()-t1;


		fwrite( synth, sizeof (short), 160, file_speech );
	}

	Decoder_Interface_exit(destate);

	fclose(file_speech);

	fclose(file_analysis);
	fprintf ( stderr, "\n%s%i%s\n","Decoded ", frames, " frames.");
	printf("time cost is : %f \n", (float)t2/(frames*1000));

	return 0;
}

⌨️ 快捷键说明

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