]> hackdaworld.org Git - sound-tools/hdrec.git/commitdiff
-
authorhackbard <hackbard>
Thu, 21 Aug 2003 03:11:30 +0000 (03:11 +0000)
committerhackbard <hackbard>
Thu, 21 Aug 2003 03:11:30 +0000 (03:11 +0000)
hdrec.c
hdrec.h

diff --git a/hdrec.c b/hdrec.c
index 77b222ba9d5644dff5c45a59a56200e17191c6a5..c6945f5d5f3d62fb7787ab0d396be1d73169c19c 100644 (file)
--- a/hdrec.c
+++ b/hdrec.c
@@ -25,6 +25,7 @@ int usage(void) {
        printf("usage:\n\n");
        printf("-h \t\t print this help\n");
        printf("-i \t\t use/print file info\n");
+       printf("-R \t\t play reversed :)\n");
        printf("-d <device> \t sound device (eg: /dev/dsp)\n");
        printf("-r <file> \t record to <file>\n");
        printf("-p <file> \t play from <file>\n");
@@ -55,6 +56,7 @@ int main(int argc,char **argv) {
        unsigned char info[8];
        int info_int;
        int tmp;
+       char is_wav=0;
        fd_set read_fds,write_fds;
        struct timeval fds_tv;
        char c;
@@ -83,6 +85,9 @@ int main(int argc,char **argv) {
                                        mode|=PLAY;
                                        strcpy(play_file,argv[++i]);
                                        break;
+                               case 'R':
+                                       mode|=REVERSED;
+                                       break;
                                case 's':
                                        set.channel=STEREO;
                                        break;
@@ -197,10 +202,32 @@ int main(int argc,char **argv) {
 
        if((mode&PLAY) && (!(mode&RECORD))) {
                printf("playing file %s ...\n",play_file);
+               if(mode&REVERSED) printf("but we do it reversed!\n");
                rw=1;
-               while(rw) {
-                       rw=read(pfile_fd,buf,set.bufsize);
-                       write(audio_fd,buf,set.bufsize);
+               if(!(mode&REVERSED)) {
+                       while(rw) {
+                               rw=read(pfile_fd,buf,set.bufsize);
+                               write(audio_fd,buf,set.bufsize);
+                       }
+               } else {
+                       i=0;
+                       read(pfile_fd,info,4);
+                       if(!strncmp(info,"RIFF",4)) {
+                               is_wav=1;
+                               printf("\nassuming wav file according to header ...\n");
+                               i=44;
+                       }
+                       lseek(pfile_fd,0,SEEK_SET);
+                       tmp=lseek(pfile_fd,0,SEEK_END);
+                       // if(set.format==AFMT_U8) i=set.channel;
+                       // if(set.format==AFMT_S16_LE) i=set.channel*2;
+                       for(j=0;j<(tmp-i);j++) {
+                               for(k=0;k<set.bufsize;k++) {
+                                       lseek(pfile_fd,tmp-(j+1)*set.bufsize+k,SEEK_SET);
+                                       read(pfile_fd,buf+k,1);
+                               }
+                               write(audio_fd,buf,set.bufsize);
+                       }
                }
        }
 
@@ -223,30 +250,26 @@ int main(int argc,char **argv) {
                /* write_fds */
                FD_SET(sfile_fd,&write_fds);
                FD_SET(audio_fd,&write_fds);
-               fds_tv.tv_sec=0;
-               fds_tv.tv_usec=1000;
                while(c!='q') {
+                       fds_tv.tv_sec=0;
+                       fds_tv.tv_usec=1000;
                        k=select(sfile_fd+1,&read_fds,&write_fds,NULL,&fds_tv);
                        if(k==0) printf("itz zZzero :p\n");
                        if(k) {
+                               printf("returned after %ld usecs\n",1000-fds_tv.tv_usec);
                                if(FD_ISSET(0,&read_fds)) {
-                                       puts("reading from stdin");
                                        read(0,&c,1);
                                }
                                if(FD_ISSET(pfile_fd,&read_fds)) {
-                                       puts("read from sound file");
                                        read(pfile_fd,buf2,set.bufsize);
                                }
                                if(FD_ISSET(audio_fd,&read_fds)) {
-                                       puts("reading from audio device");
                                        read(audio_fd,buf,set.bufsize);
                                }
                                if(FD_ISSET(sfile_fd,&write_fds)) {
-                                       puts("writing to file");
                                        write(sfile_fd,buf,set.bufsize);
                                }
                                if(FD_ISSET(audio_fd,&write_fds)) {
-                                       puts("writing to audio device");
                                        write(audio_fd,buf2,set.bufsize);
                                }
                        }
diff --git a/hdrec.h b/hdrec.h
index 90e9c339b4cfbd1863d6414fac2dd24d32a8df50..61bd6e5a1dede7e64a20f91071a3c553719dfe79 100644 (file)
--- a/hdrec.h
+++ b/hdrec.h
@@ -6,6 +6,7 @@
 #define PLAY 1
 #define RECORD 2
 #define CONVERT 4
+#define REVERSED 8
 
 #define MAX_C_FILE 128
 #define MAX_C_DEVICE 128