Added the possibility to choose a different sound device rather than the default /dev/dsp

This commit is contained in:
evilsocket 2009-05-24 16:15:38 +02:00
parent 0f41eec84a
commit 4a52ddf55c
2 changed files with 21 additions and 21 deletions

8
dsp.c
View file

@ -1,10 +1,10 @@
#include "vocal.h" #include "vocal.h"
int init_dsp() { int init_dsp( char *device ) {
int dsp, arg; int dsp, arg;
if ((dsp=open("/dev/dsp", O_RDONLY)) < 0) { if ((dsp=open( (device == NULL ? "/dev/dsp" : device), O_RDONLY)) < 0) {
perror("open of /dev/dsp failed"); perror("open of sound device failed");
return -1; return -1;
} }
@ -16,7 +16,7 @@ int init_dsp() {
} }
if (arg != AFMT_U8) { if (arg != AFMT_U8) {
perror ("/dev/dsp doesn't support AFMT_U8"); perror ("sound device doesn't support AFMT_U8");
return -1; return -1;
} }

26
main.c
View file

@ -6,7 +6,8 @@ void helpandusage() {
fprintf (stderr, fprintf (stderr,
"---=== BlackLight's vocal recognition v.0.1b ===---\n" "---=== BlackLight's vocal recognition v.0.1b ===---\n"
"author @ blacklight@autistici.org\n\n" "author @ blacklight@autistici.org\n\n"
"Usage: vocal [-a] [-c <file>] [-h]\n\n" "Usage: vocal [-d <device>] [-a] [-c <file>] [-h]\n\n"
"\t-d <device>\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-a\t\tAppend a new vocal sample with an associated command\n"
"\t-c <file>\tUse a different rc file (default: ~/.vocalrc)\n" "\t-c <file>\tUse a different rc file (default: ~/.vocalrc)\n"
"\t-h\t\tPrint this help and exit\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 i, j, dsp, fd, ch, size, recognized;
int TOTSIZE = BUF_SIZE*SAMPLE_SIZE; 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; char **match = NULL;
double deviance; double deviance;
@ -33,15 +34,14 @@ int main (int argc, char **argv) {
u8 *buf; u8 *buf;
mode m = capture; mode m = capture;
while ((ch=getopt(argc, argv, "ahc:"))>0) { while ((ch=getopt(argc, argv, "ahc:d:"))>0) {
if (ch == 'a') switch(ch){
m = append; case 'd' : device = strdup(optarg); break;
else if (ch == 'c') case 'a' : m = append; break;
fname = strdup(optarg); case 'c' : fname = strdup(optarg); break;
else if (ch == 'h') { case 'h' : helpandusage();
helpandusage(); return 0; break;
return 0; default :
} else {
helpandusage(); helpandusage();
return 1; return 1;
} }
@ -50,7 +50,7 @@ int main (int argc, char **argv) {
buf = (u8*) malloc(TOTSIZE); buf = (u8*) malloc(TOTSIZE);
neutral = (double*) malloc(TOTSIZE*sizeof(double)); neutral = (double*) malloc(TOTSIZE*sizeof(double));
trans = (double*) malloc(TOTSIZE*sizeof(double)); trans = (double*) malloc(TOTSIZE*sizeof(double));
memset (buf, 0x80, TOTSIZE); memset(buf, 0x80, TOTSIZE);
if (!fname) { if (!fname) {
fname = (char*) malloc(0x100); fname = (char*) malloc(0x100);
@ -65,7 +65,7 @@ int main (int argc, char **argv) {
read (fd, neutral, TOTSIZE*sizeof(double)); read (fd, neutral, TOTSIZE*sizeof(double));
close(fd); close(fd);
if ((dsp = init_dsp())<0) if ((dsp = init_dsp( device ))<0)
return 1; return 1;
memset (buf, 0x0, TOTSIZE); memset (buf, 0x0, TOTSIZE);