int replay_sample(FILE *fp, long f_size) { long f_left; SndBufPtr pointer; f_left = f_size; init_sound_system(); load_dsample(sound, fp, &f_left, sizeof(sound)/2); printf("\rPlayback sound\n"); buffoper(0x3); load_dsample(sound+sizeof(sound)/2, fp, &f_left, sizeof(sound)/2); buffptr(&pointer); while(pointer.play < sound+sizeof(sound)/2) buffptr(&pointer); while (f_left > 0) { buffptr(&pointer); while(pointer.play < sound+sizeof(sound)/2) buffptr(&pointer); printf("\r%lds ", (f_size-f_left)/(4*options.frequency)); fflush(stdout); load_dsample(sound, fp, &f_left, sizeof(sound)/2); buffptr(&pointer); while(pointer.play > sound+sizeof(sound)/2) buffptr(&pointer); printf("\r%lds ", (f_size-f_left)/(4*options.frequency)); fflush(stdout); load_dsample(sound+sizeof(sound)/2, fp, &f_left, sizeof(sound)/2); if (!f_left) { fseek(fp, 0, 0); f_left = filelength(fp); } } buffptr(&pointer); while(pointer.play < sound+sizeof(sound)/2 && !Bconstat(2)) buffptr(&pointer); load_dsample(sound, fp, &f_left, sizeof(sound)/2); buffoper(0x0); exit_sound_system(); return(0); }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND **fmod_sounds; FMOD_RESULT result; xmlDocPtr doc; xmlNodePtr node; int ret; ret = pthread_cond_init(&events.events_available, NULL); if (ret < 0) { fprintf(stderr, "Unable to initialize the events cond object\n"); } ret = pthread_mutex_init(&events.lock, NULL); if (ret < 0) { fprintf(stderr, "Unable to initialize the events lock object\n"); } init_sound_system(&system); init_xml_lib(); open_config_xml(&doc); node = doc->children; while (node) { if (xmlStrEqual(node->name, AUDIOTRIGGERS_ELT)) { break; } node = node->next; } if (!node) { fprintf(stderr, "Unable to find <audiotriggers> element at root of %s\n", CONFIG_XML); exit(1); } node = node->children; load_sounds_from_config(node); load_triggers_from_config(node); load_logfiles_from_config(node); close_config_xml(doc); fmod_sounds = malloc(sizeof(FMOD_SOUND *) * num_sounds); open_all_sounds(system, fmod_sounds); lfi = malloc(sizeof(struct log_file_info) * num_logfiles); open_all_logfiles(); match_triggers_with_sounds(); match_logfiles_with_triggers(); print_thankyou(); /* Main loop. */ pthread_mutex_lock(&events.lock); while (1) { int sound_id; while (events.cur == events.next) { debugmsg("event queue is empty\n"); pthread_cond_wait(&events.events_available, &events.lock); } events.cur = (events.cur + 1) % NUM_EVENTS; sound_id = events.entry[events.cur].sound_id; debugmsg("main loop received sound_id %d\n", sound_id); if (sound_id < num_sounds) { int free_channel; free_channel = find_free_channel(); if (free_channel == -1) { fprintf(stderr, "WARNING: No free channels! Dropping sound\n"); } else { result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, fmod_sounds[sound_id], 0, &channel[free_channel]); ERRCHECK(result); } } else { fprintf(stderr, "sound_id: %d exceeds the last sound_id: %d\n", sound_id, num_sounds - 1); exit(1); } } release_all_sounds(fmod_sounds); close_sound_system(system); return 0; }