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

📄 speexdec.c

📁 语音滤波源代码
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "speex_preprocess.h"
int main() {

	FILE 	*fin = NULL,  *fout = NULL;
	SpeexPreprocessState *preprocess = NULL;
	int denoise_enabled=0, agc_enabled=0;
	int lookahead = 0;

	char 	first_bytes[44];
	int		frame_size = 160;
	int		rate = 8000;
	short	output[160];
	short	input[160];
	char	wav_header[44] = {			/* header bytes of wave file */
		0x52, 0x49, 0x46, 0x46, 0xf8, 0x3f, 0x03, 0x00, 0x57, 0x41, 0x56, 0x45, 
		0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 
		0x40, 0x1f, 0x00, 0x00, 0x80, 0x3e, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 
		0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x04, 0x00 };

	fin = fopen("inbuf.wav", "rb");
	if (!fin) {		
		printf ( "can not read input.wav\n"	);
		exit(1);	
	}
	fread(first_bytes, 1, 44, fin ) ;			//读取wav 	头文件

	
	fout = fopen("output.wav", "wb");
	if (!fout) {         
		printf ( "can not write  output.wav\n");   
		exit(1);	
	}		
	fwrite(wav_header, 1, 44, fout);


	preprocess = speex_preprocess_state_init(frame_size, rate);
    speex_preprocess_ctl(preprocess, SPEEX_PREPROCESS_SET_DENOISE, &denoise_enabled);
    speex_preprocess_ctl(preprocess, SPEEX_PREPROCESS_SET_AGC, &agc_enabled);

    
	while (1)
	{
		fread(input, sizeof(short), frame_size, fin);
		if (feof(fin))
         		break;
		 if (preprocess)
			speex_preprocess(preprocess, input, NULL);

	    fwrite(input, sizeof(short), frame_size, fout);	    		 
	}

    fclose(fout);     
	fclose(fin);	exit(1);
	return 0;}

⌨️ 快捷键说明

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