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

📄 lbccodec.c

📁 语音编解码算法G.723.1的C语言算法原代码
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "typedef.h"
#include "basop.h"
#include "cst_lbc.h"
#include "tab_lbc.h"
#include "lbccodec.h"
#include "coder.h"
#include "decod.h"
#include "exc_lbc.h"
#include "util_lbc.h"

/* Global variables */
enum  Wmode    WrkMode = Both ;
enum  Crate    WrkRate = Rate53 ;

int   PackedFrameSize[2] = {   24,   20} ;

Flag    UseHp = True ;
Flag    UsePf = True ;
Flag    UseVx = False ;
Flag    UsePr = True ;
Word32  count_clip = 0L;

Word16 speech_out[Frame];

char    Line_rx[24];
char    Line_tx[24];
int main()
{

    char Line[24] ;
	Word16 input[240];
	int count;
	FILE *m_pInput;
	FILE *m_pCodec;
	FILE *m_pOutput;
      
	//Init coder and the decoder
    Init_Coder( ) ;
    Init_Decod( ) ;
///////////////////////////////////////////////////////
//  以下代码是从文件里读取数据
//  以便你进行测试,应该没问题的
    /* Process all the input file */
	//////////////////////////////////
	// 读输入文件
	if((m_pInput = fopen("inls1.wav", "rb")) == NULL) 
	{
		printf("%s - Error opening file  %s !!\n");
		exit(0);
	}
	//////////////////////////////////
	// 打开编码文件
	if((m_pCodec = fopen("codec.bit", "wb")) == NULL) 
	{
		printf("%s - Error opening file  %s !!\n");
		exit(0);
	}
	printf("开始语音压缩!\r\n");
	count =0;
	while( fread(&input[0], sizeof(Word16), Frame, m_pInput) == Frame)
	{
		printf("Frame =%d\r", count++);

		Coder( input, Line ) ;
		//将编码数据写到文件里
		fwrite(Line, sizeof(char), 24, m_pCodec);
	}
	fclose(m_pCodec);
	fclose(m_pInput);
	printf("\r\n");
	printf("开始语音合成!\r\n");
	//////////////////////////////////
	// 打开编码文件
	if((m_pCodec = fopen("codec.bit", "rb")) == NULL) 
	{
		printf("%s - Error opening file  %s !!\n");
		exit(0);
	}
	//////////////////////////////////
	// 打开合成文件
	if((m_pOutput = fopen("output.wav", "wb")) == NULL) 
	{
		printf("%s - Error opening file  %s !!\n");
		exit(0);
	}

	count = 0;
	while( fread(Line, sizeof(char), 24, m_pCodec) == 24)
	{
		printf("Frame =%d\r", count++);

		Decod( speech_out, Line, (Word16) 0 ) ;

		//将解码数据写到文件里
		fwrite(speech_out, sizeof(Word16), Frame, m_pOutput);
	}
	printf("\r\n");
	
    fclose(m_pCodec);
	fclose(m_pOutput);
//  以上代码是从文件里读取数据
///////////////////////////////////////////////////////


///////////////////////////////////////////////////////
//	下面的代码为实际应用中的
	/*for(;;)	//这里必须是死循环,表示编解码始终进行,从而为一个全双工声码器
    {     
		/////////////////////////////////////////////
		// 这里speech_in为声码器的输入接口,
		// speech_out为声码器的输出接口,怎样接口根据你
		// 的实际情况定。一般来说,speech_in为AD,speech_out
		// 为DA,Line_tx为发送到信道的数据,Line_rx为来自信道的数据
        Coder( speech_in, Line_tx ) ;
            
        for(i=0;i<12;i++)
        {
            txdata[i]=(Line_tx[2*i+1])&0xff;
		    txdata[i]=txdata[i]<<8;
		    txdata[i]=((Line_tx[2*i])&0xff)|txdata[i];
        }

  
        for(i=0;i<12;i++)
        {
            Line_rx[2*i+1]=(rxdata[i]>>8)&0xff;
		    Line_rx[2*i]=(rxdata[i])&0xff;
        }
            
        Decod( speech_out, Line_rx, (Word16) 0 ) ;
    }*/
//  这段代码为实际应用的情况
///////////////////////////////////////////////////////
    return 0 ;
}

⌨️ 快捷键说明

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