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 <file> \t record to <file>\n");
printf("-p <file> \t play from <file>\n");
printf("-s \t\t stereo\n");
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;
}
char play_file[MAX_C_FILE];
dsp_set set;
unsigned char *buf;
+ unsigned char print_info=0;
+ unsigned char info[8];
+ int info_int;
+ int tmp;
/* defaults */
strcpy(device,"");
case 'h':
usage();
return 1;
+ case 'i':
+ print_info=1;
+ break;
case 'r':
mode=RECORD;
strcpy(record_file,argv[++i]);
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;
}
}
+ if(print_info) {
+ if(mode&PLAY) {
+ printf("file info:\n");
+ lseek(pfile_fd,4,SEEK_SET);
+ read(pfile_fd,&info_int,4);
+ printf("file size: %d\n",info_int);
+ 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&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&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);
+ /* return to start */
+ lseek(pfile_fd,0,SEEK_SET);
+ }
+ }
+
/* set dsp and get capabilities */
if(get_dsp_cap(audio_fd,&set,1)==-1) {
printf("unable to get capabilities :(\n");
perror("malloc");
return -1;
}
-
+
if(mode&PLAY) {
printf("playing file %s ...\n",play_file);
rw=1;
}
}
+ 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;
}