#include #include #include #include #include #include #include #include #include #include #include #include #define ui32 int #define TRUE 1 #define FALSE 0 #include "tejeezdtmf.h" #define iobase 0x378 int getfirstzero(char *joku, int max){ int i; for(i=0; i=KLEN) index = 0; for(i=0; i8) if(fromfile==0 ? read(sd, &i, 2)==-1 : fread(&i, 2, 1, sdf)==0){ printf("luku evo\n"); exit(0); } goertzel(i); ka = hetken_keskiarvo(i); //printf("%i\t", ka); switch(tila) { case TWAITNUMBER: if(kiva_uus){ kiva_uus=0; if(kiva_mika=='A' || kiva_mika=='B'){ for(j=0; j<100; j++) numerobufferi[j] = 0; tila=TGETNUMBER; printf("switched to getnumber\n"); count = 0; } else{ if(ka > 170){ for(j=0; j<100; j++) numerobufferi[j] = 0; sprintf(numerobufferi, "unknown"); tila = TSTARTRECORD; printf("unknown call detected, recording.\n"); } printf("ignored kiva_mika %c\n", kiva_mika); } } break; case TGETNUMBER: if(kiva_uus){ kiva_uus=0; if(kiva_mika=='C') tila=TGOTNUMBER; else{ //lisätään numero bufferiin, ja jos se tulee täyteen, aloitetaan koko //homma alusta, koska tällöin joku menee selvästi pieleen if( append(numerobufferi, 100, kiva_mika) ) tila = TWAITNUMBER; printf("got %c\n", kiva_mika); count++; if(count/8000>2){ printf("waited too long, switching to twaitnumber.\n"); tila = TWAITNUMBER; } } } break; case TGOTNUMBER: printf("got number %s\n", numerobufferi); //tila=TSTARTMUSIC; tila=TSTARTRECORD; break; case TSTARTRECORD: for(j=0; ; j++){ sprintf(fname, "%s%s-%i", recdir, numerobufferi, j); filep = fopen(fname, "r"); if(filep==NULL) break; fclose(filep); } printf("trying to record to %s\n", fname); filep = fopen(fname, "a"); if(filep==NULL){ printf("lol fopen anto NULLin, otetaan alusta\n"); tila = TWAITNUMBER; } else{ tila = TRECORD; hiljaisuuscount=0; aanicount=0; count=0; printf("recording\n"); } if(tila!=TRECORD) break; case TRECORD: fwrite(&i, 2, 1, filep); count++; if(ka>170){ hiljaisuuscount = 0; aanicount++; } else{ aanicount = 0; hiljaisuuscount++; if(hiljaisuuscount%8000==0) printf("%is inactivity\n", hiljaisuuscount/8000); } if(hiljaisuuscount/8000 > 10) tila = TSTOPRECORD; if(tila!=TSTOPRECORD) break; case TSTOPRECORD: fclose(filep); tila = TWAITNUMBER; printf("stopped recording after %is of silence.\n", hiljaisuuscount/8000); break; case TSTARTMUSIC: musac=0; outb(1,iobase); close(sd); sd = open("/dev/dsp", O_WRONLY); if(sd<0){ printf("ei saatu dsp:tä auki\n"); tila=TSTOPMUSIC; break; } laitajutut(sd); filep = fopen("nightsky2.raw", "r"); if(filep==NULL){ printf("ei saatu musaa auki\n"); tila=TSTOPMUSIC; break; } tila = TMUSIC; break; case TMUSIC: if(fread(&i, 2, 1, filep)==0){ tila=TSTOPMUSIC; //musa loppu break; } write(sd, &i, 2); musac++; if(musac/8000>30) tila = TSTOPMUSIC; break; case TSTOPMUSIC: fclose(filep); close(sd); goto start; } } fromfile==0 ? close(sd) : fclose(sdf); return 0; }