printf("-m \t\t mono\n");
printf("-f <format> \t 1=8bit - 2=16bit (le)\n");
printf("-F <hz> \t frequency\n");
+ printf("-c <src> <dst> \t converts raw to wav (specify f/m,s/F)\n");
return 1;
}
unsigned char print_info=0;
unsigned char info[8];
int info_int;
+ int tmp;
/* defaults */
strcpy(device,"");
case 'd':
strncpy(device,argv[++i],MAX_C_DEVICE-1);
break;
+ case 'c':
+ mode=CONVERT;
+ strcpy(play_file,argv[++i]);
+ strcpy(record_file,argv[++i]);
+ break;
default:
usage();
return -1;
}
/* file fd's */
- if(mode&PLAY) {
+ if((mode&PLAY) || (mode&CONVERT)) {
if((pfile_fd=open_file(play_file,O_RDONLY))==-1) {
printf("unable to open file %s for reading\n",play_file);
return -1;
}
}
- if(mode&RECORD) {
+ if((mode&RECORD) || (mode&CONVERT)) {
if((sfile_fd=open_file(record_file,O_CREAT|O_WRONLY))==-1) {
printf("unable to open file %s for writing\n",record_file);
return -1;
lseek(pfile_fd,8,SEEK_CUR);
read(pfile_fd,&info_int,4);
printf("fmtsize: %d\n",info_int);
+ if(info_int==16) set.format=AFMT_S16_LE;
+ if(info_int==8) set.format=AFMT_U8;
read(pfile_fd,&info_int,4);
- printf("format tag: %d\n",(info_int>>16)&1<<16);
- printf("channels: %d\n",info_int&1<<16);
+ printf("format tag: %d\n",info_int&0xffff);
+ printf("channels: %d\n",(info_int>>16)&0xffff);
+ set.channel=(info_int>>16)&0xffff;
read(pfile_fd,&info_int,4);
printf("samples/sec: %d\n",info_int);
+ set.freq=info_int;
read(pfile_fd,&info_int,4);
printf("bytes/sec: %d\n",info_int);
read(pfile_fd,&info_int,4);
- printf("block allign: %d\n",(info_int>>16)&1<<16);
- printf("bits/sample: %d\n",info_int&1<<16);
+ printf("block allign: %d\n",info_int&0xffff);
+ printf("bits/sample: %d\n",(info_int>>16)&0xffff);
lseek(pfile_fd,4,SEEK_CUR);
read(pfile_fd,&info_int,4);
printf("datasize: %d\n\n",info_int);
}
}
+ if(mode&CONVERT) {
+ if((tmp=lseek(pfile_fd,0,SEEK_END))==-1) {
+ printf("cannot determine filesize :(\n");
+ perror("lseek");
+ return -1;
+ }
+ lseek(pfile_fd,0,SEEK_SET);
+ strcpy(info,"RIFF");
+ write(sfile_fd,info,4);
+ info_int=tmp+36;
+ write(sfile_fd,&info_int,4);
+ strcpy(info,"WAVEfmt ");
+ write(sfile_fd,info,8);
+ if(set.format==AFMT_S16_LE) info_int=16;
+ if(set.format==AFMT_U8) info_int=8;
+ write(sfile_fd,&info_int,4);
+ info_int=set.channel<<16;
+ info_int|=1;
+ write(sfile_fd,&info_int,4);
+ info_int=set.freq;
+ write(sfile_fd,&info_int,4);
+ info_int=set.freq*set.channel;
+ if(set.format==AFMT_S16_LE) info_int*=2;
+ write(sfile_fd,&info_int,4);
+ info_int=(set.channel*8)<<16;
+ info_int|=set.channel;
+ write(sfile_fd,&info_int,4);
+ strcpy(info,"data");
+ write(sfile_fd,info,4);
+ info_int=tmp;
+ write(sfile_fd,&info_int,4);
+ /* write data now ... */
+ for(j=0;j<tmp/set.bufsize;j++) {
+ i=read(pfile_fd,buf,set.bufsize);
+ k=write(sfile_fd,buf,set.bufsize);
+ printf("read %d, wrote %d\n",i,k);
+ }
+ printf("\ndone ...\n");
+ }
+
return 1;
}