#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/select.h>
+#include <sys/time.h>
#include <sys/soundcard.h>
#include <fcntl.h>
#include <unistd.h>
printf("usage:\n\n");
printf("-h \t\t print this help\n");
printf("-i \t\t use/print file info\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");
printf("-s \t\t stereo\n");
char play_file[MAX_C_FILE];
dsp_set set;
unsigned char *buf;
+ unsigned char *buf2=NULL;
unsigned char print_info=0;
unsigned char info[8];
int info_int;
int tmp;
+ fd_set read_fds,write_fds;
+ struct timeval fds_tv;
+ char c;
/* defaults */
strcpy(device,"");
print_info=1;
break;
case 'r':
- mode=RECORD;
+ mode|=RECORD;
strcpy(record_file,argv[++i]);
break;
case 'p':
- mode=PLAY;
+ mode|=PLAY;
strcpy(play_file,argv[++i]);
break;
case 's':
perror("malloc");
return -1;
}
+ if((mode&RECORD) && (mode&PLAY)) {
+ if((buf2=malloc(set.bufsize*sizeof(unsigned char)))==NULL) {
+ printf("allocating 2nd memory failed :(\n");
+ perror("malloc");
+ return -1;
+ }
+ }
- if(mode&PLAY) {
+ if((mode&PLAY) && (!(mode&RECORD))) {
printf("playing file %s ...\n",play_file);
rw=1;
while(rw) {
}
}
- if(mode&RECORD) {
+ if((mode&RECORD) && (!(mode&PLAY))) {
printf("recording to file %s ...\n",record_file);
rw=1;
while(rw) {
}
}
+ if((mode&RECORD) && (mode&PLAY)) {
+ FD_ZERO(&read_fds);
+ FD_ZERO(&write_fds);
+ /* read_fds */
+ FD_SET(0,&read_fds);
+ FD_SET(pfile_fd,&read_fds);
+ FD_SET(audio_fd,&read_fds);
+ /* 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') {
+ k=select(sfile_fd+1,&read_fds,&write_fds,NULL,&fds_tv);
+ if(k==0) printf("itz zZzero :p\n");
+ if(k) {
+ 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);
+ }
+ }
+ }
+ }
+
if(mode&CONVERT) {
if((tmp=lseek(pfile_fd,0,SEEK_END))==-1) {
printf("cannot determine filesize :(\n");