红联Linux门户
Linux帮助

Linux下噪声生成程序

发布时间:2007-04-09 09:26:18来源:红联作者:Linuxperson
搞定了linux下面白噪声的生成程序,发出来共享,也许有用。下一步解决驱动的问题。

#include
#include
#include
#include
#include
#include
#include
#include
#define BUFSIZE 88200 //100ms wav is generated every time
#define count 100 //10s data is produced


char magic[]={0x52,0x49,0x46,0x46};//"wave"
char middle[]={0x57,0x41,0x56,0x45,0x66,0x6D,0x74,0x20,
0x10,0x00,0x00,0x00,0x01,0x00,0x02,0x00,
0x44,0xAC,0x00,0x00,0x10,0xB1,0x02,0x00,
0x04,0x00,0x10,0x00,0x64,0x61,0x74,0x61};//other frame data

short rxbuf[BUFSIZE];

void write_wavheader(int fd,int data_len)
{
int tmp;
write(fd,magic,4);
tmp=data_len+36;
write(fd,(char*)&tmp,4);
write(fd,middle,32);
tmp=data_len;
write(fd,(char*)&tmp,4);
}




int main(int argc, char **argv)
{

int out_fd;
int i, j, realsize;
int output;
char *filename;

filename = "/tmp/out.wav";
if((out_fd=open(filename,O_RDWR|O_CREAT|O_TRUNC),0666)<=0)
{
printf(" Can't open output file! errno=%d\n",errno);
return;
}
memset(rxbuf, 0, BUFSIZE*sizeof(short));
write_wavheader(out_fd,count*BUFSIZE);
for(i=0;i {
for(j=0;j {
rxbuf[j]=(short)(32760.0*rand()/(RAND_MAX+1.0));
if(rxbuf[j]%2==0)
rxbuf[j]*=-1;
}

if ((realsize=write(out_fd, rxbuf, BUFSIZE*sizeof(short))) != BUFSIZE*sizeof(short))
printf("ERROR:write(%s) return count: 0x%d, errno:%d\n",filename, realsize, errno);
}

printf("\nRecord finished.\n");
return 0;
}
文章评论

共有 57 条评论

  1. 60.244.51.* 于 2007-07-17 16:55:26发表:

    http://3ad5f1e4e502eceb2c1df6fcd83c97bd-t.xkktxb.org 3ad5f1e4e502eceb2c1df6fcd83c97bd http://3ad5f1e4e502eceb2c1df6fcd83c97bd-b1.xkktxb.org 3ad5f1e4e502eceb2c1df6fcd83c97bd http://3ad5f1e4e502eceb2c1df6fcd83c97bd-b3.xkktxb.org 8d1f2bfe3cbc5359328d95464cab8b7c