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

📄 decode.c

📁 以上是标准的G.722源代码
💻 C
字号:
/*
	Note: G722.1 decoder for PC
		For packed bitstream only
*/

/*************************************************************************** Include files                                                           ***************************************************************************/#include "defs.h"#include "g722codec.h"
#include "g722interface.h"

void G722_GetDecoderMemSize(G722_CODEC_PARA * pPara)
{
	int size = 0;
	size += ALIGN_SIZE(sizeof(G722_DEC_HANDLE));
	size += 256;
	pPara->bufferSize = size;
}
void * G722_CreateDecoder(G722_CODEC_PARA * pPara)
{

	G722_CODEC_PARA tmpPara;
	G722_DEC_HANDLE * afm;
	int nFeature;

	if(pPara == 0)
		return 0;

	G722_GetDecoderMemSize(&tmpPara);
	if(tmpPara.bufferSize > pPara->bufferSize || pPara->bufferSize == 0)
	{
		DebugPrint("buffer alloced is samll!\n");
		return 0;
	}
	if( (pPara->bitrate!=16000) && (pPara->bitrate!=24000) && (pPara->bitrate!=32000) ){
		DebugPrint("Error: bitrate must be 16000 or 24000 or 32000"); 
		return 0;
	}
	memset(pPara->buffer, 0, pPara->bufferSize);
	afm = (G722_DEC_HANDLE*)pPara->buffer;
	afm->buffer = pPara->buffer;
	afm->buffer_size = pPara->bufferSize;
	afm->buffer_offset = ALIGN_SIZE(sizeof(G722_ENC_HANDLE));

	afm->number_of_bits_per_frame = pPara->bitrate/50;
	afm->number_of_16bit_words_per_frame = afm->number_of_bits_per_frame/16;
	if(afm->buffer_offset > afm->buffer_size)
	{
		//分配内存太小
		DebugPrint("buffer alloced is samll!\n");
		return 0;
	}

	afm->rmlt_coefs_to_samples = rmlt_coefs_to_samples_C;
	
	afm->randobj.seed0 = 1;
	afm->randobj.seed1 = 1;
	afm->randobj.seed2 = 1;
	afm->randobj.seed3 = 1;
	return afm;
}
int G722_Decode(void *handle, char * pSrcStream, int streamSize, short * pDstFrame, int *pDstSize)
{
	Word32 i, iFrame;
    Word16 frame_error_flag = 0;
    Word16 decoder_mlt_coefs[DCT_LENGTH];
    Word16 mag_shift;
    Bit_Obj bitobj;
	Word16 *src, *dst;
	G722_DEC_HANDLE * afm = (G722_DEC_HANDLE*) handle;
	int frames = streamSize/(afm->number_of_16bit_words_per_frame * BYTES_PER_SAMPLE);
  
	src = (Word16 *)pSrcStream;	// input bitstream data
	dst = (Word16 *)pDstFrame;	// ouput audio data

	for(iFrame=0; iFrame<frames; iFrame++){		//G722解码一次为20ms

        /* reinit the current word to point to the start of the buffer */
		bitobj.code_word_ptr = src;
		bitobj.current_word = *src;
		bitobj.code_bit_count = 0;
		bitobj.number_of_bits_left = afm->number_of_bits_per_frame;

		decoder(&bitobj,
				&(afm->randobj),
				decoder_mlt_coefs,
				&mag_shift,
				&(afm->old_mag_shift),
				afm->old_decoder_mlt_coefs,
				frame_error_flag);

		/* convert the decoder_mlt_coefs to samples */
		afm->rmlt_coefs_to_samples(decoder_mlt_coefs, afm->old_samples, dst, mag_shift);

        /* For ITU testing, off the 2 lsbs. */
        for (i=0; i<FRAMESIZE; i++)
            dst[i] &= 0xfffc;

		/* For next 20ms frame */
		src += afm->number_of_16bit_words_per_frame;
		dst += FRAMESIZE;
	}

    return 1;

}

⌨️ 快捷键说明

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