#include <graphics.h>
#include <dos.h>
#include <bios.h>
#include<conio.h>
#include<stdlib.h>
#include <stdio.h>
#include<math.h>
#define larrow 0x4b00
#define rarrow 0x4d00
#define KEY_ESC 0mouse_x_bf11b
#define pi 3.1415926
#define linex 550.00
#define liney 400.00
#define DOUBLE_PI 6.283185307179586476925286766559
#define PI 3.1415926
#define to_s( x ) #x
/*function*/
void menu1() ;
void menu2();
void x_menu();
void if_inmenu(int t,int *i,int x,int y,int x1,int y1,void (*fun)(int i),int buttons);
void input_bds();
void input_wav();
int msinit();
int msread();
void newposition(),mscursor();
void drawline(double s,int i,int w);
void show_num() ;
void buildxy();
/***********************************************************/
/*value*/
/*menu*/
int menu_flag1=1;
int menu_flag2=0;
int menu_flag3=0;
int graphdriver,graphmode;
/* mouse*/
union REGS regs;
int mouse_x=-100,mouse_y=-100;
int mouse_x_bf=-100,mouse_y_bf=-100;
int buttons;
int oy=450,ox=50;
/*length per 方格*/
double per_x_l=40;
double per_y_l=40;
double per_num_l=40.00 ;
/* value per lenth setting*/
double per_y_v=0.05;
double per_x_v=2.5;
double ox_begin=0;
double oy_begin=0;
char *yuanben[30];
char *jiazao[30];
char *chuzao[30];
int sound_type=1;
double datad[3000];
double datac[3000];
/**********************************************************************************************/
/* wav文件结构 */
typedef struct WaveData
{
unsigned long sample_lenth;
unsigned short rate;
unsigned short channels;
unsigned char time_constant;
char bit_res;
char *name_wav;
char *sample;
} WAV;
/* wav头信息结构 */
typedef struct HeaderType
{
long riff; /*RIFF类资源文件头部*/
unsigned long file_len; /*文件长度*/
char wave[4]; /*"WAVE"标志*/
char fmt [4]; /*"fmt"标志*/
char NI1 [4]; /*过渡字节*/
unsigned short format_type;/*格式类别(10H为PCM形式的声音数据)*/
unsigned short Channels; /*Channels 1 = 单声道; 2 = 立体声*/
long frequency; /*采样频率*/
long trans_speed;/*音频数据传送速率*/
char NI2 [2]; /*过渡字节*/
short sample_bits;/*样本的数据位数(8/16)*/
char data[4]; /*数据标记符"data"*/
unsigned long wav_len; /*语音数据的长度*/
char NI3 [4]; /*过渡字节*/
} HEAD_WAV;
HEAD_WAV Wav_file_head;
WAV *Wav_file;
#include <graphics.h>
#include <dos.h>
#include <bios.h>
#include<conio.h>
#include<stdlib.h>
#include <stdio.h>
#include<math.h>
#define pi 3.1415926
int graphdriver,graphmode;
void draw(double du,double fuzhi)
{int i,j;
double s=0;double temp;
char *e;
/*
for(i=0;i<3000;i++){
datac[i]=fuzhi*sin(du*(i)*pi/180);
}
setlinestyle(0,0,1);setcolor(4);
moveto(50,100);
for(i=0;i<3000;i++)lineto(i+50,datac[i]+100);
for(i=0;i<3000;i++){
if(rand()%2==0)
datac[i]=fuzhi*sin(du*(i)*pi/180)+rand()%20;
else
datac[i]=fuzhi*sin(du*(i)*pi/180)-rand()%20;
}
for(i=0;i<3000;i++){
datad[i]=0;
for(j=0;j<3000-i;j++){
datad[i]+=datac[j]*datac[i+j];
}
datad[i]=datad[i]/(j+1);
}
moveto(50,250);
setlinestyle(0,0,1);setcolor(14);
for(i=0;i<3000;i++)lineto(i+50,datac[i]+250);
setlinestyle(0,0,1);setcolor(4);
moveto(50,450);
for(i=0;i<3000;i++){lineto(i+50,datad[i]/10+400);}
setcolor(3);line(50,450,650,450);line(50,450,50,3);
for(i=0,temp=360.00/du;i<3000;i+=20)
{
s=2*i/temp*pi;
gcvt(s,6,e);
outtextxy(i+50,455,e);
}
outtextxy(0,50,"the old signal");
outtextxy(0,200,"the signal add noise");
outtextxy(0,350,"the xcorr signal");
*/
}
void returntomenu(){
menu_flag1=1;
menu_flag2=0;
menu_flag3=0;
cleardevice();x_menu();};
/*
void trantowav(int type,long double w,char * name[30],long frequency,long t_f,long length)
{
FILE *fp_out;int i=0;double data;char c;
Wav_file_head.riff=0x46464952;
Wav_file_head.file_len=length+50;
strcpy(Wav_file_head.wave,"wave");
strcpy(Wav_file_head.fmt,"fmt");
Wav_file_head.format_type=0x10;
Wav_file_head.Channels=1;
Wav_file_head.frequency=frequency;
Wav_file_head.trans_speed=t_f;
Wav_file_head.sample_bits=8;
strcpy(Wav_file_head.data,"data");
Wav_file_head.wav_len =length;
fp_out=fopen(name,"ab");
fwrite(&Wav_file_head,sizeof(HEAD_WAV),1,fp_out);
printf(name);system("pause");
if(type==1){
while(i++<length){
datac[i]=20*sin(w*i);
c=datac[i]+0;
fwrite(&c,sizeof(char),1,fp_out);
}
}
}*/
void show_system(){exit(0);}
WAV *Load_wav(char *name_wav)
{
FILE *fp,*ff;
int i,j;
FILE *fp_out;
char c;int d; double hehe;
strcpy(yuanben,name_wav);
/* 打开声音文件 */
if ((fp = fopen(name_wav, "rb")) == NULL){printf("1can’t open wav file!"); system("pause");return NULL;}
/* 开辟空间 */
if ((Wav_file = (WAV *)malloc(sizeof(WAV))) == NULL) { printf("2have’t mem!"); system("pause"); fclose(fp); return NULL; }
/* 读取文件头信息 */
fread(&Wav_file_head, sizeof(HEAD_WAV), 1, fp);
/* 检查RIFF头 0x46464952 其实就是字符串 "RIFF"
这样好处理一些,毕竟比较数字比比较字符串要省事的多 */
if (Wav_file_head.riff != 0x46464952) { printf("3isn’t wav file!"); system("pause"); fclose(fp); return NULL; }
/* 获取文件名 */
Wav_file->name_wav = name_wav;
Wav_file->rate = Wav_file_head.frequency; /* 采样频率 */
Wav_file->channels = Wav_file_head.Channels; /* 声道 */
per_x_v=1.0000/Wav_file_head.frequency;
/* 计算真实采样率 */
Wav_file->time_constant = 256 - (1000000L / (Wav_file->rate * Wav_file->channels));
/*
printf("%f,--fre",Wav_file_head.frequency);
printf("%f,--chan",Wav_file_head.Channels);
printf("%f,--riff\n",Wav_file_head.riff);
printf(",name:"); printf(Wav_file_head.name_wav);
printf(",wave:");printf(Wav_file_head.wave);
printf(",NI1:");printf(Wav_file_head.NI1);
printf(",romttype:");printf("%d",Wav_file_head.format_type);
printf(",trspeed:"); printf("%f",Wav_file_head.trans_speed);
printf(",NI2:"); printf(Wav_file_head.NI2);
printf(",data:");printf(Wav_file_head.data);
printf(",len:"); printf("%f",Wav_file_head.wav_len); system("pause"); */
/* 获取声音数据长度 */
Wav_file->sample_lenth = Wav_file_head.file_len - 50;
for(i=0;i<3000;i++)datac[i]=0;
for(i=0;i<3000;i++)datad[i]=0;
for(i=0;i<3000;i++)
{fread(&c,sizeof(char),1,fp);
datac[i]=c+0.00;}
fclose(fp);/*
fp=fopen("wewe.txt","ab");
for(i=0;i<3000;i++)
fprintf(fp,"%f",datac[i]);
fclose(fp);
for(i=0;i<3000;i++){if(!feof(fp))datac[i]=fgetc(fp);else break;&datac[i],sizeof(double),1,fp);}*/
/* out put the noise sound********************/
printf("please input the noise sound name:\n") ;
scanf("%s",name_wav);
strcpy(jiazao,name_wav);
ff=fopen(name_wav,"ab") ;
fwrite(&Wav_file_head,sizeof(HEAD_WAV),1,ff);
for(i=0;i<3000;i++)
{
datac[i]=datac[i]+rand()%50;
d=datac[i]+0;
c=(char)(d);
fwrite(&c,sizeof(char),1,ff);
}
fclose(ff);
/* out put the xocrr sound********************/
for(i=0;i<3000;i++){
for(j=0;j<3000-i;j++){
datad[i]+=datac[j]*datac[i+j];
}
datad[i]=datad[i]/(j+1.000);
}
printf("please input the xcorr sound:\n") ;
scanf("%s",name_wav);
strcpy(chuzao,name_wav);
ff=fopen(name_wav,"ab") ;
fwrite(&Wav_file_head,sizeof(HEAD_WAV),1,ff);
hehe=0;
for(i=0;i<3000;i++){if(hehe<datad[i])hehe=datad[i];} hehe=hehe/255.000;
for(i=0;i<3000;i++)
{
d=datad[i]/hehe+0;
c=(char)(d);
fwrite(&c,sizeof(char),1,ff);
}
fclose(ff);
return Wav_file;
}
void Destroy_wav(WAV *Wav_file)
{
if (Wav_file)
{
free(Wav_file->sample);
Wav_file->sample = NULL;
free(Wav_file);
Wav_file = NULL;
}
}
void wav(char
ZXG.rar_自相关滤波
版权申诉
151 浏览量
2022-09-19
20:43:49
上传
评论
收藏 5KB RAR 举报
林当时
- 粉丝: 100
- 资源: 1万+
最新资源
- Yolov8改进---注意力机制:Polarized Self-Attention,效果秒杀CBAM、SE.html
- 人才网站设计-asp.net+sql-(系统源码)
- asp.net+sql人才网站设计-含系统源码
- C#应用的用户配置窗体方案
- python实现绘制爱心图形的代码
- JAVAWEB项目-校园订餐系统项目源码.zip
- flink-1.19.0-bin-scala-2.12.tgz flink-1.16.3-bin-scala-2.12.tgz
- javaWeb项目-物资管理系统项目源码.zip
- javaweb项目-物流配货项目源码.zip
- 使用C++基于颜色纹理特征的人脸活体检测实现-附项目源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈