]> hackdaworld.org Git - sound-tools/hdrec.git/commitdiff
removed binary - added convert function
authorhackbard <hackbard>
Mon, 7 Jul 2003 23:20:09 +0000 (23:20 +0000)
committerhackbard <hackbard>
Mon, 7 Jul 2003 23:20:09 +0000 (23:20 +0000)
hdrec [deleted file]
hdrec.c
hdrec.h

diff --git a/hdrec b/hdrec
deleted file mode 100755 (executable)
index 9bfc05f..0000000
Binary files a/hdrec and /dev/null differ
diff --git a/hdrec.c b/hdrec.c
index 58cb67074b5c6276f3718e5a5095c452ca3e5f89..42d86a755ef6299acb6faf4945f90bc40ccc4219 100644 (file)
--- a/hdrec.c
+++ b/hdrec.c
@@ -29,6 +29,7 @@ int usage(void) {
        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;
 }
@@ -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<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;
 }      
diff --git a/hdrec.h b/hdrec.h
index e3cb02f88f1316e9bc0564c0e2f59de9121f6dcf..90e9c339b4cfbd1863d6414fac2dd24d32a8df50 100644 (file)
--- a/hdrec.h
+++ b/hdrec.h
@@ -5,6 +5,7 @@
 
 #define PLAY 1
 #define RECORD 2
+#define CONVERT 4
 
 #define MAX_C_FILE 128
 #define MAX_C_DEVICE 128