voltype::voltype(ODB_NAME nm, type *super, database *db):type(nm,super,db) { gettime(&ctm); }
void setupGUI() { static char text1[]="Quit"; static char text2[]="Move\nForth"; static char text3[]="Stop"; static char text4[]="Move\nBack"; static char text5[]="Wire"; static char text6[]="Pre\nMult"; static char text7[]="Pre\nInt"; static char text8[]="Rotate"; static char text9[]="H\ne\ni\ng\nh\nt"; static char text10[]="Red"; static char text11[]="Green"; static char text12[]="Blue"; static char text13[]="N\nu\nm"; static char text14[]="All"; static char text15[]="Save"; static char text16[]="Load"; static char text17[]="X"; static char text18[]="Y"; static char text19[]="Z"; static char text20[]="Rand"; static char text21[]="Clear"; static char text22[]="White"; static char text23[]="2DTF"; static char text24[]="Light"; static char text25[]="Hue"; static char text26[]="Val"; static char text27[]="Seg"; static char text28[]="Cyc"; static char text29[]="XY"; static char text30[]="YZ"; static char text31[]="Stf"; static char text32[]="Inv"; static char text33[]="Clp"; OGL_GUI.delhooks(); GUI_hook1=GUI_hook2=GUI_hook3=GUI_hook4=GUI_hook5=GUI_hook6=GUI_hook7=GUI_hook8=GUI_hook9=GUI_hook10=-1; GUI_hook11=GUI_hook12=GUI_hook13=GUI_hook14=GUI_hook15=GUI_hook16=GUI_hook17=GUI_hook18=GUI_hook19=GUI_hook20=-1; GUI_hook21=GUI_hook22=GUI_hook23=GUI_hook24=GUI_hook25=GUI_hook26=GUI_hook27=GUI_hook28=-1; if (GUI_hide) return; if (!GUI_capt) { // quit button OGL_GUI.addhook(0.025f,1.0f-0.025f-0.05f,0.075f,0.05f, 0.0f,1.0f,1.0f,0.75f, GUI::buttonhook,(void *)quithook,GUI::buttondraw,text1); // move button GUI_hook1=OGL_GUI.addhook(0.025f,0.6f,0.075f,0.05f, 120.0f,0.9f,0.9f,0.75f, GUI::buttonhook,(void *)acchook,GUI::buttondraw,text2); // stop button GUI_hook2=OGL_GUI.addhook(0.025f,0.55f,0.075f,0.05f, 240.0f,0.75f,0.9f,0.75f, GUI::buttonhook,(void *)stophook,GUI::buttondraw,text3); // back button GUI_hook3=OGL_GUI.addhook(0.025f,0.5f,0.075f,0.05f, 120.0f,0.9f,0.9f,0.75f, GUI::buttonhook,(void *)dechook,GUI::buttondraw,text4); // wire frame check button GUI_hook4=OGL_GUI.addhook(1.0f-0.025f-0.075f,1.0f-0.025f-0.025f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_wire,GUI::pushbuttondraw,text5); // premult check button GUI_hook5=OGL_GUI.addhook(1.0f-0.025f-0.075f,1.0f-2*(0.025f+0.05f),0.075f,0.05f, 240.0f,0.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_premult,GUI::pushbuttondraw,text6); // preint check buton GUI_hook6=OGL_GUI.addhook(1.0f-0.025f-0.075f,1.0f-3*(0.025f+0.05f),0.075f,0.05f, 240.0f,0.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_preint,GUI::pushbuttondraw,text7); // rotate wheel OGL_GUI.addhook(0.5f-0.2f,1.0f-0.0625f,0.4f,0.0375f, 0.0f,0.0f,0.9f,0.75f, GUI::wheelhookX,&GUI_rot,GUI::wheeldrawX,text8); // height slider OGL_GUI.addhook(1.0f-0.0625f,0.5f-0.15f,0.0375f,0.325f, 0.0f,0.0f,0.9f,0.75f, GUI::sliderhookY,&GUI_height,GUI::sliderdrawY,text9); } if (!GUI_grad || !GUI_STF) if (!GUI_capt) { // small 1D transfer function for emission: OGL_GUI.addhook(0.025f,0.025f,0.7f,0.1f, 0.0f,0.0f,0.2f,0.9f, tfEhook,NULL,tfEdraw,NULL); OGL_GUI.addhook(0.025f,0.025f-0.008f,0.7f,0.1f+2*0.008f, 0.0f,0.0f,0.0f,0.0f, tfE2hook,NULL,NULL,NULL); // small 1D transfer function for opacity: OGL_GUI.addhook(0.025f,0.025f+0.1f+0.025f,0.7f,0.1f, 0.0f,0.0f,0.2f,0.9f, tfAhook,NULL,tfAdraw,NULL); OGL_GUI.addhook(0.025f,0.025f+0.1f+0.025f-0.008f,0.7f,0.1f+2*0.008f, 0.0f,0.0f,0.0f,0.0f, tfA2hook,NULL,NULL,NULL); } else { // full width 1D transfer function for emission: OGL_GUI.addhook(0.025f,0.025f,0.95f,0.1f, 0.0f,0.0f,0.2f,0.9f, tfEhook,NULL,tfEdraw,NULL); OGL_GUI.addhook(0.025f,0.025f-0.008f,0.95f,0.1f+2*0.008f, 0.0f,0.0f,0.0f,0.0f, tfE2hook,NULL,NULL,NULL); // full width 1D transfer function for opacity: OGL_GUI.addhook(0.025f,0.025f+0.1f+0.025f,0.95f,0.1f, 0.0f,0.0f,0.2f,0.9f, tfAhook,NULL,tfAdraw,NULL); OGL_GUI.addhook(0.025f,0.025f+0.1f+0.025f-0.008f,0.95f,0.1f+2*0.008f, 0.0f,0.0f,0.0f,0.0f, tfA2hook,NULL,NULL,NULL); } else if (!GUI_capt) { // large 2D transfer function: OGL_GUI.addhook(0.025f,0.025f,0.7f,0.2f+0.025f, 0.0f,0.0f,0.2f,0.9f, tfEhook,NULL,tfEdraw,NULL); OGL_GUI.addhook(0.025f,0.025f-0.008f,0.7f,0.2f+0.025f+2*0.008f, 0.0f,0.0f,0.0f,0.0f, tfE2hook,NULL,NULL,NULL); } else { // full width 2D transfer function: OGL_GUI.addhook(0.025f,0.025f,0.95f,0.2f+0.025f, 0.0f,0.0f,0.2f,0.9f, tfEhook,NULL,tfEdraw,NULL); OGL_GUI.addhook(0.025f,0.025f-0.008f,0.95f,0.2f+0.025f+2*0.008f, 0.0f,0.0f,0.0f,0.0f, tfE2hook,NULL,NULL,NULL); } if (!GUI_capt) { // blue emission scaling slider OGL_GUI.addhook(0.8f,0.025f,0.175f,0.03f, 0.0f,0.0f,0.9f,0.75f, tfEsliderhook,&GUI_be_scale,GUI::sliderdrawX,text12); // blue emission modification check button GUI_hook7=OGL_GUI.addhook(0.7375f,0.025f,0.05f,0.03f, 240.0f,1.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_be_mod,GUI::pushbuttondraw,text12); // green emission scaling slider OGL_GUI.addhook(0.8f,0.025f+0.05f-0.015f,0.175f,0.03f, 0.0f,0.0f,0.9f,0.75f, tfEsliderhook,&GUI_ge_scale,GUI::sliderdrawX,text11); // green emission modification check button GUI_hook8=OGL_GUI.addhook(0.7375f,0.025f+0.05f-0.015f,0.05f,0.03f, 120.0f,1.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_ge_mod,GUI::pushbuttondraw,text11); // red emission scaling slider OGL_GUI.addhook(0.8f,0.025f+0.1f-0.03f,0.175f,0.03f, 0.0f,0.0f,0.9f,0.75f, tfEsliderhook,&GUI_re_scale,GUI::sliderdrawX,text10); // red emission modification check button GUI_hook9=OGL_GUI.addhook(0.7375f,0.025f+0.1f-0.03f,0.05f,0.03f, 0.0f,1.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_re_mod,GUI::pushbuttondraw,text10); // blue opacity scaling slider OGL_GUI.addhook(0.8f,0.025f+0.1f+0.025f,0.175f,0.03f, 0.0f,0.0f,0.9f,0.75f, tfAsliderhook,&GUI_ba_scale,GUI::sliderdrawX,text12); // blue opacity modification check button GUI_hook10=OGL_GUI.addhook(0.7375f,0.025f+0.1f+0.025f,0.05f,0.03f, 240.0f,1.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_ba_mod,GUI::pushbuttondraw,text12); // green opacity scaling slider OGL_GUI.addhook(0.8f,0.025f+0.1f+0.025f+0.05f-0.015f,0.175f,0.03f, 0.0f,0.0f,0.9f,0.75f, tfAsliderhook,&GUI_ga_scale,GUI::sliderdrawX,text11); // green opacity modification check button GUI_hook11=OGL_GUI.addhook(0.7375f,0.025f+0.1f+0.025f+0.05f-0.015f,0.05f,0.03f, 120.0f,1.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_ga_mod,GUI::pushbuttondraw,text11); // red opacity scaling slider OGL_GUI.addhook(0.8f,0.025f+0.1f+0.025f+0.1f-0.03f,0.175f,0.03f, 0.0f,0.0f,0.9f,0.75f, tfAsliderhook,&GUI_ra_scale,GUI::sliderdrawX,text10); // red opacity modification check button GUI_hook12=OGL_GUI.addhook(0.7375f,0.025f+0.1f+0.025f+0.1f-0.03f,0.05f,0.03f, 0.0f,1.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_ra_mod,GUI::pushbuttondraw,text10); } // dummy hook for transfer function area OGL_GUI.addhook(0.0f,0.0f,1.0f,3*0.025f+0.2f, 0.0f,0.0f,0.0f,0.0f, GUI::buttonhook,NULL,NULL,NULL); if (!GUI_capt) { // slab thickness slider GUI_hook13=OGL_GUI.addhook(0.025f,0.35f,0.035f,0.125f, 0.0f,0.0f,0.9f,0.75f, GUI::sliderhookY,&GUI_slab1,GUI::sliderdrawY,text13); // reduced slab thickness slider OGL_GUI.addhook(0.065f,0.35f,0.035f,0.125f, 0.0f,0.0f,0.9f,0.75f, GUI::sliderhookY,&GUI_slab2,GUI::sliderdrawY,NULL); // coupled modification check button GUI_hook14=OGL_GUI.addhook(1.0f-0.025f-0.075f,0.25f+0.025f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_coupled,GUI::pushbuttondraw,text14); // save button GUI_hook15=OGL_GUI.addhook(0.025f,1.0f-2*(0.025f+0.05f),0.075f,0.05f, 240.0f,0.5f,1.0f,0.75f, GUI::buttonhook,(void *)savehook,GUI::buttondraw,text15); // load button GUI_hook16=OGL_GUI.addhook(0.025f,1.0f-3*(0.025f+0.05f),0.075f,0.05f, 240.0f,0.5f,1.0f,0.75f, GUI::buttonhook,(void *)loadhook,GUI::buttondraw,text16); // x-swap button OGL_GUI.addhook(0.025f,1.0f-4*(0.025f+0.05f),0.025f,0.025f, 300.0f,0.5f,1.0f,0.75f, GUI::buttonhook,(void *)xswaphook,GUI::buttondraw,text17); // y-swap button OGL_GUI.addhook(0.05f,1.0f-4*(0.025f+0.05f),0.025f,0.025f, 300.0f,0.5f,1.0f,0.75f, GUI::buttonhook,(void *)yswaphook,GUI::buttondraw,text18); // z-swap button OGL_GUI.addhook(0.075f,1.0f-4*(0.025f+0.05f),0.025f,0.025f, 300.0f,0.5f,1.0f,0.75f, GUI::buttonhook,(void *)zswaphook,GUI::buttondraw,text19); // randomize button GUI_hook17=OGL_GUI.addhook(1.0f-0.2f,0.275f+0.025f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, GUI::buttonhook,(void *)randhook,GUI::buttondraw,text20); // clear button GUI_hook18=OGL_GUI.addhook(1.0f-0.2f,0.275f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, GUI::buttonhook,(void *)clearhook,GUI::buttondraw,text21); // white background check button GUI_hook19=OGL_GUI.addhook(1.0f-0.025f-0.075f,1.0f-0.025f-0.05f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, GUI::pushbuttonhook,&GUI_white,GUI::pushbuttondraw,text22); // 2DTF check button GUI_hook20=OGL_GUI.addhook(1.0f-0.025f-0.075f,1.0f-4*(0.025f+0.05f)+0.025f,0.075f,0.025f, 200.0f,0.0f,0.9f,0.75f, reloadhook,&GUI_grad,GUI::pushbuttondraw,text23); // lighting check button GUI_hook21=OGL_GUI.addhook(1.0f-0.025f-0.075f,1.0f-4*(0.025f+0.05f),0.075f,0.025f, 200.0f,0.0f,0.9f,0.75f, reloadhook,&GUI_light,GUI::pushbuttondraw,text24); // hue shift check button GUI_hook22=OGL_GUI.addhook(0.025f,0.275f+0.025f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, reloadhook,&GUI_gmc,GUI::pushbuttondraw,text25); // display mode check button GUI_hook23=OGL_GUI.addhook(0.025f,0.275f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, reloadhook,&GUI_mod,GUI::pushbuttondraw,text26); // segmentation check button GUI_hook24=OGL_GUI.addhook(0.025f+0.1f,0.275f+0.025f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, reloadhook,&GUI_mat,GUI::pushbuttondraw,text27); // material cycling button GUI_hook25=OGL_GUI.addhook(0.025f+0.1f,0.275f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, GUI::buttonhook,(void *)cyclehook,GUI::buttondraw,text28); // xy-rotate button OGL_GUI.addhook(0.025f,1.0f-4*(0.025f+0.05f)+0.025f,0.0375f,0.025f, 300.0f,0.5f,1.0f,0.75f, GUI::buttonhook,(void *)xrothook,GUI::buttondraw,text29); // yz-rotate button OGL_GUI.addhook(0.025f+0.0375f,1.0f-4*(0.025f+0.05f)+0.025f,0.0375f,0.025f, 300.0f,0.5f,1.0f,0.75f, GUI::buttonhook,(void *)zrothook,GUI::buttondraw,text30); // STF check button GUI_hook26=OGL_GUI.addhook(1.0f-0.025f-0.075f,0.25f+0.05f,0.075f,0.025f, 0.0f,0.0f,0.9f,0.75f, reloadhook,&GUI_STF,GUI::pushbuttondraw,text31); // inverse check button GUI_hook27=OGL_GUI.addhook(0.025f+0.1f,1.0f-0.025f-0.05f,0.075f,0.05f, 0.0f,0.0f,0.9f,0.75f, reloadhook,&GUI_inv,GUI::pushbuttondraw,text32); // clip check button GUI_hook28=OGL_GUI.addhook(1.0f-0.025f-0.075f-0.1f,1.0f-0.025f-0.05f,0.075f,0.05f, 0.0f,0.0f,0.9f,0.75f, reloadhook,&GUI_clip,GUI::pushbuttondraw,text33); } GUI_time=gettime(); }
void end_section(int section_type) { long long end = gettime(); time_in_section[section_type] += end - last_start[section_type]; }
int main( int argc, char *argv[] ) { char fn[MAX_STRING] = ""; int do_search = 0; search_t *search; conf_t conf[1]; axel_t *axel; int i, j, cur_head = 0; char *s; #ifdef I18N setlocale( LC_ALL, "" ); bindtextdomain( PACKAGE, LOCALE ); textdomain( PACKAGE ); #endif if( !conf_init( conf ) ) { return( 1 ); } opterr = 0; j = -1; while( 1 ) { int option; option = getopt_long( argc, argv, "s:n:o:S::NqvhVaH:U:", axel_options, NULL ); if( option == -1 ) break; switch( option ) { case 'U': strncpy( conf->user_agent, optarg, MAX_STRING); break; case 'H': strncpy( conf->add_header[cur_head++], optarg, MAX_STRING ); break; case 's': if( !sscanf( optarg, "%i", &conf->max_speed ) ) { print_help(); return( 1 ); } break; case 'n': if( !sscanf( optarg, "%i", &conf->num_connections ) ) { print_help(); return( 1 ); } break; case 'o': strncpy( fn, optarg, MAX_STRING ); break; case 'S': do_search = 1; if( optarg != NULL ) if( !sscanf( optarg, "%i", &conf->search_top ) ) { print_help(); return( 1 ); } break; case 'a': conf->alternate_output = 1; break; case 'N': *conf->http_proxy = 0; break; case 'h': print_help(); return( 0 ); case 'v': if( j == -1 ) j = 1; else j ++; break; case 'V': print_version(); return( 0 ); case 'q': close( 1 ); conf->verbose = -1; if( open( "/dev/null", O_WRONLY ) != 1 ) { fprintf( stderr, _("Can't redirect stdout to /dev/null.\n") ); return( 1 ); } break; default: print_help(); return( 1 ); } } conf->add_header_count = cur_head; if( j > -1 ) conf->verbose = j; if( argc - optind == 0 ) { print_help(); return( 1 ); } else if( strcmp( argv[optind], "-" ) == 0 ) { s = malloc( MAX_STRING ); if (scanf( "%1024[^\n]s", s) != 1) { fprintf( stderr, _("Error when trying to read URL (Too long?).\n") ); return( 1 ); } } else { s = argv[optind]; if( strlen( s ) > MAX_STRING ) { fprintf( stderr, _("Can't handle URLs of length over %d\n" ), MAX_STRING ); return( 1 ); } } printf( _("Initializing download: %s\n"), s ); if( do_search ) { search = malloc( sizeof( search_t ) * ( conf->search_amount + 1 ) ); memset( search, 0, sizeof( search_t ) * ( conf->search_amount + 1 ) ); search[0].conf = conf; if( conf->verbose ) printf( _("Doing search...\n") ); i = search_makelist( search, s ); if( i < 0 ) { fprintf( stderr, _("File not found\n" ) ); return( 1 ); } if( conf->verbose ) printf( _("Testing speeds, this can take a while...\n") ); j = search_getspeeds( search, i ); search_sortlist( search, i ); if( conf->verbose ) { printf( _("%i usable servers found, will use these URLs:\n"), j ); j = min( j, conf->search_top ); printf( "%-60s %15s\n", "URL", "Speed" ); for( i = 0; i < j; i ++ ) printf( "%-70.70s %5i\n", search[i].url, search[i].speed ); printf( "\n" ); } axel = axel_new( conf, j, search ); free( search ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } else if( argc - optind == 1 ) { axel = axel_new( conf, 0, s ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } else { search = malloc( sizeof( search_t ) * ( argc - optind ) ); memset( search, 0, sizeof( search_t ) * ( argc - optind ) ); for( i = 0; i < ( argc - optind ); i ++ ) strncpy( search[i].url, argv[optind+i], MAX_STRING ); axel = axel_new( conf, argc - optind, search ); free( search ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } print_messages( axel ); if( s != argv[optind] ) { free( s ); } if( *fn ) { struct stat buf; if( stat( fn, &buf ) == 0 ) { if( S_ISDIR( buf.st_mode ) ) { size_t fnlen = strlen(fn); size_t axelfnlen = strlen(axel->filename); if (fnlen + 1 + axelfnlen + 1 > MAX_STRING) { fprintf( stderr, _("Filename too long!\n")); return ( 1 ); } fn[fnlen] = '/'; memcpy(fn+fnlen+1, axel->filename, axelfnlen); fn[fnlen + 1 + axelfnlen] = '\0'; } } sprintf( string, "%s.st", fn ); if( access( fn, F_OK ) == 0 ) if( access( string, F_OK ) != 0 ) { fprintf( stderr, _("No state file, cannot resume!\n") ); return( 1 ); } if( access( string, F_OK ) == 0 ) if( access( fn, F_OK ) != 0 ) { printf( _("State file found, but no downloaded data. Starting from scratch.\n" ) ); unlink( string ); } strcpy( axel->filename, fn ); } else { /* Local file existence check */ i = 0; s = axel->filename + strlen( axel->filename ); while( 1 ) { sprintf( string, "%s.st", axel->filename ); if( access( axel->filename, F_OK ) == 0 ) { if( axel->conn[0].supported ) { if( access( string, F_OK ) == 0 ) break; } } else { if( access( string, F_OK ) ) break; } sprintf( s, ".%i", i ); i ++; } } if( !axel_open( axel ) ) { print_messages( axel ); return( 1 ); } print_messages( axel ); axel_start( axel ); print_messages( axel ); if( conf->alternate_output ) { putchar('\n'); } else { if( axel->bytes_done > 0 ) /* Print first dots if resuming */ { putchar( '\n' ); print_commas( axel->bytes_done ); } } axel->start_byte = axel->bytes_done; /* Install save_state signal handler for resuming support */ signal( SIGINT, stop ); signal( SIGTERM, stop ); while( !axel->ready && run ) { long long int prev, done; prev = axel->bytes_done; axel_do( axel ); if( conf->alternate_output ) { if( !axel->message && prev != axel->bytes_done ) print_alternate_output( axel ); } else { /* The infamous wget-like 'interface'.. ;) */ done = ( axel->bytes_done / 1024 ) - ( prev / 1024 ); if( done && conf->verbose > -1 ) { for( i = 0; i < done; i ++ ) { i += ( prev / 1024 ); if( ( i % 50 ) == 0 ) { if( prev >= 1024 ) printf( " [%6.1fKB/s]", (double) axel->bytes_per_second / 1024 ); if( axel->size < 10240000 ) printf( "\n[%3lld%%] ", min( 100, 102400 * i / axel->size ) ); else printf( "\n[%3lld%%] ", min( 100, i / ( axel->size / 102400 ) ) ); } else if( ( i % 10 ) == 0 ) { putchar( ' ' ); } putchar( '.' ); i -= ( prev / 1024 ); } fflush( stdout ); } } if( axel->message ) { if(conf->alternate_output==1) { /* clreol-simulation */ putchar( '\r' ); for( i = 0; i < 79; i++ ) /* linewidth known? */ putchar( ' ' ); putchar( '\r' ); } else { putchar( '\n' ); } print_messages( axel ); if( !axel->ready ) { if(conf->alternate_output!=1) print_commas( axel->bytes_done ); else print_alternate_output(axel); } } else if( axel->ready ) { putchar( '\n' ); } } strcpy( string + MAX_STRING / 2, size_human( axel->bytes_done - axel->start_byte ) ); printf( _("\nDownloaded %s in %s. (%.2f KB/s)\n"), string + MAX_STRING / 2, time_human( gettime() - axel->start_time ), (double) axel->bytes_per_second / 1024 ); i = axel->ready ? 0 : 2; axel_close( axel ); return( i ); }
Uint32 SDL_GetTicks (void) { const Uint64 ticks = gettime(); const Uint64 ms = ticks / TB_TIMER_CLOCK; return ms; }
int main(int argc, char **argv) { FFTComplex *tab, *tab1, *tab_ref; FFTSample *tab2; int it, i, c; int do_speed = 0; int do_mdct = 0; int do_inverse = 0; FFTContext s1, *s = &s1; MDCTContext m1, *m = &m1; int fft_nbits, fft_size; fft_nbits = 9; for(;;) { c = getopt(argc, argv, "hsimn:"); if (c == -1) break; switch(c) { case 'h': help(); break; case 's': do_speed = 1; break; case 'i': do_inverse = 1; break; case 'm': do_mdct = 1; break; case 'n': fft_nbits = atoi(optarg); break; } } fft_size = 1 << fft_nbits; tab = av_malloc(fft_size * sizeof(FFTComplex)); tab1 = av_malloc(fft_size * sizeof(FFTComplex)); tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); tab2 = av_malloc(fft_size * sizeof(FFTSample)); if (do_mdct) { if (do_inverse) av_log(NULL, AV_LOG_INFO,"IMDCT"); else av_log(NULL, AV_LOG_INFO,"MDCT"); ff_mdct_init(m, fft_nbits, do_inverse); } else { if (do_inverse) av_log(NULL, AV_LOG_INFO,"IFFT"); else av_log(NULL, AV_LOG_INFO,"FFT"); ff_fft_init(s, fft_nbits, do_inverse); fft_ref_init(fft_nbits, do_inverse); } av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); /* generate random data */ for(i=0;i<fft_size;i++) { tab1[i].re = frandom(); tab1[i].im = frandom(); } /* checking result */ av_log(NULL, AV_LOG_INFO,"Checking...\n"); if (do_mdct) { if (do_inverse) { imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ff_imdct_calc(m, tab2, (float *)tab1); check_diff((float *)tab_ref, tab2, fft_size); } else { mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ff_mdct_calc(m, tab2, (float *)tab1); check_diff((float *)tab_ref, tab2, fft_size / 2); } } else { memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); ff_fft_permute(s, tab); ff_fft_calc(s, tab); fft_ref(tab_ref, tab1, fft_nbits); check_diff((float *)tab_ref, (float *)tab, fft_size * 2); } /* do a speed test */ if (do_speed) { int64_t time_start, duration; int nb_its; av_log(NULL, AV_LOG_INFO,"Speed test...\n"); /* we measure during about 1 seconds */ nb_its = 1; for(;;) { time_start = gettime(); for(it=0;it<nb_its;it++) { if (do_mdct) { if (do_inverse) { ff_imdct_calc(m, (float *)tab, (float *)tab1); } else { ff_mdct_calc(m, (float *)tab, (float *)tab1); } } else { memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); ff_fft_calc(s, tab); } } duration = gettime() - time_start; if (duration >= 1000000) break; nb_its *= 2; } av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n", (double)duration / nb_its, (double)duration / 1000000.0, nb_its); } if (do_mdct) { ff_mdct_end(m); } else { ff_fft_end(s); } return 0; }
void service_start(struct service *svc, const char *dynamic_args) { struct stat s; pid_t pid; int needs_console; int n; char *scon = NULL; int rc; /* starting a service removes it from the disabled or reset * state and immediately takes it out of the restarting * state if it was in there */ svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET|SVC_RESTART)); svc->time_started = 0; /* running processes require no additional work -- if * they're in the process of exiting, we've ensured * that they will immediately restart on exit, unless * they are ONESHOT */ if (svc->flags & SVC_RUNNING) { return; } needs_console = (svc->flags & SVC_CONSOLE) ? 1 : 0; if (needs_console && (!have_console)) { ERROR("service '%s' requires console\n", svc->name); svc->flags |= SVC_DISABLED; return; } if (stat(svc->args[0], &s) != 0) { ERROR("cannot find '%s', disabling '%s'\n", svc->args[0], svc->name); svc->flags |= SVC_DISABLED; return; } if ((!(svc->flags & SVC_ONESHOT)) && dynamic_args) { ERROR("service '%s' must be one-shot to use dynamic args, disabling\n", svc->args[0]); svc->flags |= SVC_DISABLED; return; } if (is_selinux_enabled() > 0) { if (svc->seclabel) { scon = strdup(svc->seclabel); if (!scon) { ERROR("Out of memory while starting '%s'\n", svc->name); return; } } else { char *mycon = NULL, *fcon = NULL; INFO("computing context for service '%s'\n", svc->args[0]); rc = getcon(&mycon); if (rc < 0) { ERROR("could not get context while starting '%s'\n", svc->name); return; } rc = getfilecon(svc->args[0], &fcon); if (rc < 0) { ERROR("could not get context while starting '%s'\n", svc->name); freecon(mycon); return; } rc = security_compute_create(mycon, fcon, string_to_security_class("process"), &scon); if (rc == 0 && !strcmp(scon, mycon)) { ERROR("Warning! Service %s needs a SELinux domain defined; please fix!\n", svc->name); } freecon(mycon); freecon(fcon); if (rc < 0) { ERROR("could not get context while starting '%s'\n", svc->name); return; } } } NOTICE("starting '%s'\n", svc->name); pid = fork(); if (pid == 0) { struct socketinfo *si; struct svcenvinfo *ei; char tmp[32]; int fd, sz; umask(077); if (properties_inited()) { get_property_workspace(&fd, &sz); sprintf(tmp, "%d,%d", dup(fd), sz); add_environment("ANDROID_PROPERTY_WORKSPACE", tmp); } for (ei = svc->envvars; ei; ei = ei->next) add_environment(ei->name, ei->value); for (si = svc->sockets; si; si = si->next) { int socket_type = ( !strcmp(si->type, "stream") ? SOCK_STREAM : (!strcmp(si->type, "dgram") ? SOCK_DGRAM : SOCK_SEQPACKET)); int s = create_socket(si->name, socket_type, si->perm, si->uid, si->gid, si->socketcon ?: scon); if (s >= 0) { publish_socket(si->name, s); } } freecon(scon); scon = NULL; if (svc->ioprio_class != IoSchedClass_NONE) { if (android_set_ioprio(getpid(), svc->ioprio_class, svc->ioprio_pri)) { ERROR("Failed to set pid %d ioprio = %d,%d: %s\n", getpid(), svc->ioprio_class, svc->ioprio_pri, strerror(errno)); } } if (needs_console) { setsid(); open_console(); } else { zap_stdio(); } #if 0 for (n = 0; svc->args[n]; n++) { INFO("args[%d] = '%s'\n", n, svc->args[n]); } for (n = 0; ENV[n]; n++) { INFO("env[%d] = '%s'\n", n, ENV[n]); } #endif setpgid(0, getpid()); /* as requested, set our gid, supplemental gids, and uid */ if (svc->gid) { if (setgid(svc->gid) != 0) { ERROR("setgid failed: %s\n", strerror(errno)); _exit(127); } } if (svc->nr_supp_gids) { if (setgroups(svc->nr_supp_gids, svc->supp_gids) != 0) { ERROR("setgroups failed: %s\n", strerror(errno)); _exit(127); } } if (svc->uid) { if (setuid(svc->uid) != 0) { ERROR("setuid failed: %s\n", strerror(errno)); _exit(127); } } if (svc->seclabel) { if (is_selinux_enabled() > 0 && setexeccon(svc->seclabel) < 0) { ERROR("cannot setexeccon('%s'): %s\n", svc->seclabel, strerror(errno)); _exit(127); } } if (!dynamic_args) { if (execve(svc->args[0], (char**) svc->args, (char**) ENV) < 0) { ERROR("cannot execve('%s'): %s\n", svc->args[0], strerror(errno)); } } else { char *arg_ptrs[INIT_PARSER_MAXARGS+1]; int arg_idx = svc->nargs; char *tmp = strdup(dynamic_args); char *next = tmp; char *bword; /* Copy the static arguments */ memcpy(arg_ptrs, svc->args, (svc->nargs * sizeof(char *))); while((bword = strsep(&next, " "))) { arg_ptrs[arg_idx++] = bword; if (arg_idx == INIT_PARSER_MAXARGS) break; } arg_ptrs[arg_idx] = '\0'; execve(svc->args[0], (char**) arg_ptrs, (char**) ENV); } _exit(127); } freecon(scon); if (pid < 0) { ERROR("failed to start '%s'\n", svc->name); svc->pid = 0; return; } svc->time_started = gettime(); svc->pid = pid; svc->flags |= SVC_RUNNING; if (properties_inited()) notify_service_state(svc->name, "running"); }
int main() { int t, i, j, k; // Define the size of the grids (use quadratic grids) int x_max = GRID_SIZE; int y_max = GRID_SIZE; // Grids to store the E-field (two components) and the H-field (one // component) for t and t+1 float *_e_0_0, *e_0_0; float *_e_1_0, *e_1_0; float *_e_0_1, *e_0_1; float *_e_1_1, *e_1_1; float *_h_2_0, *h_2_0; float *_h_2_1, *h_2_1; // Grids with the constants defining the material float *_ca, *ca; float *_cb, *cb; float *_da, *da; float *_db, *db; // Output grid for the averaged electromagnetic energy float *_u_em, *u_em; // Allocate memory allocate(&_e_0_0, &e_0_0, x_max, y_max); allocate(&_e_1_0, &e_1_0, x_max, y_max); allocate(&_e_0_1, &e_0_1, x_max, y_max); allocate(&_e_1_1, &e_1_1, x_max, y_max); allocate(&_h_2_0, &h_2_0, x_max, y_max); allocate(&_h_2_1, &h_2_1, x_max, y_max); allocate(&_ca, &ca, x_max, y_max); allocate(&_cb, &cb, x_max, y_max); allocate(&_da, &da, x_max, y_max); allocate(&_db, &db, x_max, y_max); allocate(&_u_em, &u_em, x_max, y_max); // Initialize float ca_vacuum = calculateCa(0.0f, 1.0f); float cb_vacuum = calculateCb(0.0f, 1.0f); float da_vacuum = calculateDa(0.0f, 1.0f); float db_vacuum = calculateDb(0.0f, 1.0f); // Choose one of PMC or PEC // Material properties for PMC // magnetic field in the conductor is always 0) float ca_material = calculateCa(0.0f, 1.0f); float cb_material = calculateCb(0.0f, 1.0f); float da_material = 0.0f; float db_material = 0.0f; /* // Material properties for PEC // (electric field in the conductor is always 0) float ca_material = 0.0f; float cb_material = 0.0f; float da_material = calculateDa(0.0f, 1.0f); float db_material = calculateDb(0.0f, 1.0f); */ // Call initialization functions generated by Patus initialize_fdtdE2D(e_0_0, e_1_0, e_0_1, e_1_1, h_2_0, ca, cb, ca_vacuum, ca_material, cb_vacuum, cb_material, x_max, y_max); initialize_fdtdH2D(e_0_0, e_1_0, h_2_0, h_2_1, da, db, da_vacuum, da_material, db_vacuum, db_material, x_max, y_max); initialize_integrate(e_0_0, e_1_0, h_2_0, u_em, u_em, MU, EPSILON, x_max, y_max); // Pointers to output, not actually needed float* dummy = NULL; // Simulation loop // Call Patus-generated kernels double fTimeStart = gettime (); #pragma omp parallel private (t) { for (t = 0; t < T_MAX; t++) { fdtdE2D (&dummy, &dummy, e_0_0, e_1_0, e_0_1, e_1_1, h_2_0, ca, cb, ca_vacuum, ca_material, cb_vacuum, cb_material, x_max, y_max ); #pragma omp barrier #pragma omp single { // Rotate grid pointers (need to do this manually since // we compute only one timestep in the generated functions) float* temp0 = e_0_0; e_0_0 = e_0_1; e_0_1 = temp0; float* temp1 = e_1_0; e_1_0 = e_1_1; e_1_1 = temp1; } fdtdH2D (&dummy, e_0_0, e_1_0, h_2_0, h_2_1, da, db, da_vacuum, da_material, db_vacuum, db_material, x_max, y_max ); #pragma omp barrier #pragma omp single { // Rotate grid pointers float* temp2 = h_2_0; h_2_0 = h_2_1; h_2_1 = temp2; // Adding the source, needs to lie in vacuum disk h_2_0[POS((int) (GRID_SIZE * 0.5), (int) (GRID_SIZE * 0.3))] += gaussianSource(t*DT); } // Accumulate the energy density if (t > 4000) { integrate (&dummy, e_0_0, e_1_0, h_2_0, u_em, u_em, MU, EPSILON, x_max, y_max ); #pragma omp barrier } } } double fTimeEnd = gettime(); printf("Time used: %f s\n", fTimeEnd - fTimeStart); // Write the output to a file write(u_em, x_max, y_max); // Clean up free (_e_0_0); free (_e_1_0); free (_e_0_1); free (_e_1_1); free (_h_2_0); free (_h_2_1); free (_u_em); free (_ca); free (_cb); free (_da); free (_db); return 0; }
int main(int argc, char*argv[]) { struct hadoopRzOptions *zopts = NULL; struct hadoopRzBuffer *rzbuf = NULL; if (argc < 4) { usage(); } char* filename = argv[1]; int num_iters = atoi(argv[2]); char method = *argv[3]; if (NULL == strchr("mrzh", method)) { usage(); } int ret; void* aligned = NULL; // If local mem, copy file into a local mlock'd aligned buffer if (method == 'm') { printf("Creating %d of aligned data...\n", size); aligned = memalign(32, size); if (aligned == NULL) { perror("memalign"); exit(3); } // Read the specified file in buffer int fd = open(filename, O_RDONLY); int total_bytes = 0; while (total_bytes < size) { int bytes = read(fd, aligned+total_bytes, size-total_bytes); if (bytes == -1) { perror("read"); exit(-1); } total_bytes += bytes; } printf("Attempting mlock of buffer\n"); ret = mlock(aligned, size); if (ret != 0) { perror("mlock"); exit(2); } } printf("Summing output %d times...\n", num_iters); int i, j, k, l; // Copy data into this intermediate buffer const int buffer_size = (8*1024*1024); void *temp_buffer; ret = posix_memalign(&temp_buffer, 32, buffer_size); if (ret != 0) { printf("error in posix_memalign\n"); exit(ret); } // This is for loop unrolling (unroll 4 times) __m128d* tempd = memalign(32, 16*4); struct timespec start, end; if (tempd == NULL) { perror("memalign"); exit(3); } const int print_iters = 10; double end_sum = 0; hdfsFS fs = NULL; if (method == 'h' || method == 'z') { struct hdfsBuilder *builder = hdfsNewBuilder(); hdfsBuilderSetNameNode(builder, "default"); hdfsBuilderConfSetStr(builder, "dfs.client.read.shortcircuit.skip.checksum", "true"); fs = hdfsBuilderConnect(builder); if (fs == NULL) { printf("Could not connect to default namenode!\n"); exit(-1); } } for (i=0; i<num_iters; i+=print_iters) { gettime(&start); __m128d sum; // Number of packed doubles we've processed for (j=0; j<print_iters; j++) { int offset = 0; int fd = 0; hdfsFile hdfsFile = NULL; if (method == 'r') { fd = open(filename, O_RDONLY); } // hdfs zerocopy read else if (method == 'z') { zopts = hadoopRzOptionsAlloc(); if (!zopts) abort(); if (hadoopRzOptionsSetSkipChecksum(zopts, 1)) abort(); if (hadoopRzOptionsSetByteBufferPool(zopts, NULL)) abort(); hdfsFile = hdfsOpenFile(fs, filename, O_RDONLY, 0, 0, 0); } // hdfs normal read else if (method == 'h') { hdfsFile = hdfsOpenFile(fs, filename, O_RDONLY, 0, 0, 0); } // Each iteration, process the buffer once for (k=0; k<size; k+=buffer_size) { // Set this with varying methods! const double* buffer = NULL; // Local file read if (method == 'r') { // do read int total_bytes = 0; while (total_bytes < buffer_size) { int bytes = read(fd, temp_buffer+total_bytes, buffer_size-total_bytes); if (bytes < 0) { printf("Error on read\n"); return -1; } total_bytes += bytes; } buffer = (double*)temp_buffer; } // Local memory read else if (method == 'm') { buffer = (double*)(aligned + offset); } // hdfs zerocopy read else if (method == 'z') { int len; rzbuf = hadoopReadZero(hdfsFile, zopts, buffer_size); if (!rzbuf) abort(); buffer = hadoopRzBufferGet(rzbuf); if (!buffer) abort(); len = hadoopRzBufferLength(rzbuf); if (len < buffer_size) abort(); } // hdfs normal read else if (method == 'h') { abort(); // need to implement hdfsReadFully //ret = hdfsReadFully(fs, hdfsFile, temp_buffer, buffer_size); if (ret == -1) { printf("Error: hdfsReadFully errored\n"); exit(-1); } buffer = temp_buffer; } offset += buffer_size; // Unroll the loop a bit const double* a_ptr = &(buffer[0]); const double* b_ptr = &(buffer[2]); const double* c_ptr = &(buffer[4]); const double* d_ptr = &(buffer[6]); for (l=0; l<buffer_size; l+=64) { tempd[0] = _mm_load_pd(a_ptr); tempd[1] = _mm_load_pd(b_ptr); tempd[2] = _mm_load_pd(c_ptr); tempd[3] = _mm_load_pd(d_ptr); sum = _mm_add_pd(sum, tempd[0]); sum = _mm_add_pd(sum, tempd[1]); sum = _mm_add_pd(sum, tempd[2]); sum = _mm_add_pd(sum, tempd[3]); a_ptr += 8; b_ptr += 8; c_ptr += 8; d_ptr += 8; } if (method == 'z') { hadoopRzBufferFree(hdfsFile, rzbuf); } } // Local file read if (method == 'r') { close(fd); } // hdfs zerocopy read // hdfs normal read else if (method == 'z' || method == 'h') { hdfsCloseFile(fs, hdfsFile); } printf("iter %d complete\n", j); } gettime(&end); print_duration(&start, &end, (long)size*print_iters); // Force the compiler to actually generate above code double* unpack = (double*)∑ double final = unpack[0] + unpack[1]; end_sum += final; } if (method == 'z' || method == 'h') { hdfsDisconnect(fs); } printf("%f\n", end_sum); return 0; }
void flip_sequencer() { if ( !isflipping) return; if (onground) flipstage = STAGE_FLIP_EXIT; if ( isflipping && gettime() - fliptime > FLIP_TIMEOUT_TOTAL ) { // abort after 1 second flipstage = STAGE_FLIP_EXIT; } switch (flipstage ) { case STAGE_FLIP_NONE: break; case STAGE_FLIP_START: // acro_override = 1; controls_override = 1; rx_override[1] = 0; rx_override[2] = 0; rx_override[3] = THROTTLE_UP; if ( GEstG[2] < 0 ) { // flip initiated inverted if ( flipdir) rx_override[flipindex] = (float) FLIP_RATE / (float) MAX_RATE; else rx_override[flipindex] = (float)- FLIP_RATE / (float) MAX_RATE; rx_override[3] = THROTTLE_HOVER; flipstage = STAGE_FLIP_ROTATING_INVERTED; } flipstage = STAGE_FLIP_THROTTLEUP; break; case STAGE_FLIP_THROTTLEUP: if ( gettime() - fliptime > THROTTLE_UP_TIME ) { if ( flipdir) rx_override[flipindex] = (float) FLIP_RATE / (float) MAX_RATE; else rx_override[flipindex] = (float)- FLIP_RATE / (float) MAX_RATE; rx_override[3] = THROTTLE_UP; flipstage = STAGE_FLIP_ROTATING; } break; case STAGE_FLIP_ROTATING: if ( gettime() - fliptime > FLIP_TIMEOUT_STAGE1 + THROTTLE_UP_TIME ) { // abort flipstage = STAGE_FLIP_EXIT; } if ( GEstG[2] < 0 ) { //we are inverted rx_override[3] = THROTTLE_HOVER; flipstage = STAGE_FLIP_ROTATING_INVERTED; } break; case STAGE_FLIP_ROTATING_INVERTED: if ( GEstG[2] > 200 ) { //we no longer inverted levelmodetime = gettime(); rx_override[3] = THROTTLE_EXIT; acro_override = 0; level_override = 1; flipstage = STAGE_FLIP_LEVELMODE; } break; case STAGE_FLIP_LEVELMODE: // allow control in other axis at this point rx_override[0] = rx[0]; rx_override[1] = rx[1]; rx_override[2] = rx[2]; if ( flipdir ) rx_override[flipindex] = (float) LEVEL_MODE_ANGLE / (float) MAX_ANGLE_HI; else rx_override[flipindex] = (float) - LEVEL_MODE_ANGLE / (float) MAX_ANGLE_HI; aierror[flipindex] = 0.0f; // reset integral term if( gettime() - levelmodetime > LEVEL_MODE_TIME ) flipstage = STAGE_FLIP_EXIT; break; case STAGE_FLIP_EXIT: isflipping = 0; flipstage = STAGE_FLIP_NONE; acro_override = 0; level_override = 0; controls_override = 0; break; default: flipstage = STAGE_FLIP_EXIT; break; } }
bool http_request (const char *url, const u32 max_size) { int linecount; if (!http_split_url(&http_host, &http_path, url)) return false; http_port = 80; http_max_size = max_size; http_status = 404; content_length = 0; http_data = NULL; int s = tcp_connect (http_host, http_port); // printf("tcp_connect(%s, %hu) = %d\n", http_host, http_port, s); if (s < 0) { result = HTTPR_ERR_CONNECT; return false; } char *request = (char *) memalign (32, 1024); char *r = request; r += sprintf (r, "GET %s HTTP/1.1\r\n", http_path); r += sprintf (r, "Host: %s\r\n", http_host); r += sprintf (r, "Cache-Control: no-cache\r\n\r\n"); // printf("request = %s\n", request); bool b = tcp_write (s, (u8 *) request, strlen (request)); // printf("tcp_write returned %d\n", b); free (request); linecount = 0; for (linecount=0; linecount < 32; linecount++) { char *line = tcp_readln (s, 0xff, gettime(), (u16)HTTP_TIMEOUT); // printf("tcp_readln returned %p (%s)\n", line, line?line:"(null)"); if (!line) { http_status = 404; result = HTTPR_ERR_REQUEST; break; } if (strlen (line) < 1) { free (line); line = NULL; break; } sscanf (line, "HTTP/1.%*u %u", &http_status); sscanf (line, "Content-Length: %u", &content_length); free (line); line = NULL; } // printf("content_length = %d, status = %d, linecount = %d\n", content_length, http_status, linecount); if (linecount == 32 || !content_length) http_status = 404; if (http_status != 200) { result = HTTPR_ERR_STATUS; net_close (s); return false; } if (content_length > http_max_size) { result = HTTPR_ERR_TOOBIG; net_close (s); return false; } http_data = (u8 *) memalign (32, content_length); b = tcp_read (s, &http_data, content_length); if (!b) { free (http_data); http_data = NULL; result = HTTPR_ERR_RECEIVE; net_close (s); return false; } result = HTTPR_OK; net_close (s); return true; }
int main() { struct viv_conn *conn = 0; int rv; rv = viv_open(VIV_HW_3D, &conn); if(rv!=0) { fprintf(stderr, "Error opening device\n"); exit(1); } uint32_t num_profile_counters = viv_get_num_profile_counters(); /* XXX parameter parsing */ int samples_per_second = 100; bool interactive = true; int mode = MODE_ALL; //int mode = MODE_SORTED; bool color = true; uint32_t *counter_data = calloc(num_profile_counters, 4); uint32_t *counter_data_last = calloc(num_profile_counters, 4); uint64_t *events_per_s = calloc(num_profile_counters, 8); struct counter_rec *sorted = calloc(num_profile_counters, sizeof(struct counter_rec)); /* reset counters and initial values */ if(viv_read_profile_counters_3d(conn, counter_data_last) != 0) { fprintf(stderr, "Error querying counters (probably unsupported with this kernel, or not built into libetnaviv)\n"); exit(1); } uint32_t begin_time = gettime(); useconds_t interval = 1000000 / samples_per_second; while(true) { /* Scale counters by real elapsed time */ for(int c=0; c<num_profile_counters; ++c) { events_per_s[c] = 0; } for(int sample=0; sample<samples_per_second; ++sample) { if(viv_read_profile_counters_3d(conn, counter_data) != 0) { fprintf(stderr, "Error querying counters (probably unsupported with this kernel, or not built into libetnaviv)\n"); exit(1); } for(int c=0; c<num_profile_counters; ++c) { /* some counters don't reset when read */ if(c == VIV_PROF_PS_INST_COUNTER || c == VIV_PROF_VS_INST_COUNTER || c == VIV_PROF_RENDERED_PIXEL_COUNTER || c == VIV_PROF_RENDERED_VERTICE_COUNTER || c == VIV_PROF_PXL_TEXLD_INST_COUNTER || c == VIV_PROF_PXL_BRANCH_INST_COUNTER || c == VIV_PROF_VTX_TEXLD_INST_COUNTER || c == VIV_PROF_VTX_BRANCH_INST_COUNTER || c == VIV_PROF_SE_CULLED_TRIANGLE_COUNT || c == VIV_PROF_SE_CULLED_LINES_COUNT) events_per_s[c] += counter_data[c] - counter_data_last[c]; else events_per_s[c] += counter_data[c]; } for(int c=0; c<num_profile_counters; ++c) counter_data_last[c] = counter_data[c]; usleep(interval); } uint32_t end_time = gettime(); uint32_t diff_time = end_time - begin_time; /* Scale counters by real elapsed time */ for(int c=0; c<num_profile_counters; ++c) { events_per_s[c] = events_per_s[c] * 1000000LL / (uint64_t)diff_time; } /* Sort counters descending */ for(int c=0; c<num_profile_counters; ++c) { sorted[c].id = c; sorted[c].events_per_s = events_per_s[c]; } qsort(sorted, num_profile_counters, sizeof(struct counter_rec), &counter_rec_compar); if(interactive) { int line = 0; /* current screen line */ printf("%s", clear_screen); int max_lines = get_screen_lines() - line - 1; if(mode == MODE_SORTED) { int count = (num_profile_counters > max_lines) ? max_lines : num_profile_counters; for(int c=0; c<count; ++c) { char num[100]; struct viv_profile_counter_info *info = viv_get_profile_counter_info(sorted[c].id); format_number(num, sizeof(num), sorted[c].events_per_s); if(color) printf("%s", sorted[c].events_per_s == 0 ? color_num_zero : color_num); printf("%15.15s", num); if(color) printf("%s", color_reset); printf(" "); printf("%-30.30s", info->name); printf("\n"); } } else if(mode == MODE_ALL) { /* XXX check that width doesn't exceed screen width */ for(int l=0; l<max_lines; ++l) { int c = VIV_PROF_GPU_CYCLES_COUNTER + l; while(c < num_profile_counters) { char num[100]; struct viv_profile_counter_info *info = viv_get_profile_counter_info(c); format_number(num, sizeof(num), events_per_s[c]); if(color) printf("%s", events_per_s[c] == 0 ? color_num_zero : color_num); printf("%15.15s", num); if(color) printf("%s", color_reset); printf(" "); printf("%-30.30s", info->name); printf(" "); c += max_lines; } printf("\n"); } } } begin_time = end_time; } /* * XXX define new mode MODE_OCCUPANCY and some derived percentage bars: * - [PA] Number of primitives per vertex (max 1) * - [PA] % of primitives culled * - VS -> PA -> SE -> RA primitives/vertices in each stage * - RA -> PS -> PE pixels/quads in each stage * - Pixels per PS inst * - Vertices per VS inst * - % of texture requests trilinear/bilinear * - overdraw (killed by depth) */ return 0; }
int main (int argc, const char * argv[]) { // get start time double t = gettime(); // Display each command-line argument. // show_args(argc, argv); if (argc <= 1) { fprintf(stderr, "sw <seqfile> [threads]\n"); exit(1); } // get number of threads (default is 1) // and set that number for OpenMP int num_threads = 1; if (argc == 3) { num_threads = atoi(argv[2]); } omp_set_num_threads(num_threads); fprintf(stderr, "running with %d threads\n", omp_get_max_threads() ); // open file and initialize vars FILE *file; char lineAs[num_threads][MAXLINELEN]; char lineBs[num_threads][MAXLINELEN]; file = fopen(argv[1], "r"); if (file == NULL) { perror ("Error reading file"); exit(1); } int c = 0; while (!feof(file)) { // grab two lines and store them in our line arrays A & B char lineA [MAXLINELEN]; char lineB [MAXLINELEN]; fgets(lineA, MAXLINELEN, file); fgets(lineB, MAXLINELEN, file); chomp(lineA); chomp(lineB); strcpy(lineAs[c], lineA); strcpy(lineBs[c], lineB); // fprintf(stderr, "c = %d\n", c); // fire off a batch if (c != 0 && c % (num_threads-1) == 0) { int job_num; // each loop is one alignment (2 lines) #pragma omp parallel for for (job_num = 0; job_num < num_threads; job_num++) { char line1 [MAXLINELEN]; char line2 [MAXLINELEN]; strcpy(line1, lineAs[job_num]); strcpy(line2, lineBs[job_num]); // fprintf(stderr, "thread %d got job %d\n", omp_get_thread_num(), job_num); // fprintf(stderr, "thread %d got job %d and seq %s\n", omp_get_thread_num(), job_num, line1); do_alignment(line1, line2); } c=0; } else { c++; } } fclose(file); // get and print elapsed time t = gettime() - t; printf("elapsed time: %f secs\n", t); return 0; }
static void measure_init (void) { # define N 100 # define M 10 /* must be at least 2 to get steady-state */ double stop, start, get_cold, get_warm, init_cold, init_warm, delta; struct { unw_cursor_t c; char padding[1024]; /* should be > 2 * max. cacheline size */ } cursor[N]; struct { unw_context_t uc; char padding[1024]; /* should be > 2 * max. cacheline size */ } uc[N]; int i, j; /* Run each test M times and take the minimum to filter out noise such dynamic linker resolving overhead, context-switches, page-in, cache, and TLB effects. */ get_cold = 1e99; for (j = 0; j < M; ++j) { dummy += sum (big, sizeof (big)); /* flush the cache */ for (i = 0; i < N; ++i) uc[i].padding[511] = i; /* warm up the TLB */ start = gettime (); for (i = 0; i < N; ++i) unw_getcontext (&uc[i].uc); stop = gettime (); delta = (stop - start) / N; if (delta < get_cold) get_cold = delta; } init_cold = 1e99; for (j = 0; j < M; ++j) { dummy += sum (big, sizeof (big)); /* flush cache */ for (i = 0; i < N; ++i) uc[i].padding[511] = i; /* warm up the TLB */ start = gettime (); for (i = 0; i < N; ++i) unw_init_local (&cursor[i].c, &uc[i].uc); stop = gettime (); delta = (stop - start) / N; if (delta < init_cold) init_cold = delta; } get_warm = 1e99; for (j = 0; j < M; ++j) { start = gettime (); for (i = 0; i < N; ++i) unw_getcontext (&uc[0].uc); stop = gettime (); delta = (stop - start) / N; if (delta < get_warm) get_warm = delta; } init_warm = 1e99; for (j = 0; j < M; ++j) { start = gettime (); for (i = 0; i < N; ++i) unw_init_local (&cursor[0].c, &uc[0].uc); stop = gettime (); delta = (stop - start) / N; if (delta < init_warm) init_warm = delta; } printf ("unw_getcontext : cold avg=%9.3f nsec, warm avg=%9.3f nsec\n", 1e9 * get_cold, 1e9 * get_warm); printf ("unw_init_local : cold avg=%9.3f nsec, warm avg=%9.3f nsec\n", 1e9 * init_cold, 1e9 * init_warm); }
double *synt_noise(double **d, int32_t Xsize, int32_t bands, int32_t *samplecount, int32_t samplerate, double basefreq, double pixpersec, double bpo) { int32_t i; // general purpose iterator int32_t ib; // bands iterator int32_t il; // loop iterator double *s; // final signal double coef; double *noise; // filtered looped noise double loop_size_sec=LOOP_SIZE_SEC; // size of the filter bank loop, in seconds. Later to be taken from user input int32_t loop_size; // size of the filter bank loop, in samples. Deduced from loop_size_sec int32_t loop_size_min; // minimum required size for the filter bank loop, in samples. Calculated from the longest windowed sinc's length double *pink_noise; // original pink noise (in the frequency domain) double mag, phase; // parameters for the creation of pink_noise's samples double *envelope; // interpolated envelope double *lut; // Blackman Sqaure look-up table double *freq; // frequency look-up table double maxfreq; // central frequency of the last band int32_t Fa; // Fa is the index of the band's start in the frequency domain int32_t Fd; // Fd is the index of the band's end in the frequency domain double La; // La is the log2 of the frequency of Fa double Ld; // Ld is the log2 of the frequency of Fd double Li; // Li is the iterative frequency between La and Ld defined logarithmically freq = freqarray(basefreq, bands, bpo); if (LOGBASE==1.0) maxfreq = bpo; // in linear mode we use bpo to store the maxfreq since we couldn't deduce maxfreq otherwise else maxfreq = basefreq * pow(LOGBASE, ((double) (bands-1)/ bpo)); clocka=gettime(); *samplecount = roundoff(Xsize/pixpersec); // calculation of the length of the final signal printf("Sound duration : %.3f s\n", (double) *samplecount/samplerate); s = calloc (*samplecount, sizeof(double)); // allocation of the final signal envelope = calloc (*samplecount, sizeof(double)); // allocation of the interpolated envelope //********Loop size calculation******** loop_size = loop_size_sec * samplerate; if (LOGBASE==1.0) loop_size_min = (int32_t) roundoff(4.0*5.0/ freq[1]-freq[0]); // linear mode else loop_size_min = (int32_t) roundoff(2.0*5.0/((freq[0] * pow(2.0, -1.0/(bpo))) * (1.0 - pow(2.0, -1.0 / bpo)))); // this is the estimate of how many samples the longest FIR will take up in the time domain if (loop_size_min > loop_size) loop_size = loop_size_min; loop_size = nextsprime(loop_size); // enlarge the loop_size to the next multiple of short primes in order to make IFFTs faster //--------Loop size calculation-------- //********Pink noise generation******** pink_noise = calloc (loop_size, sizeof(double)); for (i=1; i<(loop_size+1)>>1; i++) { mag = pow((double) i, 0.5 - 0.5*LOGBASE); // FIXME something's not necessarily right with that formula phase = dblrand() * pi; // random phase between -pi and +pi pink_noise[i]= mag * cos(phase); // real part pink_noise[loop_size-i]= mag * sin(phase); // imaginary part } //--------Pink noise generation-------- noise = malloc(loop_size * sizeof(double)); // allocate noise lut = bmsq_lut(BMSQ_LUT_SIZE); // Blackman Square look-up table initalisation for (ib=0; ib<bands; ib++) { printf("%4d/%d\r", ib+1, bands); memset(noise, 0, loop_size * sizeof(double)); // reset filtered noise //********Filtering******** Fa = roundoff(log_pos((double) (ib-1)/(double) (bands-1), basefreq, maxfreq) * loop_size); Fd = roundoff(log_pos((double) (ib+1)/(double) (bands-1), basefreq, maxfreq) * loop_size); La = log_pos_inv((double) Fa / (double) loop_size, basefreq, maxfreq); Ld = log_pos_inv((double) Fd / (double) loop_size, basefreq, maxfreq); if (Fd > loop_size/2) Fd = loop_size/2; // stop reading if reaching the Nyquist frequency if (Fa<1) Fa=1; printf("%4d/%d %.2f Hz - %.2f Hz\r", ib+1, bands, (double) Fa*samplerate/loop_size, (double) Fd*samplerate/loop_size); for (i=Fa; i<Fd; i++) { Li = log_pos_inv((double) i / (double) loop_size, basefreq, maxfreq); // calculation of the logarithmic position Li = (Li-La)/(Ld-La); coef = 0.5 - 0.5*cos(2.0*pi*Li); // Hann function noise[i+1] = pink_noise[i+1] * coef; noise[loop_size-1-i] = pink_noise[loop_size-1-i] * coef; } //--------Filtering-------- fft(noise, noise, loop_size, 1); // IFFT of the filtered noise memset(envelope, 0, *samplecount * sizeof(double)); // blank the envelope blackman_square_interpolation(d[bands-ib-1], envelope, Xsize, *samplecount, lut, BMSQ_LUT_SIZE); // interpolation of the envelope il = 0; for (i=0; i<*samplecount; i++) { s[i] += envelope[i] * noise[il]; // modulation il++; // increment loop iterator if (il==loop_size) // if the array iterator has reached the end of the array, it's reset il=0; } } printf("\n"); normi(&s, *samplecount, 1, 1.0); return s; }
/* function TIMESINCE returns the time elapsed from parameter redshift zsource to parameter redshift z */ double timesince(double z, double zsource){ if (z > zsource){printf("Invalid usage of TIMESINCE. Z must be <= Zsource."); return 0;} else if ((zsource-z) < TINY){ return 0;} return (gettime(z) - gettime(zsource)); }
int main (int argc, char *argv[]) { double t, tv[2]; int reps = 10000; int doprint = 0; char *progName; int minWords = 1; int maxWords = 1; int incWords; int nwords; int nproc; int proc; int peer; int c; int r; int i; long *rbuf; long *tbuf; start_pes (0); proc = _my_pe (); nproc = _num_pes (); for (progName = argv[0] + strlen (argv[0]); progName > argv[0] && *(progName - 1) != '/'; progName--) ; while ((c = getopt (argc, argv, "n:eh")) != -1) switch (c) { case 'n': if ((reps = getSize (optarg)) <= 0) usage (progName); break; case 'e': doprint++; break; case 'h': help (progName); default: usage (progName); } if (optind == argc) minWords = 1; else if ((minWords = getSize (argv[optind++])) <= 0) usage (progName); if (optind == argc) maxWords = minWords; else if ((maxWords = getSize (argv[optind++])) < minWords) usage (progName); if (optind == argc) incWords = 0; else if ((incWords = getSize (argv[optind++])) < 0) usage (progName); if (!(rbuf = (long *) shmalloc (maxWords * sizeof (long)))) { perror ("Failed memory allocation"); exit (1); } memset (rbuf, 0, maxWords * sizeof (long)); shmem_barrier_all (); if (!(tbuf = (long *) malloc (maxWords * sizeof (long)))) { perror ("Failed memory allocation"); exit (1); } if (nproc == 1) return 0; for (i = 0; i < maxWords; i++) tbuf[i] = 1000 + (i & 255); if (doprint) printf ("%d(%d): Shmem PING reps %d minWords %d maxWords %d incWords %d\n", proc, nproc, reps, minWords, maxWords, incWords); shmem_barrier_all (); peer = proc ^ 1; if (peer >= nproc) doprint = 0; for (nwords = minWords; nwords <= maxWords; nwords = incWords ? nwords + incWords : nwords ? 2 * nwords : 1) { r = reps; shmem_barrier_all (); tv[0] = gettime (); if (peer < nproc) { if (proc & 1) { r--; shmem_wait (&rbuf[nwords - 1], 0); rbuf[nwords - 1] = 0; } while (r-- > 0) { shmem_long_put (rbuf, tbuf, nwords, peer); shmem_wait (&rbuf[nwords - 1], 0); rbuf[nwords - 1] = 0; } if (proc & 1) shmem_long_put (rbuf, tbuf, nwords, peer); } tv[1] = gettime (); t = dt (&tv[1], &tv[0]) / (2 * reps); shmem_barrier_all (); printStats (proc, peer, doprint, nwords, t); } shmem_barrier_all (); free (tbuf); shfree (rbuf); return 0; }
void tic () { g_fTimeStart = gettime (); g_tickStart = getticks (); }
irc_t *irc_new( int fd ) { irc_t *irc; struct sockaddr_storage sock; socklen_t socklen = sizeof( sock ); char *host = NULL, *myhost = NULL; irc_user_t *iu; GSList *l; set_t *s; bee_t *b; irc = g_new0( irc_t, 1 ); irc->fd = fd; sock_make_nonblocking( irc->fd ); irc->r_watch_source_id = b_input_add( irc->fd, B_EV_IO_READ, bitlbee_io_current_client_read, irc ); irc->status = USTATUS_OFFLINE; irc->last_pong = gettime(); irc->nick_user_hash = g_hash_table_new( g_str_hash, g_str_equal ); irc->watches = g_hash_table_new( g_str_hash, g_str_equal ); irc->iconv = (GIConv) -1; irc->oconv = (GIConv) -1; if( global.conf->hostname ) { myhost = g_strdup( global.conf->hostname ); } else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 ) { char buf[NI_MAXHOST+1]; if( getnameinfo( (struct sockaddr *) &sock, socklen, buf, NI_MAXHOST, NULL, 0, 0 ) == 0 ) { myhost = g_strdup( ipv6_unwrap( buf ) ); } } if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 ) { char buf[NI_MAXHOST+1]; if( getnameinfo( (struct sockaddr *)&sock, socklen, buf, NI_MAXHOST, NULL, 0, 0 ) == 0 ) { host = g_strdup( ipv6_unwrap( buf ) ); } } if( host == NULL ) host = g_strdup( "localhost.localdomain" ); if( myhost == NULL ) myhost = g_strdup( "localhost.localdomain" ); if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 ) irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc ); irc_connection_list = g_slist_append( irc_connection_list, irc ); b = irc->b = bee_new(); b->ui_data = irc; b->ui = &irc_ui_funcs; s = set_add( &b->set, "allow_takeover", "true", set_eval_bool, irc ); s = set_add( &b->set, "away_devoice", "true", set_eval_bw_compat, irc ); s->flags |= SET_HIDDEN; s = set_add( &b->set, "away_reply_timeout", "3600", set_eval_int, irc ); s = set_add( &b->set, "charset", "utf-8", set_eval_charset, irc ); s = set_add( &b->set, "default_target", "root", NULL, irc ); s = set_add( &b->set, "display_namechanges", "false", set_eval_bool, irc ); s = set_add( &b->set, "display_timestamps", "true", set_eval_bool, irc ); s = set_add( &b->set, "handle_unknown", "add_channel", NULL, irc ); s = set_add( &b->set, "last_version", "0", NULL, irc ); s->flags |= SET_HIDDEN; s = set_add( &b->set, "lcnicks", "true", set_eval_bool, irc ); s = set_add( &b->set, "nick_format", "%-@nick", NULL, irc ); s = set_add( &b->set, "offline_user_quits", "true", set_eval_bool, irc ); s = set_add( &b->set, "ops", "both", set_eval_irc_channel_ops, irc ); s = set_add( &b->set, "paste_buffer", "false", set_eval_bool, irc ); s->old_key = g_strdup( "buddy_sendbuffer" ); s = set_add( &b->set, "paste_buffer_delay", "200", set_eval_int, irc ); s->old_key = g_strdup( "buddy_sendbuffer_delay" ); s = set_add( &b->set, "password", NULL, set_eval_password, irc ); s->flags |= SET_NULL_OK | SET_PASSWORD; s = set_add( &b->set, "private", "true", set_eval_bool, irc ); s = set_add( &b->set, "query_order", "lifo", NULL, irc ); s = set_add( &b->set, "root_nick", ROOT_NICK, set_eval_root_nick, irc ); s->flags |= SET_HIDDEN; s = set_add( &b->set, "show_offline", "false", set_eval_bw_compat, irc ); s->flags |= SET_HIDDEN; s = set_add( &b->set, "simulate_netsplit", "true", set_eval_bool, irc ); s = set_add( &b->set, "timezone", "local", set_eval_timezone, irc ); s = set_add( &b->set, "to_char", ": ", set_eval_to_char, irc ); s = set_add( &b->set, "typing_notice", "false", set_eval_bool, irc ); irc->root = iu = irc_user_new( irc, ROOT_NICK ); iu->host = g_strdup( myhost ); iu->fullname = g_strdup( ROOT_FN ); iu->f = &irc_user_root_funcs; iu = irc_user_new( irc, NS_NICK ); iu->host = g_strdup( myhost ); iu->fullname = g_strdup( ROOT_FN ); iu->f = &irc_user_root_funcs; irc->user = g_new0( irc_user_t, 1 ); irc->user->host = g_strdup( host ); conf_loaddefaults( irc ); /* Evaluator sets the iconv/oconv structures. */ set_eval_charset( set_find( &b->set, "charset" ), set_getstr( &b->set, "charset" ) ); irc_write( irc, ":%s NOTICE AUTH :%s", irc->root->host, "BitlBee-IRCd initialized, please go on" ); if( isatty( irc->fd ) ) irc_write( irc, ":%s NOTICE AUTH :%s", irc->root->host, "If you read this, you most likely accidentally " "started BitlBee in inetd mode on the command line. " "You probably want to run it in (Fork)Daemon mode. " "See doc/README for more information." ); g_free( myhost ); g_free( host ); /* libpurple doesn't like fork()s after initializing itself, so this is the right moment to initialize it. */ #ifdef WITH_PURPLE nogaim_init(); #endif for( l = irc_plugins; l; l = l->next ) { irc_plugin_t *p = l->data; if( p->irc_new ) p->irc_new( irc ); } return irc; }
int main( int argc, char argv[] ) { unsigned int i; timing_t t_start, t_stop, t_gen, t_sort, t_merge, t_check; printf( "-------------------------------------------------------\n" "ReconOS hardware multithreading case study (sort)\n" "(c) Computer Engineering Group, University of Paderborn\n\n" "Standalone, single-threaded software version (" __FILE__ ")\n" "Compiled on " __DATE__ ", " __TIME__ ".\n" "-------------------------------------------------------\n\n" ); data = buf_a; //---------------------------------- //-- GENERATE DATA //---------------------------------- printf( "Generating data..." ); t_start = gettime( ); generate_data( data, SIZE ); t_stop = gettime( ); t_gen = calc_timediff_ms( t_start, t_stop ); printf( "done\n" ); //---------------------------------- //-- SORT DATA //---------------------------------- printf( "Sorting data..." ); t_start = gettime( ); for ( i = 0; i < SIZE; i += N ) { bubblesort( &data[i], N ); } t_stop = gettime( ); t_sort = calc_timediff_ms( t_start, t_stop ); printf( "done\n" ); //---------------------------------- //-- MERGE DATA //---------------------------------- printf( "Merging data..." ); t_start = gettime( ); data = recursive_merge( data, buf_b, SIZE, N, simple_merge ); t_stop = gettime( ); t_merge = calc_timediff_ms( t_start, t_stop ); printf( "done\n" ); //---------------------------------- //-- CHECK DATA //---------------------------------- printf( "Checking sorted data..." ); t_start = gettime( ); if ( check_data( data, SIZE ) != 0 ) printf( "CHECK FAILED!\n" ); else printf( "check successful.\n" ); t_stop = gettime( ); t_check = calc_timediff_ms( t_start, t_stop ); printf( "\nRunning times (size: %d words):\n" "\tGenerate data: %d ms\n" "\tSort data : %d ms\n" "\tMerge data : %d ms\n" "\tCheck data : %d ms\n" "\nTotal computation time (sort & merge): %d ms\n", SIZE, t_gen, t_sort, t_merge, t_check, t_sort + t_merge ); }
int main(int argc, char **argv) { int fd_count = 0; struct pollfd ufds[4]; char *tmpdev; char* debuggable; char tmp[32]; int property_set_fd_init = 0; int signal_fd_init = 0; int keychord_fd_init = 0; bool is_charger = false; if (!strcmp(basename(argv[0]), "ueventd")) return ueventd_main(argc, argv); if (!strcmp(basename(argv[0]), "watchdogd")) return watchdogd_main(argc, argv); /* clear the umask */ umask(0); /* Get the basic filesystem setup we need put * together in the initramdisk on / and then we'll * let the rc file figure out the rest. */ mkdir("/dev", 0755); mkdir("/proc", 0755); mkdir("/sys", 0755); mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755"); mkdir("/dev/pts", 0755); mkdir("/dev/socket", 0755); mount("devpts", "/dev/pts", "devpts", 0, NULL); mount("proc", "/proc", "proc", 0, NULL); mount("sysfs", "/sys", "sysfs", 0, NULL); /* indicate that booting is in progress to background fw loaders, etc */ close(open("/dev/.booting", O_WRONLY | O_CREAT, 0000)); /* We must have some place other than / to create the * device nodes for kmsg and null, otherwise we won't * be able to remount / read-only later on. * Now that tmpfs is mounted on /dev, we can actually * talk to the outside world. */ open_devnull_stdio(); klog_init(); property_init(); get_hardware_name(hardware, &revision); process_kernel_cmdline(); union selinux_callback cb; cb.func_log = klog_write; selinux_set_callback(SELINUX_CB_LOG, cb); cb.func_audit = audit_callback; selinux_set_callback(SELINUX_CB_AUDIT, cb); selinux_initialize(); /* These directories were necessarily created before initial policy load * and therefore need their security context restored to the proper value. * This must happen before /dev is populated by ueventd. */ restorecon("/dev"); restorecon("/dev/socket"); restorecon("/dev/__properties__"); restorecon_recursive("/sys"); is_charger = !strcmp(bootmode, "charger"); INFO("property init\n"); if (!is_charger) property_load_boot_defaults(); INFO("reading config file\n"); init_parse_config_file("/init.rc"); action_for_each_trigger("early-init", action_add_queue_tail); queue_builtin_action(wait_for_coldboot_done_action, "wait_for_coldboot_done"); queue_builtin_action(mix_hwrng_into_linux_rng_action, "mix_hwrng_into_linux_rng"); queue_builtin_action(keychord_init_action, "keychord_init"); queue_builtin_action(console_init_action, "console_init"); /* execute all the boot actions to get us started */ action_for_each_trigger("init", action_add_queue_tail); /* skip mounting filesystems in charger mode */ if (!is_charger) { action_for_each_trigger("early-fs", action_add_queue_tail); action_for_each_trigger("fs", action_add_queue_tail); action_for_each_trigger("post-fs", action_add_queue_tail); action_for_each_trigger("post-fs-data", action_add_queue_tail); } /* Repeat mix_hwrng_into_linux_rng in case /dev/hw_random or /dev/random * wasn't ready immediately after wait_for_coldboot_done */ queue_builtin_action(mix_hwrng_into_linux_rng_action, "mix_hwrng_into_linux_rng"); queue_builtin_action(property_service_init_action, "property_service_init"); queue_builtin_action(signal_init_action, "signal_init"); queue_builtin_action(check_startup_action, "check_startup"); if (is_charger) { action_for_each_trigger("charger", action_add_queue_tail); } else { action_for_each_trigger("early-boot", action_add_queue_tail); action_for_each_trigger("boot", action_add_queue_tail); } /* run all property triggers based on current state of the properties */ queue_builtin_action(queue_property_triggers_action, "queue_property_triggers"); #if BOOTCHART queue_builtin_action(bootchart_init_action, "bootchart_init"); #endif for(;;) { int nr, i, timeout = -1; execute_one_command(); restart_processes(); if (!property_set_fd_init && get_property_set_fd() > 0) { ufds[fd_count].fd = get_property_set_fd(); ufds[fd_count].events = POLLIN; ufds[fd_count].revents = 0; fd_count++; property_set_fd_init = 1; } if (!signal_fd_init && get_signal_fd() > 0) { ufds[fd_count].fd = get_signal_fd(); ufds[fd_count].events = POLLIN; ufds[fd_count].revents = 0; fd_count++; signal_fd_init = 1; } if (!keychord_fd_init && get_keychord_fd() > 0) { ufds[fd_count].fd = get_keychord_fd(); ufds[fd_count].events = POLLIN; ufds[fd_count].revents = 0; fd_count++; keychord_fd_init = 1; } if (process_needs_restart) { timeout = (process_needs_restart - gettime()) * 1000; if (timeout < 0) timeout = 0; } if (!action_queue_empty() || cur_action) timeout = 0; #if BOOTCHART if (bootchart_count > 0) { if (timeout < 0 || timeout > BOOTCHART_POLLING_MS) timeout = BOOTCHART_POLLING_MS; if (bootchart_step() < 0 || --bootchart_count == 0) { bootchart_finish(); bootchart_count = 0; } } #endif nr = poll(ufds, fd_count, timeout); if (nr <= 0) continue; for (i = 0; i < fd_count; i++) { if (ufds[i].revents & POLLIN) { if (ufds[i].fd == get_property_set_fd()) handle_property_set_fd(); else if (ufds[i].fd == get_keychord_fd()) handle_keychord(); else if (ufds[i].fd == get_signal_fd()) handle_signal(); } } } return 0; }
int main( int argc, char *argv[] ) { unsigned int i, start_count = 0, done_count = 0, j; timing_t t_start = 0, t_stop = 0, t_gen = 0, t_sort = 0, t_merge = 0, t_check = 0, t_tmp; printf( "-------------------------------------------------------\n" "ReconOS hardware multithreading case study (sort)\n" "(c) Computer Engineering Group, University of Paderborn\n\n" "eCos, single-threaded hardware version (" __FILE__ ")\n" "Compiled on " __DATE__ ", " __TIME__ ".\n" "-------------------------------------------------------\n\n" ); #ifdef USE_CACHE printf( "enabling data cache for external ram\n" ); XCache_EnableDCache( 0x80000000 ); #else printf( "data cache disabled\n" ); XCache_DisableDCache( ); #endif data = buf_a; //---------------------------------- //-- GENERATE DATA //---------------------------------- printf( "Generating data..." ); t_start = gettime( ); generate_data( data, SIZE ); t_stop = gettime( ); t_gen = calc_timediff_ms( t_start, t_stop ); printf( "done\n" ); #ifdef USE_CACHE // flush cache contents - the hardware can only read from main memory // TODO: storing could be more efficient printf( "Flushing cache..." ); XCache_EnableDCache( 0x80000000 ); printf( "done\n" ); #endif //---------------------------------- //-- SORT DATA //---------------------------------- // create mail boxes for 'start' and 'complete' messages cyg_mbox_create( &mb_start_handle, &mb_start ); cyg_mbox_create( &mb_done_handle, &mb_done ); // create sorting thread reconos_hwthread_create( 16, // priority 0, // entry data (not needed) "MT_HW_SORT", // thread name hwthread_sorter_stack, // stack STACK_SIZE, // stack size &hwthread_sorter_handle, // thread handle &hwthread_sorter, // thread object (void*)UPBHWR_OSIF_0_BASEADDR, XPAR_OPB_INTC_0_OSIF_0_INTERRUPT_INTR+1, // ( void * ) XPAR_PLB_RECONOS_SLOT_0_BASEADDR, // base address // XPAR_OPB_INTC_0_PLB_RECONOS_SLOT_0_INTERRUPT_INTR + 1, // interrupt hwthread_sorter_resources, // resource array 2, // number of resources 0xFFFFFFFF, 0xFFFFFFFF ); cyg_thread_resume( hwthread_sorter_handle ); printf( "Sorting data..." ); i = 0; while ( done_count < SIZE / N ) { t_start = gettime( ); // if we have something to distribute, // put as many as possile into the start mailbox while ( start_count < SIZE / N ) { if ( cyg_mbox_tryput( mb_start_handle, ( void * ) &data[i] ) == true ) { start_count++; i += N; } else { // mailbox full break; } } t_stop = gettime( ); t_sort += calc_timediff_ms( t_start, t_stop ); // see whether anybody's done t_start = gettime( ); if ( ( t_tmp = ( timing_t ) cyg_mbox_get( mb_done_handle ) ) != 0 ) { done_count++; } else { printf( "cyg_mbox_get returned NULL!\n" ); } t_stop = gettime( ); t_sort += calc_timediff_ms( t_start, t_stop ); } printf( "done\n" ); #ifdef USE_CACHE // flush cache contents // TODO: invalidating would suffice printf( "Flushing cache..." ); XCache_EnableDCache( 0x80000000 ); printf( "done\n" ); #endif //---------------------------------- //-- MERGE DATA //---------------------------------- printf( "Merging data..." ); t_start = gettime( ); data = recursive_merge( data, buf_b, SIZE, N, simple_merge ); t_stop = gettime( ); t_merge = calc_timediff_ms( t_start, t_stop ); printf( "done\n" ); //---------------------------------- //-- CHECK DATA //---------------------------------- printf( "Checking sorted data..." ); t_start = gettime( ); if ( check_data( data, SIZE ) != 0 ) printf( "CHECK FAILED!\n" ); else printf( "check successful.\n" ); t_stop = gettime( ); t_check = calc_timediff_ms( t_start, t_stop ); printf( "\nRunning times (size: %d words):\n" "\tGenerate data: %d ms\n" "\tSort data : %d ms\n" "\tMerge data : %d ms\n" "\tCheck data : %d ms\n" "\nTotal computation time (sort & merge): %d ms\n", SIZE, t_gen, t_sort, t_merge, t_check, t_sort + t_merge ); return 0; }
void start_download(const char* url, const char* saving_path, int max_count, int max_speed, int taskId) { DebugMsg("start_download: %s %s", url, saving_path); char fn[MAX_STRING] = ""; int do_search = 0; search_t *search; conf_t conf[1]; axel_t *axel; int i, j, cur_head = 0; char *s; if( !conf_init( conf ) ) { return; } // strncpy( conf->user_agent, optarg, MAX_STRING); case 'U': // strncpy( conf->add_header[cur_head++], optarg, MAX_STRING ); case 'H': if (max_speed > 0) { conf->max_speed = max_speed; // 限速,指定每秒下载最大byte } // conf->num_connections = 10; // 指定同时打开的线程数 // strncpy( fn, optarg, MAX_STRING ); // 指定本地输出文件 // do_search = 1; // 查找镜像 // if( optarg != NULL ) { // if( !sscanf( optarg, "%i", &conf->search_top ) ) // { // print_help(); // return( 1 ); // } // } // conf->alternate_output = 1; // 交替输出进度信息 // *conf->http_proxy = 0; // 不使用代理服务器 print_help(); // 打印帮助 print_version(); // 打印版本号 conf->verbose = 1; // 打印更多状态信息 conf->task_id = taskId; s = (char*)url; strncpy(conf->saving_path, saving_path, sizeof(conf->saving_path) - 1); conf->add_header_count = cur_head; printf( _("Initializing download: %s\n"), s ); if( do_search == 1) { search = (search_t*)malloc( sizeof( search_t ) * ( conf->search_amount + 1 ) ); memset( search, 0, sizeof( search_t ) * ( conf->search_amount + 1 ) ); search[0].conf = conf; if( conf->verbose ) printf( _("Doing search...\n") ); i = search_makelist( search, s ); if( i < 0 ) { fprintf( stderr, _("File not found\n" ) ); return; } if( conf->verbose ) printf( _("Testing speeds, this can take a while...\n") ); j = search_getspeeds( search, i ); search_sortlist( search, i ); if( conf->verbose ) { printf( _("%i usable servers found, will use these URLs:\n"), j ); j = __min( j, conf->search_top ); printf( "%-60s %15s\n", "URL", "Speed" ); for( i = 0; i < j; i ++ ) printf( "%-70.70s %5i\n", search[i].url, search[i].speed ); printf( "\n" ); } axel = axel_new( conf, j, search ); free( search ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return; } } else if (do_search == 0) { axel = axel_new( conf, 0, s ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return; } } else { // 多个url地址进行搜寻 // search = (search_t*)malloc( sizeof( search_t ) * ( argc - optind ) ); // memset( search, 0, sizeof( search_t ) * ( argc - optind ) ); // for( i = 0; i < ( argc - optind ); i ++ ) // strncpy( search[i].url, argv[optind+i], MAX_STRING ); // axel = axel_new( conf, argc - optind, search ); // free( search ); // if( axel->ready == -1 ) // { // print_messages( axel ); // axel_close( axel ); // return( 1 ); // } } print_messages( axel ); // 指定输出文件 if( *fn ) { struct stat buf; if( stat( fn, &buf ) == 0 ) { if( S_ISDIR( buf.st_mode ) ) { size_t fnlen = strlen(fn); size_t axelfnlen = strlen(axel->filename); if (fnlen + 1 + axelfnlen + 1 > MAX_STRING) { fprintf( stderr, _("Filename too long!\n")); return; } fn[fnlen] = '/'; memcpy(fn+fnlen+1, axel->filename, axelfnlen); fn[fnlen + 1 + axelfnlen] = '\0'; } } sprintf( string, "%s.st", fn ); if( access( fn, F_OK ) == 0 ) if( access( string, F_OK ) != 0 ) { fprintf( stderr, _("No state file, cannot resume!\n") ); return; } if( access( string, F_OK ) == 0 ) if( access( fn, F_OK ) != 0 ) { printf( _("State file found, but no downloaded data. Starting from scratch.\n" ) ); unlink( string ); } strcpy( axel->filename, fn ); } else { /* Local file existence check */ i = 0; s = axel->filename + strlen( axel->filename ); while( 1 ) { char szTempPath[512] = {0}; char szFilePath[512] = {0}; snprintf(szTempPath, sizeof(szTempPath) - 1, "%s/%s.st", axel->conf[0].saving_path, axel->filename); snprintf(szFilePath, sizeof(szFilePath) - 1, "%s/%s", axel->conf[0].saving_path, axel->filename); if( access(szFilePath, F_OK ) == 0 ) { if( axel->conn[0].supported ) { if( access(szTempPath, F_OK ) == 0 ) break; } } else { if( access( szTempPath, F_OK ) ) break; } sprintf( s, ".%i", i ); i ++; } } if( !axel_open( axel ) ) { print_messages( axel ); return; } print_messages( axel ); axel_start( axel ); print_messages( axel ); if( conf->alternate_output ) { putchar('\n'); } else { if( axel->bytes_done > 0 ) /* Print first dots if resuming */ { putchar( '\n' ); print_commas( axel->bytes_done ); } } axel->start_byte = axel->bytes_done; /* Install save_state signal handler for resuming support */ signal( SIGINT, stop ); signal( SIGTERM, stop ); while( !axel->ready && run ) { long long int prev, done; prev = axel->bytes_done; axel_do( axel ); update_percent(axel->conf[0].task_id, axel->size, axel->bytes_done, 1.0 * axel->bytes_done / __max(axel->size, 1), axel->bytes_per_second); if (g_verbose) { if( conf->alternate_output ) { if( !axel->message && prev != axel->bytes_done ) { print_alternate_output( axel ); } } else { /* The infamous wget-like 'interface'.. ;) */ done = ( axel->bytes_done / 1024 ) - ( prev / 1024 ); if( done && conf->verbose > -1 ) { for( i = 0; i < done; i ++ ) { i += ( prev / 1024 ); if( ( i % 50 ) == 0 ) { if( prev >= 1024 ) printf( " [%6.1fKB/s]", (double) axel->bytes_per_second / 1024 ); if( axel->size < 10240000 ) printf( "\n[%3lld%%] ", __min( 100, 102400 * i / axel->size ) ); else printf( "\n[%3lld%%] ", __min( 100, i / ( axel->size / 102400 ) ) ); } else if( ( i % 10 ) == 0 ) { putchar( ' ' ); } putchar( '.' ); i -= ( prev / 1024 ); } fflush( stdout ); } } if( axel->message ) { if(conf->alternate_output==1) { /* clreol-simulation */ putchar( '\r' ); for( i = 0; i < 79; i++ ) /* linewidth known? */ putchar( ' ' ); putchar( '\r' ); } else { putchar( '\n' ); } print_messages( axel ); if( !axel->ready ) { if(conf->alternate_output!=1) print_commas( axel->bytes_done ); else print_alternate_output(axel); } } else if( axel->ready ) { putchar( '\n' ); } } } strcpy( string + MAX_STRING / 2, size_human( axel->bytes_done - axel->start_byte ) ); printf( _("\nDownloaded %s in %s. (%.2f KB/s)\n"), string + MAX_STRING / 2, time_human( gettime() - axel->start_time ), (double) axel->bytes_per_second / 1024 ); i = axel->ready ? 0 : 2; axel_close( axel ); return; }
timer() : m_st(gettime()) {};
void handler(float time) { static float oldtime=0.0f; static float lx=0.0f,ly=0.0f; static float mx,my; static BOOLINT b1,b2,b3; static int key; int t1,t2,t3; float newtime; BOOLINT update; int hook; float over; if (!GUI_demo) { mx=getmousex(); my=getmousey(); b1=getbutton1(); b2=getbutton2(); b3=getbutton3(); key=getkey(); } else switch (key=getkey()) { case '\033': // quit application case 'q': case 'Q': case 'x': quithook(); } if (GUI_record) fprintf(GUI_recfile,"time=%g dt=%g mx=%g my=%g b1=%d b2=%d b3=%d key=%d\n", gettime()-GUI_start,time,mx,my,b1,b2,b3,(key!='D')?key:0); update=TRUE; if (GUI_demo) if (oldtime<gettime()-GUI_start) if (fscanf(GUI_recfile,"time=%g dt=%g mx=%g my=%g b1=%d b2=%d b3=%d key=%d\n", &newtime,&time,&mx,&my,&t1,&t2,&t3,&key)!=8) if (GUI_loop==0) { oldtime=newtime; GUI_demo=FALSE; b1=b2=b3=FALSE; key=0; } else { fclose(GUI_recfile); if ((GUI_recfile=fopen(RECORD,"rb"))==NULL) ERRORMSG(); oldtime=0.0f; GUI_start=gettime(); b1=b2=b3=FALSE; key=0; } else { oldtime=newtime; b1=(t1!=0); b2=(t2!=0); b3=(t3!=0); } else update=FALSE; if (update) { switch (key) { case ' ': // start/stop of flight if (EYE_SPEED==0.0f) EYE_SPEED=EYE_MAXSPEED; else stophook(); break; case 'a': // accelerate flight acchook(); break; case 's': // decelerate flight dechook(); break; case 'w': // toggle wireframe GUI_wire=!GUI_wire; break; case 'b': // toggle white background GUI_white=!GUI_white; break; case 'B': // toggle inverse mode GUI_inv=!GUI_inv; break; case 'm': // toggle premultiplied alpha GUI_premult=!GUI_premult; break; case 'i': // toggle preintegration GUI_preint=!GUI_preint; break; case 'g': // toggle 2DTF GUI_grad=!GUI_grad; reloadhook(); break; case 'l': // toggle lighting GUI_light=!GUI_light; reloadhook(); break; case 'h': // hide GUI if (GUI_capt) GUI_capt=FALSE; else GUI_hide=!GUI_hide; reloadhook(); break; case 'H': // hide GUI except TF GUI_hide=FALSE; GUI_capt=!GUI_capt; reloadhook(); break; case 'p': // toggle barycenters GUI_points=!GUI_points; break; case '+': // select higher gradients case 'A': cyclehook(); break; case '-': // select lower gradients case 'S': recyclehook(); break; case '>': // select more gradients incrangehook(); break; case '<': // select fewer gradients decrangehook(); break; case '0': // disable gradient selection VOLREN->get_tfunc()->unset_imp(); break; case '1': // enable gradient selection VOLREN->get_tfunc()->set_imp(GUI_cycle,GUI_range); break; case 'C': // toggle coupling GUI_coupled=!GUI_coupled; break; case 'W': // write .sav file savehook(); break; case 'R': // read .sav file loadhook(); break; case 'D': // toggle event recording if (!GUI_demo) { GUI_record=!GUI_record; if (GUI_record) { if ((GUI_recfile=fopen(RECORD,"wb"))==NULL) ERRORMSG(); GUI_start=gettime(); } } break; case '\033': // quit application case 'q': case 'Q': case 'x': quithook(); } if (gettime()-GUI_time>VOL_DELAY1) GUI_reduced=FALSE; if (!b1) OGL_GUI.release(mx,my); else { hook=OGL_GUI.click(mx,my); if (hook==0) if (!GUI_clip) { GUI_rotx+=mx-lx; GUI_roty-=my-ly; GUI_reduced=TRUE; } else { GUI_clip_dist-=my-ly; GUI_reduced=TRUE; } else if (hook!=GUI_hook1 && hook!=GUI_hook2 && hook!=GUI_hook3 && hook!=GUI_hook4 && hook!=GUI_hook5 && hook!=GUI_hook6 && hook!=GUI_hook7 && hook!=GUI_hook8 && hook!=GUI_hook9 && hook!=GUI_hook10 && hook!=GUI_hook11 && hook!=GUI_hook12 && hook!=GUI_hook14 && hook!=GUI_hook15 && hook!=GUI_hook16 && hook!=GUI_hook17 && hook!=GUI_hook18 && hook!=GUI_hook19 && hook!=GUI_hook20 && hook!=GUI_hook21 && hook!=GUI_hook22 && hook!=GUI_hook23 && hook!=GUI_hook24 && hook!=GUI_hook25 && hook!=GUI_hook26 && hook!=GUI_hook27 && hook!=GUI_hook28) GUI_reduced=TRUE; GUI_time=gettime(); } lx=mx; ly=my; GUI_roty=fmin(fmax(GUI_roty,-0.5f),0.5f); EYE_DX=fsin(GUI_rotx*PI)*fcos(GUI_roty*PI); EYE_DY=fsin(GUI_roty*PI); EYE_DZ=-fcos(GUI_rotx*PI)*fcos(GUI_roty*PI); EYE_UX=-fsin(GUI_rotx*PI)*fsin(GUI_roty*PI); EYE_UY=fcos(GUI_roty*PI); EYE_UZ=fcos(GUI_rotx*PI)*fsin(GUI_roty*PI); if (b2) if (b3) stophook(); else acchook(); else if (b3) dechook(); if (fabs(EYE_SPEED)>EYE_MAXSPEED/20.0f) { GUI_reduced=TRUE; GUI_time=gettime(); } EYE_X+=EYE_DX*EYE_SPEED*time; EYE_Y+=EYE_DY*EYE_SPEED*time; EYE_Z+=EYE_DZ*EYE_SPEED*time; } if (!GUI_reduced) if (gettime()-GUI_time>VOL_DELAY2) over=VOL_OVERMIN; else if (GUI_slab1<0.5f) { float w=2.0f*GUI_slab1; over=((1.0f-w)*VOL_OVERMAX+w); } else { float w=2.0f*(1.0f-GUI_slab1); over=((1.0f-w)*VOL_OVERMIN+w); } else if (GUI_slab1<0.5f) { float w=2.0f*GUI_slab1; over=((1.0f-w)*VOL_OVERMAX+w)*fmin(1.0f/GUI_slab2,VOL_OVERMAX); } else { float w=2.0f*(1.0f-GUI_slab1); over=((1.0f-w)*VOL_OVERMIN+w)*fmin(1.0f/GUI_slab2,VOL_OVERMAX); } VOLREN->enablewireframe(GUI_wire); VOLREN->enablehistogram(GUI_points); VOLREN->begin(EYE_FOVY,getaspect(),EYE_NEAR,EYE_FAR, GUI_white,GUI_inv); VOLREN->render(EYE_X,EYE_Y,EYE_Z, EYE_DX,EYE_DY,EYE_DZ, EYE_UX,EYE_UY,EYE_UZ, EYE_NEAR, GUI_fbo, 360.0f*GUI_rot,0.0f,0.0f, 0.0f,4.0f*(GUI_height-0.5f),0.0f, VOL_EMISSION,VOL_DENSITY, GUI_re_scale,GUI_ge_scale,GUI_be_scale, GUI_ra_scale,GUI_ga_scale,GUI_ba_scale, GUI_premult,GUI_preint, GUI_inv, over, GUI_light, GUI_clip,GUI_clip_dist); OGL_GUI.refresh(); if (GUI_demo) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0f,getwinwidth()-1,0.0f,getwinheight()-1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glScalef(getwinwidth()-1,getwinheight()-1,0.0f); glDisable(GL_DEPTH_TEST); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_LINES); glVertex2f(0.5f+mx-0.01f/getaspect(),0.5f+my-0.01f); glVertex2f(0.5f+mx+0.01f/getaspect(),0.5f+my+0.01f); glVertex2f(0.5f+mx+0.01f/getaspect(),0.5f+my-0.01f); glVertex2f(0.5f+mx-0.01f/getaspect(),0.5f+my+0.01f); glEnd(); glEnable(GL_DEPTH_TEST); glPopMatrix(); } swapbuffers(); }
double elapsed() const { return gettime() - m_st; }
void start_section(int section_type) { last_start[section_type] = gettime(); }
double *synt_sine(double **d, int32_t Xsize, int32_t bands, int32_t *samplecount, int32_t samplerate, double basefreq, double pixpersec, double bpo) { double *s, *freq, *filter, *sband, sine[4], rphase; int32_t i, ib; int32_t Fc, Bc, Mh, Mn, sbsize; /* d is the original image (spectrogram) s is the output sound sband is the band's envelope upsampled and shifted up in frequency sbsize is the length of sband sine is the random sine look-up table *samplecount is the output sound's length ib is the band iterator i is a general purpose iterator bands is the total count of bands Fc is the index of the band's centre in the frequency domain on the new signal Bc is the index of the band's centre in the frequency domain on sband (its imaginary match being sbsize-Bc) Mh is the length of the real or imaginary part of the envelope's FFT, DC element included and Nyquist element excluded Mn is the length of the real or imaginary part of the sound's FFT, DC element included and Nyquist element excluded freq is the band's central frequency rphase is the band's sine's random phase */ freq = freqarray(basefreq, bands, bpo); clocka=gettime(); sbsize = nextsprime(Xsize * 2); // In Circular mode keep it to sbsize = Xsize * 2; *samplecount = roundoff(Xsize/pixpersec); printf("Sound duration : %.3f s\n", (double) *samplecount/samplerate); *samplecount = roundoff(0.5*sbsize/pixpersec); // Do not change this value as it would stretch envelopes s = calloc(*samplecount, sizeof(double)); // allocation of the sound signal sband = malloc (sbsize * sizeof(double)); // allocation of the shifted band Bc = roundoff(0.25 * (double) sbsize); Mh = (sbsize + 1) >> 1; Mn = (*samplecount + 1) >> 1; filter = wsinc_max(Mh, 1.0/TRANSITION_BW_SYNT); // generation of the frequency-domain filter for (ib=0; ib<bands; ib++) { memset(sband, 0, sbsize * sizeof(double)); // reset sband //********Frequency shifting******** rphase = dblrand() * pi; // random phase between -pi and +pi for (i=0; i<4; i++) // generating the random sine LUT sine[i]=cos(i*2.0*pi*0.25 + rphase); for (i=0; i<Xsize; i++) // envelope sampling rate * 2 and frequency shifting by 0.25 { if ((i & 1) == 0) { sband[i<<1] = d[bands-ib-1][i] * sine[0]; sband[(i<<1) + 1] = d[bands-ib-1][i] * sine[1]; } else { sband[i<<1] = d[bands-ib-1][i] * sine[2]; sband[(i<<1) + 1] = d[bands-ib-1][i] * sine[3]; } } //--------Frequency shifting-------- fft(sband, sband, sbsize, 0); // FFT of the envelope Fc = roundoff(freq[ib] * *samplecount); // band's centre index (envelope's DC element) printf("%4d/%d %.2f Hz\r", ib+1, bands, (double) Fc*samplerate / *samplecount); //********Write FFT******** for (i=1; i<Mh; i++) { if (Fc-Bc+i > 0 && Fc-Bc+i < Mn) // if we're between frequencies 0 and 0.5 of the new signal and that we're not at Fc { s[i+Fc-Bc] += sband[i] * filter[i]; // Real part s[*samplecount-(i+Fc-Bc)] += sband[sbsize-i] * filter[i]; // Imaginary part } } //--------Write FFT-------- } printf("\n"); fft(s, s, *samplecount, 1); // IFFT of the final sound *samplecount = roundoff(Xsize/pixpersec); // chopping tails by ignoring them normi(&s, *samplecount, 1, 1.0); return s; }
void tcpip_tmr_needed() { if(!tcpip_time && (uip_tcp_active_pcbs || uip_tcp_tw_pcbs)) { tcpip_time = gettime(); } }
voltype::voltype(void):type() { gettime(&ctm); }