/* * special dedikass Pink Lady */ #include #include #include #include #include #include #include /* --------------------------------------------------------------- */ #define T_BUFF_WAVES (8192*8) #define NB_WAVES 12 #define T_FNAME 1000 /* --------------------------------------------------------------- */ typedef struct { char *name; long size; /* number of samples */ int volume; } A_Wave; char waves_names[NB_WAVES][T_FNAME+1]; int16_t *waves_data[NB_WAVES]; /* --------------------------------------------------------------- */ /* WARNING : dont reuse this func when you got an error : fd leak happen */ static int lireconfig(char *fname) { FILE *fp; char ligne[T_FNAME+1], *cptr; int foo, lg, numid; if (NULL==(fp=fopen(fname, "r"))) { perror(fname); return -1; } /* cleanup the datasore */ for (foo=0; foo=NB_WAVES) { fprintf(stderr, "numid %d out of trolley\n", numid); return -5; } /* after that, we grab the holly filename */ cptr = strtok(ligne, " \t"); cptr = strtok(NULL, " \t"); /* headshoot ! */ if (NULL==cptr) { fprintf(stderr, "err strtok\n"); return -3; } #if DEBUG_LEVEL fprintf(stderr, "fname = %s\n", cptr); #endif /* insert all the big dataz in memory linear databaze */ strncpy(waves_names[numid], cptr, T_FNAME); } fclose(fp); return 0; } /* --------------------------------------------------------------- */ static void list_waves(void) { int foo; for (foo=0; foo %ld\n", total); #else putc('\n', stderr); #endif /* do some cleanup */ sf_close(sndf); ao_close(device); ao_shutdown(); return 0; } /* --------------------------------------------------------------- */ int grande_boucle(char *joydevice) { struct js_event evn; int foo, fd; int nombre; fd = open(joydevice, O_RDONLY | O_NONBLOCK); if (fd < 0) { perror(joydevice); exit(1); } nombre = 0; for (;;) { foo = read(fd, &evn, sizeof(evn)); if (0 == foo) { fprintf(stderr, "nothing...\n"); } else if (sizeof(evn) == foo) { /* skip calibration datas */ if (evn.type > 127) continue; printf("%12d %3u %3u %6d\n", evn.time, evn.type, evn.number, evn.value); /* got an event, blast the sound */ } else { // perror("joy read"); sleep(1); } if (evn.number==8 && evn.value==1) /* DEBUG */ { list_waves(); continue; } if (evn.number==9 && evn.value==1) /* DEBUG */ { fprintf(stderr, "Quit command\n"); break; } if (evn.value == 1 && /* button down */ evn.number >= 0 && evn.number < NB_WAVES) { /* action */ playfile(waves_names[evn.number]); printf("%d waves played\n", nombre++); sleep(1); } } return 0; } /* --------------------------------------------------------------- */ int main(int argc, char *argv[]) { int foo; fprintf(stderr, " ************** pling !\n"); foo = lireconfig("madphoenix.conf"); if (foo < 0) exit(1); grande_boucle("/dev/input/js0"); return 0; } /* --------------------------------------------------------------- */