From: hackbard Date: Mon, 7 Jul 2003 23:20:09 +0000 (+0000) Subject: removed binary - added convert function X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=9894394f33f4aee3cafbaf91c076cdd13f4fc1c6;p=sound-tools%2Fhdrec.git removed binary - added convert function --- diff --git a/hdrec b/hdrec deleted file mode 100755 index 9bfc05f..0000000 Binary files a/hdrec and /dev/null differ diff --git a/hdrec.c b/hdrec.c index 58cb670..42d86a7 100644 --- a/hdrec.c +++ b/hdrec.c @@ -29,6 +29,7 @@ int usage(void) { printf("-m \t\t mono\n"); printf("-f \t 1=8bit - 2=16bit (le)\n"); printf("-F \t frequency\n"); + printf("-c \t converts raw to wav (specify f/m,s/F)\n"); return 1; } @@ -49,6 +50,7 @@ int main(int argc,char **argv) { unsigned char print_info=0; unsigned char info[8]; int info_int; + int tmp; /* defaults */ strcpy(device,""); @@ -91,6 +93,11 @@ int main(int argc,char **argv) { 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; @@ -113,13 +120,13 @@ int main(int argc,char **argv) { } /* 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; @@ -135,16 +142,20 @@ int main(int argc,char **argv) { 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); @@ -188,5 +199,45 @@ int main(int argc,char **argv) { } } + 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