bool bbruntime_destroy(){ runtime_glfw3_destroy(); graphics_destroy(); blitz2d_destroy(); pixmap_destroy(); userlibs_destroy(); audio_fmod_destroy(); audio_destroy(); input_directinput8_destroy(); input_destroy(); timer_windows_destroy(); filesystem_windows_destroy(); filesystem_destroy(); system_windows_destroy(); bank_destroy(); system_destroy(); runtime_destroy(); enet_destroy(); sockets_destroy(); stream_destroy(); stdio_destroy(); string_destroy(); math_destroy(); event_destroy(); hook_destroy(); blitz_destroy(); return true; }
int main(void) { // initialize stdlib things signal(SIGINT, _finish); srand(time(NULL)); atexit(_exit_cb); // initialize ncurses initscr(); keypad(stdscr, true); nonl(); cbreak(); // TODO use raw() and handle CTRL inputs manually (no signal) noecho(); curs_set(false); nodelay(stdscr, true); // TODO support no color mode (just investigate if attron works) if (!has_colors()) { FPRINTF(stderr, "ncurses colors not supported\n"); exit(EXIT_FAILURE); } start_color(); init_pair(COLOR__GRASS, COLOR_WHITE, COLOR_GREEN); init_pair(COLOR__HP_GOOD, COLOR_GREEN, COLOR_GREEN); init_pair(COLOR__HP_WARNING, COLOR_YELLOW, COLOR_YELLOW); init_pair(COLOR__HP_DANGER, COLOR_RED, COLOR_RED); names_init(); struct game game; audio_init(&game.audio); game_init(&game); // TODO clean this up struct map_chunk chunk; map_chunk_init(&chunk); game.chunk = &chunk; // TODO improve game loop // - "rendering" and update tick do not need to have same rate // - fix input triggering after letting go, etc. for (;;) { int c = getch(); game_handle_input(&game, c); game_tick(&game); game_render(&game); ++game.frame; usleep(100000); } // clean up audio audio_destroy(&game.audio); return EXIT_SUCCESS; }
EXPORT void iaxc_shutdown() { iaxc_dump_all_calls(); get_iaxc_lock(); if ( !test_mode ) { audio_driver.destroy(&audio_driver); audio_destroy(); #ifdef USE_VIDEO video_destroy(); #endif } /* destroy enocders and decoders for all existing calls */ if ( calls ) { int i; for ( i=0 ; i<max_calls ; i++ ) { if ( calls[i].encoder ) calls[i].encoder->destroy(calls[i].encoder); if ( calls[i].decoder ) calls[i].decoder->destroy(calls[i].decoder); if ( calls[i].vencoder ) calls[i].vencoder->destroy(calls[i].vencoder); if ( calls[i].vdecoder ) calls[i].vdecoder->destroy(calls[i].vdecoder); } free(calls); calls = NULL; } put_iaxc_lock(); #ifdef WIN32 closesocket(iax_get_fd()); //fd: #endif free(calls); MUTEXDESTROY(&event_queue_lock); MUTEXDESTROY(&iaxc_lock); }
bool bbruntime_create(){ if( blitz_create() ){ if( hook_create() ){ if( event_create() ){ if( math_create() ){ if( string_create() ){ if( stdio_create() ){ if( stream_create() ){ if( sockets_create() ){ if( enet_create() ){ if( runtime_create() ){ if( system_create() ){ if( bank_create() ){ if( system_windows_create() ){ if( filesystem_create() ){ if( filesystem_windows_create() ){ if( timer_windows_create() ){ if( input_create() ){ if( input_directinput8_create() ){ if( audio_create() ){ if( audio_fmod_create() ){ if( userlibs_create() ){ if( pixmap_create() ){ if( blitz2d_create() ){ if( graphics_create() ){ if( runtime_glfw3_create() ){ return true; }else sue( "runtime_glfw3_create failed" ); graphics_destroy(); }else sue( "graphics_create failed" ); blitz2d_destroy(); }else sue( "blitz2d_create failed" ); pixmap_destroy(); }else sue( "pixmap_create failed" ); userlibs_destroy(); }else sue( "userlibs_create failed" ); audio_fmod_destroy(); }else sue( "audio_fmod_create failed" ); audio_destroy(); }else sue( "audio_create failed" ); input_directinput8_destroy(); }else sue( "input_directinput8_create failed" ); input_destroy(); }else sue( "input_create failed" ); timer_windows_destroy(); }else sue( "timer_windows_create failed" ); filesystem_windows_destroy(); }else sue( "filesystem_windows_create failed" ); filesystem_destroy(); }else sue( "filesystem_create failed" ); system_windows_destroy(); }else sue( "system_windows_create failed" ); bank_destroy(); }else sue( "bank_create failed" ); system_destroy(); }else sue( "system_create failed" ); runtime_destroy(); }else sue( "runtime_create failed" ); enet_destroy(); }else sue( "enet_create failed" ); sockets_destroy(); }else sue( "sockets_create failed" ); stream_destroy(); }else sue( "stream_create failed" ); stdio_destroy(); }else sue( "stdio_create failed" ); string_destroy(); }else sue( "string_create failed" ); math_destroy(); }else sue( "math_create failed" ); event_destroy(); }else sue( "event_create failed" ); hook_destroy(); }else sue( "hook_create failed" ); blitz_destroy(); }else sue( "blitz_create failed" ); return false; }
int main(int argc, char **argv) { wav_t *w; audio_meta_t meta; state_t s; audio_config_t audio_cfg; audio_device_t audio_dev; audio_t *audio; talking_skull_t *talking_skull; bool has_servo_track; pi_usb_init(); s.gain = 1; if ((s.m = maestro_new()) == NULL) { fprintf(stderr, "couldn't find a recognized device.\n"); exit(1); } while (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-') { if (strcmp(argv[1], "--") == 0) { argc -= 1; argv += 1; break; } if (argc > 2 && strcmp(argv[1], "--gain") == 0) { s.gain = atof(argv[2]); argc -= 2; argv += 2; } if (argc > 1 && strcmp(argv[1], "--servo") == 0) { has_servo_track = true; argc -= 1; argv += 1; } if (argc > 1 && strcmp(argv[1], "--baxter") == 0) { maestro_set_servo_range(s.m, SERVO_ID, BAXTER_MOUTH); argc -= 1; argv += 1; } if (argc > 1 && strcmp(argv[1], "--deer") == 0) { maestro_set_servo_is_inverted(s.m, SERVO_ID, 0); maestro_set_servo_range(s.m, SERVO_ID, TALKING_DEER); argc -= 1; argv += 1; } if (argc > 1 && strcmp(argv[1], "--skull2") == 0) { maestro_set_servo_is_inverted(s.m, SERVO_ID, 0); maestro_set_servo_range(s.m, SERVO_ID, TALKING_SKULL2); argc -= 1; argv += 1; } } w = wav_new(argv[1]); if (! w) { perror(argv[1]); exit(1); } meta = wav_get_meta(w); talking_skull = talking_skull_new(&meta, has_servo_track, update_servo, &s); if (has_servo_track) { wav_extract_servo_track(w); } audio_device_init_playback(&audio_dev); audio_config_init_default(&audio_cfg); wav_configure_audio(w, &audio_cfg); printf("Config from wav file: "); audio_config_print(&audio_cfg, stdout); printf("\n"); audio = audio_new(&audio_cfg, &audio_dev); if (! audio) { perror("audio_new"); exit(1); } audio_set_volume(audio, 100); wav_play_with_talking_skull(w, audio, talking_skull); if (s.m) { maestro_set_servo_pos(s.m, SERVO_ID, 50); maestro_destroy(s.m); } wav_destroy(w); audio_destroy(audio); return 0; }
int main(int argc, char **argv) { unsigned char *buffer; audio_t *in; audio_config_t cfg; audio_meta_t meta; audio_device_t in_dev, out_dev; server_args_t server_args; pthread_t server_thread; pthread_t play_thread; unsigned char *auto_play_buffer = NULL; size_t auto_play_bytes_left = 0; wav_t *auto_wav; pi_usb_init(); if ((maestro = maestro_new()) == NULL) { fprintf(stderr, "couldn't find a recognized device, disabling skull.\n"); } else { maestro_set_servo_is_inverted(maestro, SERVO_ID, true); maestro_set_servo_range(maestro, SERVO_ID, TALKING_SKULL2); } piface = piface_new(); if ((auto_wav = wav_new("chant1.wav")) == NULL) { perror("chant1.wav"); exit(1); } pthread_mutex_init(&speak_lock, NULL); server_args.port = 5555; server_args.command = remote_event; server_args.state = NULL; pc = producer_consumer_new(1); pthread_create(&server_thread, NULL, server_thread_main, &server_args); pthread_create(&play_thread, NULL, play_thread_main, NULL); audio_config_init_default(&cfg); cfg.channels = 2; cfg.rate = 48000; audio_device_init_playback(&out_dev); audio_device_init_capture(&in_dev); out = audio_new(&cfg, &out_dev); in = audio_new(&cfg, &in_dev); if (! out) { perror("out"); fprintf(stderr, "Failed to initialize playback\n"); exit(1); } if (! in) { perror("in"); fprintf(stderr, "Failed to initialize capture\n"); exit(1); } audio_set_volume(in, 100); audio_set_volume(out, 100); size = audio_get_buffer_size(in); assert(audio_get_buffer_size(out) == size); buffer = fatal_malloc(size); audio_meta_init_from_config(&meta, &cfg); skull = talking_skull_new(&meta, false, servo_update, NULL); fprintf(stderr, "Copying from capture to play using %u byte buffers\n", size); last_audio = time(NULL); while (audio_capture_buffer(in, buffer)) { pthread_mutex_lock(&speak_lock); if (auto_play_bytes_left == 0 && time(NULL) - last_audio >= IDLE_AUDIO_SECS) { auto_play_buffer = wav_get_raw_data(auto_wav, &auto_play_bytes_left); gain = 3; } if (auto_play_bytes_left > 0) { size_t n = auto_play_bytes_left > size ? size : auto_play_bytes_left; memcpy(buffer, auto_play_buffer, n); auto_play_buffer += n; auto_play_bytes_left -= n; } producer_consumer_produce(pc, buffer); pthread_mutex_unlock(&speak_lock); buffer = fatal_malloc(size); } fprintf(stderr, "Failed to capture buffer!\n"); audio_destroy(in); audio_destroy(out); free(buffer); return 0; }
static javacall_result video_destroy(javacall_handle handle) { return audio_destroy(handle); }