/*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "vocal.h" typedef enum { capture, append } mode; void helpandusage() { fprintf (stderr, "---=== BlackLight's && evilsocket's vocal recognition v.0.1b ===---\n" "author @ blacklight@autistici.org\n" "author @ evilsocket@gmail.com\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" ); } 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, *device = NULL; char **match = NULL; double deviance; double *neutral, *trans; double value, sum = 0.0; double PIconst = (D_M_PI/TOTSIZE); double coeff = 1.0 / TOTSIZE; double t, v; FILE *fp; time_t t1, t2; u8 *buf; mode m = capture; 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; } } printf( "DEVICE : %s\n", device ); buf = (u8*) malloc(TOTSIZE); neutral = (double*) malloc(TOTSIZE*sizeof(double)); trans = (double*) malloc(TOTSIZE*sizeof(double)); memset(buf, 0x80, TOTSIZE); if (!fname) { fname = (char*) malloc(0x100); snprintf (fname, 0x100, "%s/.vocalrc", getenv("HOME")); } if ((fd=open("neutral.ft", O_RDONLY, 0644))<0) { perror ("could not find file neutral.ft"); return 1; } read (fd, neutral, TOTSIZE*sizeof(double)); close(fd); if ((dsp = init_dsp( device ))<0) return 1; memset (buf, 0x0, TOTSIZE); printf ("now capturing, say something...\n"); if (read(dsp, buf, TOTSIZE) != TOTSIZE) { perror("read the wrong number of bytes"); return 1; } close(dsp); printf ("capture done, computing DCT...\n" ); t1 = time((unsigned) NULL); for (i=0; i= 0) ? v : -v; trans[i] = log(v); } free(neutral); free(buf); t2 = time((unsigned) NULL); printf ("DCT computing: done in %u seconds\n", (unsigned int) (t2-t1)); for (i=0; i