diff --git a/dsp.c b/dsp.c index 0b93f2e..189b9ab 100644 --- a/dsp.c +++ b/dsp.c @@ -1,10 +1,10 @@ #include "vocal.h" -int init_dsp() { +int init_dsp( char *device ) { int dsp, arg; - if ((dsp=open("/dev/dsp", O_RDONLY)) < 0) { - perror("open of /dev/dsp failed"); + if ((dsp=open( (device == NULL ? "/dev/dsp" : device), O_RDONLY)) < 0) { + perror("open of sound device failed"); return -1; } @@ -16,7 +16,7 @@ int init_dsp() { } if (arg != AFMT_U8) { - perror ("/dev/dsp doesn't support AFMT_U8"); + perror ("sound device doesn't support AFMT_U8"); return -1; } diff --git a/main.c b/main.c index ce0eca7..115ff58 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,8 @@ void helpandusage() { fprintf (stderr, "---=== BlackLight's vocal recognition v.0.1b ===---\n" "author @ blacklight@autistici.org\n\n" - "Usage: vocal [-a] [-c ] [-h]\n\n" + "Usage: vocal [-d ] [-a] [-c ] [-h]\n\n" + "\t-d \tUse a different device instead the default one (/dev/dsp)\n" "\t-a\t\tAppend a new vocal sample with an associated command\n" "\t-c \tUse a different rc file (default: ~/.vocalrc)\n" "\t-h\t\tPrint this help and exit\n" @@ -17,7 +18,7 @@ int main (int argc, char **argv) { int i, j, dsp, fd, ch, size, recognized; int TOTSIZE = BUF_SIZE*SAMPLE_SIZE; - char *line, *tmp, *cmd = NULL, *fname = NULL; + char *line, *tmp, *cmd = NULL, *fname = NULL, device = NULL; char **match = NULL; double deviance; @@ -33,24 +34,23 @@ int main (int argc, char **argv) { u8 *buf; mode m = capture; - while ((ch=getopt(argc, argv, "ahc:"))>0) { - if (ch == 'a') - m = append; - else if (ch == 'c') - fname = strdup(optarg); - else if (ch == 'h') { - helpandusage(); - return 0; - } else { - helpandusage(); - return 1; + while ((ch=getopt(argc, argv, "ahc:d:"))>0) { + switch(ch){ + case 'd' : device = strdup(optarg); break; + case 'a' : m = append; break; + case 'c' : fname = strdup(optarg); break; + case 'h' : helpandusage(); + return 0; break; + default : + helpandusage(); + return 1; } } - buf = (u8*) malloc(TOTSIZE); + buf = (u8*) malloc(TOTSIZE); neutral = (double*) malloc(TOTSIZE*sizeof(double)); - trans = (double*) malloc(TOTSIZE*sizeof(double)); - memset (buf, 0x80, TOTSIZE); + trans = (double*) malloc(TOTSIZE*sizeof(double)); + memset(buf, 0x80, TOTSIZE); if (!fname) { fname = (char*) malloc(0x100); @@ -65,7 +65,7 @@ int main (int argc, char **argv) { read (fd, neutral, TOTSIZE*sizeof(double)); close(fd); - if ((dsp = init_dsp())<0) + if ((dsp = init_dsp( device ))<0) return 1; memset (buf, 0x0, TOTSIZE);