static inline float get_sample_time(obs_source_t *transition, size_t sample_rate, size_t sample, uint64_t ts) { uint64_t sample_ts_offset = (uint64_t)sample * 1000000000ULL / (uint64_t)sample_rate; uint64_t i_ts = ts + sample_ts_offset; return calc_time(transition, i_ts); }
void PLab_ZumoMotors::backward(int _speed, int _length) { motors.setSpeeds(0, 0); float _time = calc_time(_speed,_length); motors.setSpeeds(- _speed, - _speed); delay(_time); motors.setSpeeds(0, 0); }
void update_time() { long time; char tmp[64]; if(count_dir) time = total_time - calc_time(); else time = calc_time(); sprintf(tmp,"%02ld:%02ld",time/60,time%60); if(strcmp(tmp,windforms[WIND_CTRL].wind_title)) { strcpy(windforms[WIND_CTRL].wind_title,tmp); wind_set(windforms[WIND_CTRL].whandle,WF_NAME, windforms[WIND_CTRL].wind_title); } }
bool AbstractContest::score(ContestResult &result) { if (positive(calc_time())) { result = best_result; return true; } return false; }
void dbrelay_time_release_shmem(dbrelay_request_t *request, dbrelay_connection_t *connections) { struct timeval start; struct timeval now; gettimeofday(&start, NULL); dbrelay_release_shmem(connections); gettimeofday(&now, NULL); dbrelay_log_debug(request, "shmem release time %d", calc_time(&start, &now)); }
void PLab_ZumoMotors::turnLeft(int _speed, int degrees) { motors.setSpeeds(0, 0); float _length = calc_turn_length(_speed); _length = _length * degrees / 90.0; float _time = calc_time(_speed,_length); motors.setSpeeds(- _speed, _speed); delay(_time); motors.setSpeeds(0, 0); }
int main(int argc,char * argv[]) { check_input(argc,argv); // Simple argument number checking struct timespec start, end; // Initialize long coords_within_lim = 0; // vars needed for int coll = atoi(argv[1]); // configuration int runtime = atoi(argv[2]); // and basic char *file = argv[3]; // calculations int threads_num = atoi(argv[4]); // in order to get int proc_num = atoi(argv[5]); // the desired output float coords_val[3] = {0, 0, 0}; long time_elapsed = 0; long loop_count = calc_lines(file); if(coll != -1) { if(coll>loop_count) { printf("[!] Warning: Specified collisions to be tested exceed the ones in input file\n"); printf("[!] Setting the number of collisions to the maximum (taken from input file)\n"); } else { loop_count = coll; } } FILE *input = fopen(file, "r"); // File opening if(!input) { printf("[!] Input file does not exist.\nExiting...\n"); exit(3); } clock_gettime(CLOCK_MONOTONIC, &start); // Initialize time calculation int i; for(i=0; i<loop_count; i++) // The main loop of the program { fscanf(input, "%f %f %f", &coords_val[0], &coords_val[1], &coords_val[2]); if(coords_val[0] >= MIN_LIM && coords_val[0] <= MAX_LIM && coords_val[1] >= MIN_LIM && coords_val[1] <= MAX_LIM && coords_val[2] >= MIN_LIM && coords_val[2] <= MAX_LIM) { coords_within_lim++; // If the current coordinate is within the accepted limits, update the number of accepted coordinates } } clock_gettime(CLOCK_MONOTONIC, &end); // Stop the timer time_elapsed = calc_time(start, end, 1); // Calculate the time elapsed printf("[+] %ld coordinates have been read\n[+] %ld cooordinates were inside the area of interest\n[+] %ld coordinates read per second\n", loop_count, coords_within_lim, loop_count/time_elapsed); fclose(input); // Close the file printf("[+] Done! \n" ); return 0; }
dbrelay_connection_t *dbrelay_time_get_shmem(dbrelay_request_t *request) { struct timeval start; struct timeval now; dbrelay_connection_t *connections; gettimeofday(&start, NULL); connections = dbrelay_get_shmem(); gettimeofday(&now, NULL); dbrelay_log_debug(request, "shmem attach time %d", calc_time(&start, &now)); return connections; }
/** * @brief This function is used to add a check point to a entrant. * * @param event Event structure with data about the event. * * @param status The status read from file. * * @param node Pointer to the node that is the checkpoint. * * @param ent The entrant that checked in at the check point * * @param time Time string of the time. */ void add_cp(EVENT *event, char status, NODE *node, ENTRANT *ent, char *time) { CP_LIST *list = NULL; CP_TIME *temp = calloc(1, sizeof(CP_TIME)); if(temp == NULL) { fprintf(stderr, "Call to calloc() failed.\n\n"); exit(0); } if(ent->checkpoints == NULL) { list = calloc(1, sizeof(CP_LIST)); if(list == NULL) { fprintf(stderr, "Call to calloc() failed.\n\n"); exit(0); } list->size = 1; ent->checkpoints = list; ent->start_time = format_time(time); list->head = temp; } else { TIME_STRUCT *ct = (TIME_STRUCT *) calloc(1, sizeof(TIME_STRUCT)); if(ct == NULL) { fprintf(stderr, "Call to calloc() failed.\n\n"); exit(0); } ent->checkpoints->size += 1; ct = format_time(time); temp->time = ct; calc_time(ent->start_time, ct, ent->total_time); ent->checkpoints->tail->next = temp; } temp->node = node; temp->status = status; temp->time = format_time(time); //ent->start_time = format_time(time); ent->current_node = node; ent->last_cp = temp; ent->checkpoints->tail = temp; if(status == 'I') { ent->excluded = 1; } update_status(ent, event); }
static void fini( TIMESTAMP *time ) { ULONG rc; ULONG bytes; DosRead( timerHandle, &stopTime, sizeof( TIMESTAMP ), &bytes ); calc_time( time, &startTime, &stopTime, &overHead ); rc = DosClose( timerHandle ); if( rc != 0 ) { printf( "Could not close WTIMER$\n" ); } }
float time_wrapper( void (*f)(int*, int, void (*)(int*, int) ), void (*s)(int*, int), int *a, int n ) { struct timeval timev1, timev2; gettimeofday(&timev1, NULL); (*f)(a, n, s); gettimeofday(&timev2, NULL); return calc_time(timev1, timev2); }
fixed OLCDijkstra::score(fixed& the_distance, fixed& the_speed, fixed& the_time) { if (positive(calc_time())) { solution_found = true; the_distance = best_distance; the_speed = best_speed; the_time = best_time; return best_distance; } return fixed_zero; }
int main() { char buf[BUF_SIZE]; get_cpu_type(buf, sizeof(buf)); printf("CPU Type: %s\n", buf); get_kernel_version(buf, sizeof(buf)); printf("Kernel Version: %s\n", buf); get_uptime(buf, sizeof(buf)); calc_time(buf, buf, sizeof(buf)); printf("Time since bootup: %s\n", buf); return 0; }
static void init( void ) { ULONG rc; ULONG action; ULONG bytes; rc = DosOpen( "WTIMER$", &timerHandle, &action, 0, FILE_NORMAL, FILE_OPEN, OPEN_SHARE_DENYNONE, NULL ); if( rc == 0 ) { DosRead( timerHandle, &startTime, sizeof( TIMESTAMP ), &bytes ); DosRead( timerHandle, &stopTime, sizeof( TIMESTAMP ), &bytes ); calc_time( &overHead, &startTime, &stopTime, NULL ); DosRead( timerHandle, &startTime, sizeof( TIMESTAMP ), &bytes ); } else { printf( "Could not open WTIMER$\n" ); } }
bool AbstractContest::save_solution() { const fixed score = calc_score(); const bool improved = (score>best_result.score); if (improved) { best_result.score = score; best_result.distance = calc_distance(); best_result.time = calc_time(); if (positive(best_result.time)) best_result.speed = best_result.distance / best_result.time; else best_result.speed = fixed_zero; return true; } return false; }
int main(int argc, char** argv) { /* Add code here -- put your names at the top. */ char buf[MAX_BUF_LEN]; char prompt[] = "> "; unsigned long begin_time = 0, end_time = 0; ssize_t read_cnt = 0; int second_decimal = 0, second_fraction = 0; while(1) { write(STDOUT_FILENO, prompt, 2); begin_time = time(); read_cnt = read(STDIN_FILENO, buf, MAX_BUF_LEN); end_time = time(); write(STDOUT_FILENO, buf, read_cnt); calc_time(begin_time, end_time, &second_decimal, &second_fraction); printf("%d.%ds\n", second_decimal, second_fraction); } return 0; }
void OLCDijkstra::save_solution() { if (!solution.size()) return; const fixed the_distance = calc_distance(); if (the_distance > best_distance) { best_solution.clear(); for (unsigned i = 0; i < num_stages; ++i) best_solution.push_back(solution[i]); best_distance = the_distance; best_time = calc_time(); if (positive(best_time)) best_speed = best_distance / best_time; else best_speed = fixed_zero; } }
/** * @brief Prints out nicely formated info about a entrant. * * @param entrant The entrant to print out. */ void print_entrant(ENTRANT *entrant) { if (entrant->checkpoints == NULL) { printf(ENT_FORMAT, entrant->comp_number, entrant->name, entrant->course_id, "Not Started", "N/A", "N/A"); //printf("This entrant has not started.\n"); } else { char time[20]; calc_time(entrant->start_time, entrant->last_cp->time, time); printf(ENT_FORMAT, entrant->comp_number, entrant->name, entrant->course_id, entrant->status, entrant->start_time->time_str, time); } }
int do_formstuff(int obj_id) { int tfd; switch(obj_id) { case CTRL_STOP: if(Dsp_Hf1(-1)) /* If fast forwarding */ { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); } if(replay || replay_pause) { if(windforms[WIND_CTRL].formtree[CTRL_PAUSE].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL); replay_pause=0; exit_replay(); update_time(); } break; case CTRL_PLAY: if(replay_pause || Dsp_Hf1(-1)) { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); if(windforms[WIND_CTRL].formtree[CTRL_PAUSE].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL); continue_replay(); replay_pause=0; } else { if(!replay && file_open) { replay_pause=0; init_replay(); } else { if((tfd = open_file()) > 0) { int error; fd=tfd; if((error=getmp2info(fd))==MP2_NOERR) { replay_pause=0; update_time(); setfilename(filename); init_replay(); } else { show_mp2_error(error); close_file(fd); strcpy(windforms[WIND_CTRL].wind_title,"MPEG"); wind_set(windforms[WIND_CTRL].whandle,WF_NAME, windforms[WIND_CTRL].wind_title); setfilename("MPEGFILE"); } } } } break; case CTRL_PAUSE: if(replay_pause) { continue_replay(); replay_pause=0; } else { if(replay) { pause_replay(); replay_pause=1; } } break; case CTRL_LOAD: if((tfd = open_file()) > 0) { int error; if(windforms[WIND_CTRL].formtree[CTRL_PAUSE].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL); replay_pause=0; if(Dsp_Hf1(-1)) /* If fast forwarding */ { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); } fd=tfd; if((error=getmp2info(tfd))==MP2_NOERR) { update_time(); setfilename(filename); } else { show_mp2_error(error); close_file(fd); strcpy(windforms[WIND_CTRL].wind_title,"MPEG"); wind_set(windforms[WIND_CTRL].whandle,WF_NAME, windforms[WIND_CTRL].wind_title); setfilename("MPEGFILE"); } } break; case CTRL_LOOP: looping=(windforms[WIND_CTRL].formtree[CTRL_LOOP].ob_state & SELECTED); break; case CTRL_INFO: /* Open info window */ if(windforms[WIND_INFO].wind_open) wind_set(windforms[WIND_INFO].whandle,WF_TOP); else { fg_init(&windforms[WIND_INFO]); wind_open(windforms[WIND_INFO].whandle, windforms[WIND_INFO].wind.x,windforms[WIND_INFO].wind.y, windforms[WIND_INFO].wind.w,windforms[WIND_INFO].wind.h); windforms[WIND_INFO].wind_open=1; } break; case CTRL_NEXT: if(file_open) { int o_replay,o_pause; if(Dsp_Hf1(-1)) /* If fast forwarding */ { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); } o_replay = replay; o_pause = replay_pause; exit_replay(); while((tfd=next_song(path, filename, 1))!=0) { if(getmp2info(tfd)!=MP2_NOERR) { close_file(tfd); } else { if(file_open) close_file(fd); fd = tfd; file_open=1; update_time(); setfilename(filename); replay = o_replay; replay_pause = o_pause; if(replay) init_replay(); if(replay_pause) { init_replay(); pause_replay(); } break; } } if(!tfd) { update_time(); } } break; case CTRL_PREV: if(file_open) { int o_replay,o_pause; if(Dsp_Hf1(-1)) /* If fast forwarding */ { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); } o_replay = replay; o_pause = replay_pause; /* if more than or one second of the song has elapsed, go to the beginning of of the same song! */ if(calc_time() > 0) { reset_file(fd); update_time(); replay = o_replay; replay_pause = o_pause; if(replay) init_replay(); if(replay_pause) { init_replay(); pause_replay(); } } else { exit_replay(); while((tfd=next_song(path, filename, 0))!=0) { if(getmp2info(tfd)!=MP2_NOERR) { close_file(tfd); } else { if(file_open) close_file(fd); fd = tfd; file_open=1; update_time(); setfilename(filename); replay = o_replay; replay_pause = o_pause; if(replay) init_replay(); if(replay_pause) { init_replay(); pause_replay(); } break; } } if(!tfd) { update_time(); } } } break; case CTRL_FF: if (windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) Dsp_Hf1(1); else Dsp_Hf1(0); break; case CTRL_TIME: if(windforms[WIND_CTRL].formtree[CTRL_TIME].ob_state & SELECTED) count_dir = 0; /* count up */ else count_dir = 1; /* count down */ if(file_open) update_time(); break; default: break; } return 0; }
END_TEST START_TEST(test_overflow) { ck_assert_int_eq(calc_time(899, INT_MAX/2, INT_MAX-10), -2); }
END_TEST START_TEST(test_four_turns_eight) { ck_assert_int_eq(calc_time(1, 5, 7), 15); }
static inline float get_video_time(obs_source_t *transition) { uint64_t ts = obs->video.video_time; return calc_time(transition, ts); }
END_TEST START_TEST(test_one_turn_again) { ck_assert_int_eq(calc_time(3, 3, 9), 3); }
END_TEST START_TEST(test_three_turns) { ck_assert_int_eq(calc_time(3, 2, 9), 9); }
END_TEST START_TEST(test_fail) { ck_assert_int_eq(calc_time(3, 4, 6), -1); }
END_TEST START_TEST(test_one_turn) { ck_assert_int_eq(calc_time(3, 5, 7), 10); }
END_TEST START_TEST(test_fail_one) { ck_assert_int_eq(calc_time(1, 3, 9), -1); }
END_TEST START_TEST(test_three_turns_eight) { ck_assert_int_eq(calc_time(8, 5, 7), 15); }
END_TEST START_TEST(test_two_turns) { ck_assert_int_eq(calc_time(3, 10, 9), 30); }
bool obs_transition_audio_render(obs_source_t *transition, uint64_t *ts_out, struct obs_source_audio_mix *audio, uint32_t mixers, size_t channels, size_t sample_rate, obs_transition_audio_mix_callback_t mix_a, obs_transition_audio_mix_callback_t mix_b) { obs_source_t *sources[2]; struct transition_state state = {0}; bool stopped = false; uint64_t min_ts; float t; if (!transition_valid(transition, "obs_transition_audio_render")) return false; lock_transition(transition); sources[0] = transition->transition_sources[0]; sources[1] = transition->transition_sources[1]; min_ts = calc_min_ts(sources); if (min_ts) { t = calc_time(transition, min_ts); if (t >= 1.0f && transition->transitioning_audio) stopped = stop_audio(transition); sources[0] = transition->transition_sources[0]; sources[1] = transition->transition_sources[1]; min_ts = calc_min_ts(sources); if (min_ts) copy_transition_state(transition, &state); } else if (transition->transitioning_audio) { stopped = stop_audio(transition); } unlock_transition(transition); if (min_ts) { if (state.transitioning_audio) { if (state.s[0]) process_audio(transition, state.s[0], audio, min_ts, mixers, channels, sample_rate, mix_a); if (state.s[1]) process_audio(transition, state.s[1], audio, min_ts, mixers, channels, sample_rate, mix_b); } else if (state.s[0]) { memcpy(audio->output[0].data[0], state.s[0]->audio_output_buf[0][0], TOTAL_AUDIO_SIZE); } obs_source_release(state.s[0]); obs_source_release(state.s[1]); } if (stopped) obs_source_dosignal(transition, "source_transition_stop", "transition_stop"); *ts_out = min_ts; return !!min_ts; }