Exemplo n.º 1
0
int play_trk(int from, int to)
{
    struct msft f;
    struct msft t;

    get_start_time(from, &f);
    get_start_time(to + 1, &t);
    return play_msf(&f, &t);
}
Exemplo n.º 2
0
Arquivo: misc.c Projeto: cfxks1989/mpv
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t)
{
    double length = get_time_length(mpctx);
    double start = get_start_time(mpctx);
    switch (t.type) {
    case REL_TIME_ABSOLUTE:
        return t.pos;
    case REL_TIME_RELATIVE:
        if (t.pos >= 0) {
            return start + t.pos;
        } else {
            if (length != 0)
                return MPMAX(start + length + t.pos, 0.0);
        }
        break;
    case REL_TIME_PERCENT:
        if (length != 0)
            return start + length * (t.pos / 100.0);
        break;
    case REL_TIME_CHAPTER:
        if (chapter_start_time(mpctx, t.pos) != MP_NOPTS_VALUE)
            return chapter_start_time(mpctx, t.pos);
        break;
    }
    return MP_NOPTS_VALUE;
}
Exemplo n.º 3
0
void App::initialise_1()
{
	draw_info("* Calculating Test Run Length *");

	cb_test = clan::bind_member(&tests, &Tests::test_empty);

	tests_run_length_microseconds = (uint64_t) (((double) target_test_run_length_seconds) * 1000000.0);

	const uint64_t num_block_iteration = 10000;

	uint64_t start_time = get_start_time();
	for (num_iterations = 0; ; num_iterations++)
	{
		uint64_t current_time = clan::System::get_microseconds();

		if ((current_time - start_time) >= tests_run_length_microseconds)
			break;
	
		for (uint64_t cnt=0; cnt < num_block_iteration; cnt++)
		{
			cb_test();
		}
		num_iterations+=num_block_iteration;
	}
	cb_main = clan::bind_member(this, &App::initialise_2);
}
Exemplo n.º 4
0
/* To print the statistics of the solution */
void print_summary(solution_t *soln) {
    
    job_t *jobs = soln->jobs;
    int *jobs_order = soln->jobs_order;
    int first_job, last_job;

    printf("-----------------\n");
    printf("SUMMARY\n");
    printf("-----------------\n");
    first_job = jobs_order[0]; 
    last_job = jobs_order[numnodes]; 
    printf("Time span: %f\n", get_end_time(last_job, soln)-get_start_time(first_job, soln));
    printf("Objective function: %f\n", objective_function(soln));
    printf("\n");
    printf("Number of late jobs: %d\n", get_num_late_jobs(soln));
    printf("Sum of all tardiness: %f\n", get_total_lateness(soln));
    printf("Max tardiness: %f\n", get_max_lateness(soln));
    printf("Average tardiness: %f\n", get_average_lateness(soln));
    printf("Variance of tardiness: %f\n", get_variance_lateness(soln));
    printf("Standard deviation of tardiness: %f\n", get_standard_deviation_lateness(soln));
    printf("\n");
    printf("Number of early jobs: %d\n", get_num_early_jobs(soln));
    printf("Sum of all earliness: %f\n", get_total_earliness(soln));
    printf("Average earliness: %f\n", get_average_earliness(soln));
    printf("\n");
    printf("Total travelling time: %f\n", get_total_travelling_time(soln));
    printf("Total waiting time: %f\n", get_total_waiting_time(soln));
    printf("-----------------\n");

}
Exemplo n.º 5
0
void App::initialise_1()
{
	draw_info("* Calculating Test Run Length *");

	cb_test.set(&tests, &Tests::test_empty);

	tests_run_length_microseconds = (clan::ubyte64) (((double) target_test_run_length_seconds) * 1000000.0);

	const clan::ubyte64 num_block_iteration = 10000;

	clan::ubyte64 start_time = get_start_time();
	for (num_iterations = 0; ; num_iterations++)
	{
		clan::ubyte64 current_time = clan::System::get_microseconds();

		if ((current_time - start_time) >= tests_run_length_microseconds)
			break;
	
		for (clan::ubyte64 cnt=0; cnt < num_block_iteration; cnt++)
		{
			cb_test.invoke();
		}
		num_iterations+=num_block_iteration;
	}
	cb_main.set(this, &App::initialise_2);
}
Exemplo n.º 6
0
Arquivo: misc.c Projeto: cfxks1989/mpv
// Get the offset from the given track to the video.
double get_track_video_offset(struct MPContext *mpctx, struct track *track)
{
    if (track && track->under_timeline)
        return mpctx->video_offset;
    if (track && track->is_external)
        return get_start_time(mpctx);
    return 0;
}
Exemplo n.º 7
0
    ulong_ elapsed() const
    {
        if(!is_supported() || !m_start_event){
            return 0;
        }

        if(m_stop_event){
            const_cast<event &>(m_stop_event).wait();

            return get_start_time(m_stop_event) - get_end_time(m_start_event);
        }
        else {
            event now = const_cast<command_queue &>(m_queue).enqueue_marker();
            now.wait();

            return get_start_time(now) - get_end_time(m_start_event);
        }
    }
Exemplo n.º 8
0
Arquivo: dir.c Projeto: nmcv/foremost
int create_output_directory(f_state *s)
{
	DIR		*d;
	char	dir_name[MAX_STRING_LENGTH];
  
	memset(dir_name, 0, MAX_STRING_LENGTH - 1);
	if (s->time_stamp)
		{
		strcpy(dir_name, get_output_directory(s));
		strcat(dir_name, "_");
		strcat(dir_name, get_start_time(s));
		clean_time_string(dir_name);
		set_output_directory(s, dir_name);
		}
#ifdef DEBUG
	printf("Checking output directory %s\n", get_output_directory(s));
#endif

	if ((d = opendir(get_output_directory(s))) != NULL)
		{

		/* The directory exists already. It MUST be empty for us to continue */
		if (!is_empty_directory(d))
			{
			printf("ERROR: %s is not empty\n \tPlease specify another directory or run with -T.\n",
				   get_output_directory(s));

			exit(EXIT_FAILURE);
			}

		/* The directory exists and is empty. We're done! */
		closedir(d);
		return FALSE;
		}

	/* The error value ENOENT means that either the directory doesn't exist,
     which is fine, or that the filename is zero-length, which is bad.
     All other errors are, of course, bad. 
*/
	if (errno != ENOENT)
		{
		print_error(s, get_output_directory(s), strerror(errno));
		return TRUE;
		}

	if (strlen(get_output_directory(s)) == 0)
		{

		/* Careful! Calling print_error will try to display a filename
       that is zero characters! In theory this should never happen 
       as our call to realpath should avoid this. But we'll play it safe. */
		print_error(s, "(output_directory)", "Output directory name unknown");
		return TRUE;
		}

	return (make_new_directory(s, get_output_directory(s)));
}
Exemplo n.º 9
0
void c_init()
{
    struct cdrom_tochdr toc_hdr;

    fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);

    if (ioctl(fd, CDROMREADTOCHDR, &toc_hdr) != -1){
		first_trk = toc_hdr.cdth_trk0;
		last_trk = toc_hdr.cdth_trk1;
    }
    else{
		first_trk = -1;
		return;
    }

    get_start_time(first_trk, &start);
    get_start_time(last_trk + 1, &end);
}
Exemplo n.º 10
0
int64_t App::run_test()
{
	uint64_t start_time = get_start_time();
	for (uint64_t cnt=0; cnt < num_iterations; cnt++)
	{
		cb_test();
	}
	return (clan::System::get_microseconds() - start_time);

}
Exemplo n.º 11
0
clan::byte64 App::run_test()
{
	clan::ubyte64 start_time = get_start_time();
	for (clan::ubyte64 cnt=0; cnt < num_iterations; cnt++)
	{
		cb_test.invoke();
	}
	return (clan::System::get_microseconds() - start_time);

}
Exemplo n.º 12
0
// 最初の初期化するための関数
void first_init(engine* e) {

	LOGD("call_order", "first_init() called");
	init_all_trig_samples();
	int suc = create_window_surface(e->app->window);
	LOGD("call_order", "create_window_surface, suc: %d", suc);
	suc = gles_init();
	LOGD("call_order", "init_cmds, suc: %d", suc);
	get_start_time();
	get_screen_dimensions(e);
	calc_segment_width();
	e->animating = TRUE;
}
Exemplo n.º 13
0
/* To print the solution in gantt chart like format */
void print_graph(solution_t *soln) {

    job_t *jobs = soln->jobs;
    int *jobs_order = soln->jobs_order;
    int i, j, job_id;
    int current_pos;
    
    for(i=0; i<numnodes+1; i++) {
        current_pos = 0;
        job_id = jobs_order[i]; 
        
        printf("Job ID %d:\t", job_id);
        
        /* Print the release date */
        for(j=0; j<(int) node_tw[job_id][0]; j++) {
            current_pos++;
            printf(" ");
        }    
        printf("[");
     
        /* Print the underscore ( _ ) to represent the time before the start of the job */
        for(j=current_pos; j<(int)(get_start_time(job_id, soln)); j++) {
            current_pos++;
            if(current_pos == (int) node_tw[job_id][1])
                printf("*");
            else if(current_pos > (int) node_tw[job_id][0])
                printf("_");
        }
        /* Print the duration of the job */
        for(j=0; j<(int)(get_duration(job_id, soln)); j++) {
            current_pos++;
            if(current_pos == (int) node_tw[job_id][1])
                printf("*");
            else
                printf("|");
        }
        
        /* Print the due date if it is not yet passed */
        if(current_pos < (int) node_tw[job_id][1]) {
            for(j=current_pos; j < (int)node_tw[job_id][1]; j++)
                printf("_");
            printf("]");
        }

        printf("\n");
    }

    print_legend();

}
Exemplo n.º 14
0
void get_date_and_time(int *minutes, int *day, int *month, int *year)
{
    time_t myclock = get_start_time();
    struct tm *tmptr ;
    if (utc_option) {
        tmptr = gmtime(&myclock);
    } else {
        tmptr = localtime(&myclock);
    }

    *minutes = tmptr->tm_hour * 60 + tmptr->tm_min;
    *day = tmptr->tm_mday;
    *month = tmptr->tm_mon + 1;
    *year = tmptr->tm_year + 1900;

    {
#ifdef SA_INTERRUPT

        /*
            Under SunOS 4.1.x, the default action after return from the signal
            handler is to restart the I/O if nothing has been transferred. The
            effect on TeX is that interrupts are ignored if we are waiting for
            input. The following tells the system to return EINTR from read() in
            this case. From [email protected].
        */

        struct sigaction a, oa;

        a.sa_handler = catch_interrupt;
        sigemptyset(&a.sa_mask);
        sigaddset(&a.sa_mask, SIGINT);
        a.sa_flags = SA_INTERRUPT;
        sigaction(SIGINT, &a, &oa);
        if (oa.sa_handler != SIG_DFL)
            sigaction(SIGINT, &oa, (struct sigaction *) 0);
#else /* no SA_INTERRUPT */
#  ifdef WIN32
        SetConsoleCtrlHandler(catch_interrupt, TRUE);
#  else /* not WIN32 */
        RETSIGTYPE(*old_handler) (int);

        old_handler = signal(SIGINT, catch_interrupt);
        if (old_handler != SIG_DFL)
            signal(SIGINT, old_handler);
#  endif /* not WIN32 */
#endif /* no SA_INTERRUPT */
    }
}
Exemplo n.º 15
0
Arquivo: misc.c Projeto: Deadsign/mpv
double get_play_end_pts(struct MPContext *mpctx)
{
    struct MPOpts *opts = mpctx->opts;
    if (opts->play_end.type) {
        return rel_time_to_abs(mpctx, opts->play_end);
    } else if (opts->play_length.type) {
        double startpts = get_start_time(mpctx);
        double start = rel_time_to_abs(mpctx, opts->play_start);
        if (start == MP_NOPTS_VALUE)
            start = startpts;
        double length = rel_time_to_abs(mpctx, opts->play_length);
        if (start != MP_NOPTS_VALUE && length != MP_NOPTS_VALUE)
            return start + length;
    }
    return MP_NOPTS_VALUE;
}
Exemplo n.º 16
0
static __inline__ int 
xmt_get_start_time(const char *pri, H264_DVR_TIME *time)
{
    int ret;
    JTime ts;

    ret = get_start_time(pri, &ts);
    if (!ret)
    {
        time->dwYear   = ts.year + J_SDK_DEF_BASE_YEAR;
        time->dwMonth  = ts.month;
        time->dwDay    = ts.date;
        time->dwHour   = ts.hour;
        time->dwMinute = ts.minute;
        time->dwSecond = ts.second;
    }

    return ret;
}
Exemplo n.º 17
0
int getrandomseed(void)
{
#if defined (HAVE_GETTIMEOFDAY)
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return (int)(tv.tv_usec + 1000000 * tv.tv_usec);
#elif defined (HAVE_FTIME)
    struct timeb tb;
    ftime(&tb);
    return (tb.millitm + 1000 * tb.time);
#else
    time_t myclock = get_start_time((time_t *) NULL);
    struct tm *tmptr ;
    if (utc_option) {
        tmptr = gmtime(&myclock);
    } else {
        tmptr = localtime(&myclock);
    }
    return (tmptr->tm_sec + 60 * (tmptr->tm_min + 60 * tmptr->tm_hour));
#endif
}
Exemplo n.º 18
0
static __inline__ int 
hie_get_start_time(const char *pri, TimeInfo *time)
{
    int ret;
    JTime ts;

    ret = get_start_time(pri, &ts);
    if (!ret)
    {
        time->wYear   = ts.year + J_SDK_DEF_BASE_YEAR;
        time->wMonth  = ts.month;
        time->wDay    = ts.date;
        time->wHour   = ts.hour;
        time->wMinute = ts.minute;
        time->wSecond = 0;//ts.second;
    }
    /*printf("start:%04d/%02d/%02d-%02d:%02d:%02d\n", 
        (int)time->wYear, (int)time->wMonth, (int)time->wDay, 
        (int)time->wHour, (int)time->wMinute, (int)time->wSecond);*/
    return ret;
}
Exemplo n.º 19
0
Arquivo: misc.c Projeto: LiminWang/mpv
double get_play_end_pts(struct MPContext *mpctx)
{
    struct MPOpts *opts = mpctx->opts;
    double end = MP_NOPTS_VALUE;
    if (opts->play_end.type) {
        end = rel_time_to_abs(mpctx, opts->play_end);
    } else if (opts->play_length.type) {
        double startpts = get_start_time(mpctx);
        double start = rel_time_to_abs(mpctx, opts->play_start);
        if (start == MP_NOPTS_VALUE)
            start = startpts;
        double length = rel_time_to_abs(mpctx, opts->play_length);
        if (start != MP_NOPTS_VALUE && length != MP_NOPTS_VALUE)
            end = start + length;
    }
    if (opts->chapterrange[1] > 0) {
        double cend = chapter_start_time(mpctx, opts->chapterrange[1]);
        if (cend != MP_NOPTS_VALUE && (end == MP_NOPTS_VALUE || cend < end))
            end = cend;
    }
    return end;
}
Exemplo n.º 20
0
/* To print the details of the solution */
void print_solution(solution_t *soln) {

    job_t *jobs = soln->jobs;
    int *jobs_order = soln->jobs_order;
    int i, job_id;
    float duration; 
    
    for(i=0; i<numnodes+1; i++) {
        job_id = jobs_order[i];
        duration = jobs[job_id].end_time - jobs[job_id].start_time;
        
        printf("-----------------\n");
        printf("Job #: %d\n", job_id);
        printf("Job order: %d\n", get_job_order(job_id, soln));
        if(i > 0)
            printf("Waiting time: %f\n", get_waiting_time(jobs_order[i-1], job_id, soln));
        printf("Start Time: %f\n", get_start_time(job_id, soln));
        printf("End Time: %f\n", get_end_time(job_id, soln));
        printf("Duration: %f\n", get_duration(job_id, soln));
        printf("Lateness: %f\n", get_lateness_time(job_id, soln));
        printf("-----------------\n");
    }
}
Exemplo n.º 21
0
void
rewind_audio (void)
{
    if (Denemo.project->movement->recording && (Denemo.project->movement->recording->type==DENEMO_RECORDING_AUDIO))
    {
        if (Denemo.project->movement->recording->sndfile == NULL)
        {
            gint leadin = Denemo.project->movement->recording->leadin;  /* not part of the audio file itself */
            open_source_audio (Denemo.project->movement->recording->filename);
            if (Denemo.project->movement->recording==NULL)
            {
                g_warning("Unable to open audio file");
                return;
            }
            if (Denemo.project->movement->recording->samplerate)
            {
                Denemo.project->movement->recording->leadin = leadin;
                update_leadin_widget (((double) leadin) / Denemo.project->movement->recording->samplerate);
            }
        }
        gdouble start = get_start_time ();
        if (start < 0.0)
            start = 0.0;
        gint startframe = start * Denemo.project->movement->recording->samplerate;
        startframe += Denemo.project->movement->recording->leadin;
        if (startframe < 0)
        {
            leadin = -startframe;
            startframe = 0;
        }
        else
            leadin = 0;
        sf_seek (Denemo.project->movement->recording->sndfile, startframe, SEEK_SET);
    }
    else
        gtk_widget_hide (Denemo.audio_vol_control);
}
Exemplo n.º 22
0
int cgiMain() {
	int power_num,group_serial_num[5],group_num,group_idx;
	int i,j,k;
	char name[81];
	ctrl_group *p_group ;

	cgiFormInteger("power_num", &power_num, 0);
	cgiFormInteger("group_num", &group_num, 0);
	memset(name,0,sizeof(name));
	cgiFormStringNoNewlines("serial_num", name, 81);
	get_serial_num(name,&group_serial_num);
	
	if(power_num > 100) power_num = 100;
	if(group_num > 5) group_num = 5;
	if(group_serial_num[0] > 100) group_serial_num[0] = 100;
	if(group_serial_num[1] > 100) group_serial_num[1] = 100;
	if(group_serial_num[2] > 100) group_serial_num[2] = 100;
	if(group_serial_num[3] > 100) group_serial_num[3] = 100;
	if(group_serial_num[4] > 100) group_serial_num[4] = 100;


	cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat");
	cgiHeaderContentType("text/html");

	OutHead();
	OutBodyStart();

	if(0 == check_password())
		return 0;

	fprintf(cgiOut, "<p>power_num=%d group_num=%d [%d-%d-%d-%d-%d]</p>\n",
		power_num,group_num,group_serial_num[0],group_serial_num[1],
		group_serial_num[2],group_serial_num[3],group_serial_num[4]);

	if(0 == power_num)
	{
		fprintf(cgiOut, "<p>数据出错,退出!!</p>\n");
		OutBodyEnd();	
		return 0;
	}
	else
	{
		pwsw_h.power_num = power_num;
		pwsw_h.group_num = group_num;
		pwsw_h.group[0].ctrl_serial_num = group_serial_num[0];
		pwsw_h.group[1].ctrl_serial_num = group_serial_num[1];
		pwsw_h.group[2].ctrl_serial_num = group_serial_num[2];
		pwsw_h.group[3].ctrl_serial_num = group_serial_num[3];
		pwsw_h.group[4].ctrl_serial_num = group_serial_num[4];

		for(i=0;i<group_num;i++)
		{
			p_group = &pwsw_h.group[i];
			p_group->projector_on = 0;
			p_group->ctrl_serial_num = group_serial_num[i];
			get_start_time(i,&p_group->start_time);
			get_end_time(i,&p_group->end_time);
			for(j=0;j<p_group->ctrl_serial_num;j++)
			{
				p_group->serial_info[j].duration_ms = get_duration_ms(i,j);
				for(k=0;k<power_num;k++)
				{
					p_group->serial_info[j].power_status[k]= get_power_status(i,j,k);
				}
				
			}
		}
	}

	//Out_pwsw_xml();
	save_to_xml_file();
	fprintf(cgiOut, "<p>保存成功,请返回!</p>\n");
	fprintf(cgiOut, "&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"button\" name=\"rest\" onclick=\"javascript:history.go(-1)\" value=\"重新载入\" />\n");

	OutBodyEnd();

	return 0;
}
Exemplo n.º 23
0
void *workload_replayer(void *arg)
{
    unsigned int tid = 0;
    readLine req;
    long long trace_sTime = -1;
    long long trace_wTime = 0;
    long long gio_sTime   = 0;
    long long gio_wTime   = 0;
    struct timeval now;
    int fd;
    char *buf;
    size_t ret;
    unsigned long mSize;
    unsigned long mAddr;
    OPERATION_TYPE op;

    desc = (wg_env *)arg;
    if( (fd = open(desc->file_path, O_CREAT|O_RDWR|O_DIRECT, 0666)) == -1 ){
    //if( (fd = open(desc->file_path, O_CREAT|O_RDWR, 0666)) == -1){
	PRINT("Error on opening the init_file of workload generator, file:%s, line:%d, fd=%d\n", __func__, __LINE__, fd);
	exit(1);
    }

#if !defined(BLOCKING_IO)
    aio_initialize(desc->max_queue_depth);
#endif

    mem_allocation(desc, &buf, REPLAYER_MAX_FILE_SIZE);
    if (NULL == buf) {
	PRINT("Error on memory allocation, file:%s, line:%d\n", __func__, __LINE__);
	exit(1);
    }

    while(1){
	//Dequeueing
	req = de_queue();
	//If a request is successfully dequeued.
	if(strcmp(req.rwbs, "EMPTY") != 0){
	    mSize = select_size(req.size);
	    mAddr = select_start_addr(req.sSector);
	    fill_data(desc, buf, mSize);

	    //Calculate wait time based on trace log
	    if(trace_sTime == -1){
		get_start_time(&trace_sTime, &gio_sTime); 
	    }
	    trace_wTime = MICRO_SECOND(req.sTime) - trace_sTime;
	    if(trace_wTime < 0){
		PRINT("trace_wTime : %lli\n", trace_wTime);
		PRINT("Issue time must be ordered. Check the issue time in trace file");
		exit(1);
	    }

	    //Caculate how much time should wait
	    get_current_time(&now);
	    gio_wTime = TIME_VALUE(&now) - gio_sTime;
	    PRINT("TIMEDEBUG trace_wTime:%10lli  \tgio_wTime:%10lli\n",
		    trace_wTime, gio_wTime);

	    //If we need to wait
	    if(trace_wTime > gio_wTime){
		PRINT("WAITING ....%lli us\n", trace_wTime - gio_wTime);
		usec_sleep(trace_wTime - gio_wTime);
	    }
	    op = strstr(req.rwbs,"R")!=NULL? WG_READ : WG_WRITE;
#if defined(BLOCKING_IO)
	    if(op == WG_READ){
		//PRINT("R\n");
		ret = pread(fd, buf , (size_t)mSize, mAddr);
	    }else{
		//PRINT("W\n");
		ret = pwrite(fd, buf , (size_t)mSize, mAddr);
		fsync(fd);
	    }
	    if (ret != mSize) {
		PRINT("Error on file I/O (error# : %zu), file:%s, line:%d\n", ret, __func__, __LINE__);
		break;
	    }
#else
    	    ret = aio_enqueue(fd, buf, mSize, mAddr, op);
	    if (ret != 1) {
		PRINT("Error on file I/O (error# : %zu), file:%s, line:%d\n", ret, __func__, __LINE__);
		break;
	    }
#endif //BLOCKING_IO
#if 0
	    PRINT("DEQUEUED REQ tid:%u sTime:%lf rwbs:%s Addr:%12li \t Size:%12lu\n\n", 
		    tid,
		    req.sTime,
		    req.rwbs,
		    mAddr,
		    mSize);	
#endif
		   
	}

	if( get_queue_status() == 1 ){
	    PRINT("END OF REPLAYER\n");
	    break;
	}
    }
    pthread_mutex_destroy(&thr_mutex);
}
Exemplo n.º 24
0
void slopecurv(node *p,double y,double *like,double *slope,double *curve)
{
#ifdef CALLCOUNT
	printf("slopecurve\n");
#endif
#ifdef SCTIMINGS
	get_start_time(slopecurv_tk);
#endif
	
	
	if (!tbl) {
		printf("oh, my, god\n");
	}
	if (!tbl[0]) {
		printf("oh, my, god2\n");
	}
	if (!tbl[0][0]) {
		printf("oh, my, god3\n");
	}	
	
	
	/* compute log likelihood, slope and curvature at node p */
	long i, j, k, lai;
	double sum, sumc, sumterm, lterm, sumcs, sumcc, sum2, slope2, curve2,
	temp;
	double lz, zz, z1, zzs, z1s, zzc, z1c, aa, bb, cc,
	prod1, prod2, prod12, prod3;
	contribarr thelike, nulike, nuslope, nucurve,
    theslope, thecurve, clai, cslai, cclai;
	node *q;
	sitelike x1, x2;
	
	q = p->back;
	sum = 0.0;
	lz = -y;
	for (i = 0; i < rcategs; i++)
		for (j = 0; j < categs; j++) {
			tbl[i][j]->orig_zz = exp(tbl[i][j]->rat * lz);
			tbl[i][j]->z1 = exp(tbl[i][j]->ratxv * lz);
		}
	for (i = 0; i < endsite; i++) {
		k = category[alias[i]-1] - 1;
		for (j = 0; j < rcategs; j++) {
			if (y > 0.0) {
				zz = tbl[j][k]->orig_zz;
				z1 = tbl[j][k]->z1;
			} else {
				zz = 1.0;
				z1 = 1.0;
			}
			zzs = -tbl[j][k]->rat * zz ;
			z1s = -tbl[j][k]->ratxv * z1 ;
			temp = tbl[j][k]->rat;
			zzc = temp * temp * zz;
			temp = tbl[j][k]->ratxv;
			z1c = temp * temp * z1;
			memcpy(x1, p->x[i][j], sizeof(sitelike));
			prod1 = freqa * x1[0] + freqc * x1[(long)C - (long)A] +
            freqg * x1[(long)G - (long)A] + freqt * x1[(long)T - (long)A];
			memcpy(x2, q->x[i][j], sizeof(sitelike));
			prod2 = freqa * x2[0] + freqc * x2[(long)C - (long)A] +
            freqg * x2[(long)G - (long)A] + freqt * x2[(long)T - (long)A];
			prod3 = (x1[0] * freqa + x1[(long)G - (long)A] * freqg) *
			(x2[0] * freqar + x2[(long)G - (long)A] * freqgr) +
			(x1[(long)C - (long)A] * freqc + x1[(long)T - (long)A] * freqt) *
			(x2[(long)C - (long)A] * freqcy + x2[(long)T - (long)A] * freqty);
			prod12 = freqa * x1[0] * x2[0] +
			freqc * x1[(long)C - (long)A] * x2[(long)C - (long)A] +
			freqg * x1[(long)G - (long)A] * x2[(long)G - (long)A] +
			freqt * x1[(long)T - (long)A] * x2[(long)T - (long)A];
			aa = prod12 - prod3;
			bb = prod3 - prod1*prod2;
			cc = prod1 * prod2;
			term[i][j] = zz * aa + z1 * bb + cc;
			slopeterm[i][j] = zzs * aa + z1s * bb;
			curveterm[i][j] = zzc * aa + z1c * bb;
		}
		
		// REDUCTION
		sumterm = 0.0;
		for (j = 0; j < rcategs; j++)
			sumterm += probcat[j] * term[i][j];
		lterm = log(sumterm) + p->underflows[i] + q->underflows[i];
		
		// PARALLEL
		for (j = 0; j < rcategs; j++) {
			term[i][j] = term[i][j] / sumterm;
			slopeterm[i][j] = slopeterm[i][j] / sumterm;
			curveterm[i][j] = curveterm[i][j] / sumterm; 
		}
		sum += aliasweight[i] * lterm;
	}
	
	// PARALLEL!
	for (i = 0; i < rcategs; i++) {
		thelike[i] = 1.0;
		theslope[i] = 0.0;
		thecurve[i] = 0.0;
	}
	for (i = 0; i < sites; i++) {
		sumc = 0.0;
		sumcs = 0.0;
		sumcc = 0.0;
		for (k = 0; k < rcategs; k++) {
			sumc += probcat[k] * thelike[k];
			sumcs += probcat[k] * theslope[k];
			sumcc += probcat[k] * thecurve[k];
		}
		sumc *= lambda;
		sumcs *= lambda;
		sumcc *= lambda;
		if ((ally[i] > 0) && (location[ally[i]-1] > 0)) {
			lai = location[ally[i] - 1];
			memcpy(clai, term[lai - 1], rcategs*sizeof(double));
			memcpy(cslai, slopeterm[lai - 1], rcategs*sizeof(double));
			memcpy(cclai, curveterm[lai - 1], rcategs*sizeof(double));
			if (weight[i] > 1) {
				for (j = 0; j < rcategs; j++) {
					if (clai[j] > 0.0)
						clai[j] = exp(weight[i]*log(clai[j]));
					else clai[j] = 0.0;
					if (cslai[j] > 0.0)
						cslai[j] = exp(weight[i]*log(cslai[j]));
					else cslai[j] = 0.0;
					if (cclai[j] > 0.0)
						cclai[j] = exp(weight[i]*log(cclai[j])); 
					else cclai[j] = 0.0;
				}
			}
			for (j = 0; j < rcategs; j++) {
				nulike[j] = ((1.0 - lambda) * thelike[j] + sumc) * clai[j];
				nuslope[j] = ((1.0 - lambda) * theslope[j] + sumcs) * clai[j]
				+ ((1.0 - lambda) * thelike[j] + sumc) * cslai[j];
				nucurve[j] = ((1.0 - lambda) * thecurve[j] + sumcc) * clai[j]
				+ 2.0 * ((1.0 - lambda) * theslope[j] + sumcs) * cslai[j]
				+ ((1.0 - lambda) * thelike[j] + sumc) * cclai[j];
			}
		} else {
			for (j = 0; j < rcategs; j++) {
				nulike[j] = ((1.0 - lambda) * thelike[j] + sumc);
				nuslope[j] = ((1.0 - lambda) * theslope[j] + sumcs);
				nucurve[j] = ((1.0 - lambda) * thecurve[j] + sumcc);
			}
		}
		memcpy(thelike, nulike, rcategs*sizeof(double));
		memcpy(theslope, nuslope, rcategs*sizeof(double));
		memcpy(thecurve, nucurve, rcategs*sizeof(double));
	}
	sum2 = 0.0;
	slope2 = 0.0;
	curve2 = 0.0;
	for (i = 0; i < rcategs; i++) {
		sum2 += probcat[i] * thelike[i];
		slope2 += probcat[i] * theslope[i];
		curve2 += probcat[i] * thecurve[i];
	}
	sum += log(sum2);
	(*like) = sum;
	(*slope) = slope2 / sum2;
	
	/* Expressed in terms of *slope to prevent overflow */
	(*curve) = curve2 / sum2 - *slope * *slope;
	
#ifdef SCTIMINGS
	get_stop_time(slopecurv_tk);
#endif
} /* slopecurv */
Exemplo n.º 25
0
double evaluate(node *p, boolean saveit)
{
#ifdef CALLCOUNT
	printf("evaluate\n");
#endif
#ifdef TIMINGS
	get_start_time(eval_tk);
#endif 
	
	contribarr tterm;
	double sum, sum2, sumc, y, lz, y1, z1zz, z1yy, prod12, prod1, prod2, prod3,
	sumterm, lterm;
	long i, j, k, lai;
	node *q;
	sitelike x1, x2;
	
	sum = 0.0;
	q = p->back;
	if ( p->initialized  == false && p->tip == false)  nuview(p);
	if ( q->initialized  == false && q->tip == false)  nuview(q);
	y = p->v;
	lz = -y;
	for (i = 0; i < rcategs; i++)
		for (j = 0; j < categs; j++) {
			tbl[i][j]->orig_zz = exp(tbl[i][j]->ratxi * lz);
			tbl[i][j]->z1 = exp(tbl[i][j]->ratxv * lz);
			tbl[i][j]->z1zz = tbl[i][j]->z1 * tbl[i][j]->orig_zz;
			tbl[i][j]->z1yy = tbl[i][j]->z1 - tbl[i][j]->z1zz;
		}
	for (i = 0; i < endsite; i++) {
		k = category[alias[i]-1] - 1;
		for (j = 0; j < rcategs; j++) {
			if (y > 0.0) {
				y1 = 1.0 - tbl[j][k]->z1;
				z1zz = tbl[j][k]->z1zz;
				z1yy = tbl[j][k]->z1yy;
			} else {
				y1 = 0.0;
				z1zz = 1.0;
				z1yy = 0.0;
			}
			memcpy(x1, p->x[i][j], sizeof(sitelike));
			prod1 = freqa * x1[0] + freqc * x1[(long)C - (long)A] +
			freqg * x1[(long)G - (long)A] + freqt * x1[(long)T - (long)A];
			memcpy(x2, q->x[i][j], sizeof(sitelike));
			prod2 = freqa * x2[0] + freqc * x2[(long)C - (long)A] +
			freqg * x2[(long)G - (long)A] + freqt * x2[(long)T - (long)A];
			prod3 = (x1[0] * freqa + x1[(long)G - (long)A] * freqg) *
			(x2[0] * freqar + x2[(long)G - (long)A] * freqgr) +
			(x1[(long)C - (long)A] * freqc + x1[(long)T - (long)A] * freqt) *
			(x2[(long)C - (long)A] * freqcy + x2[(long)T - (long)A] * freqty);
			prod12 = freqa * x1[0] * x2[0] +
			freqc * x1[(long)C - (long)A] * x2[(long)C - (long)A] +
			freqg * x1[(long)G - (long)A] * x2[(long)G - (long)A] +
			freqt * x1[(long)T - (long)A] * x2[(long)T - (long)A];
			tterm[j] = z1zz * prod12 + z1yy * prod3 + y1 * prod1 * prod2;
		}
		sumterm = 0.0;
		for (j = 0; j < rcategs; j++)
			sumterm += probcat[j] * tterm[j];
		lterm = log(sumterm) + p->underflows[i] + q->underflows[i];
		for (j = 0; j < rcategs; j++)
			clai[j] = tterm[j] / sumterm;
		memcpy(contribution[i], clai, rcategs*sizeof(double));
		if (saveit && !auto_ && usertree && (which <= shimotrees))
			l0gf[which - 1][i] = lterm;
		sum += aliasweight[i] * lterm;
	}
	for (j = 0; j < rcategs; j++)
		like[j] = 1.0;
	for (i = 0; i < sites; i++) {
		sumc = 0.0;
		for (k = 0; k < rcategs; k++)
			sumc += probcat[k] * like[k];
		sumc *= lambda;
		if ((ally[i] > 0) && (location[ally[i]-1] > 0)) {
			lai = location[ally[i] - 1];
			memcpy(clai, contribution[lai - 1], rcategs*sizeof(double));
			for (j = 0; j < rcategs; j++)
				nulike[j] = ((1.0 - lambda) * like[j] + sumc) * clai[j];
		} else {
			for (j = 0; j < rcategs; j++)
				nulike[j] = ((1.0 - lambda) * like[j] + sumc);
		}
		memcpy(like, nulike, rcategs*sizeof(double));
	}
	sum2 = 0.0;
	for (i = 0; i < rcategs; i++)
		sum2 += probcat[i] * like[i];
	sum += log(sum2);
	curtree.likelihood = sum;
	if (!saveit || auto_ || !usertree) {
#ifdef TIMINGS
		get_stop_time(eval_tk);
#endif
		return sum;
	}
	if(which <= shimotrees)
		l0gl[which - 1] = sum;
	if (which == 1) {
		maxwhich = 1;
		maxlogl = sum;
#ifdef TIMINGS
		get_stop_time(eval_tk);
#endif
		return sum;
	}
	if (sum > maxlogl) {
		maxwhich = which;
		maxlogl = sum;
	}
#ifdef TIMINGS
	get_stop_time(eval_tk);
#endif
	
	return sum;
}  /* evaluate */
Exemplo n.º 26
0
void LSMASHAudioSource::get_audio_track( const char *source, uint32_t track_number, bool skip_priming, IScriptEnvironment *env )
{
    uint32_t number_of_tracks = open_file( source, env );
    if( track_number && track_number > number_of_tracks )
        env->ThrowError( "LSMASHAudioSource: the number of tracks equals %I32u.", number_of_tracks );
    /* L-SMASH */
    uint32_t i;
    lsmash_media_parameters_t media_param;
    if( track_number == 0 )
    {
        /* Get the first audio track. */
        for( i = 1; i <= number_of_tracks; i++ )
        {
            adh.track_ID = lsmash_get_track_ID( adh.root, i );
            if( adh.track_ID == 0 )
                env->ThrowError( "LSMASHAudioSource: failed to find audio track." );
            lsmash_initialize_media_parameters( &media_param );
            if( lsmash_get_media_parameters( adh.root, adh.track_ID, &media_param ) )
                env->ThrowError( "LSMASHAudioSource: failed to get media parameters." );
            if( media_param.handler_type == ISOM_MEDIA_HANDLER_TYPE_AUDIO_TRACK )
                break;
        }
        if( i > number_of_tracks )
            env->ThrowError( "LSMASHAudioSource: failed to find audio track." );
    }
    else
    {
        /* Get the desired audio track. */
        adh.track_ID = lsmash_get_track_ID( adh.root, track_number );
        if( adh.track_ID == 0 )
            env->ThrowError( "LSMASHAudioSource: failed to find audio track." );
        lsmash_initialize_media_parameters( &media_param );
        if( lsmash_get_media_parameters( adh.root, adh.track_ID, &media_param ) )
            env->ThrowError( "LSMASHAudioSource: failed to get media parameters." );
        if( media_param.handler_type != ISOM_MEDIA_HANDLER_TYPE_AUDIO_TRACK )
            env->ThrowError( "LSMASHAudioSource: the track you specified is not an audio track." );
    }
    if( lsmash_construct_timeline( adh.root, adh.track_ID ) )
        env->ThrowError( "LSMASHAudioSource: failed to get construct timeline." );
    if( get_summaries( adh.root, adh.track_ID, &adh.config ) )
        env->ThrowError( "LSMASHAudioSource: failed to get summaries." );
    adh.frame_count = lsmash_get_sample_count_in_media_timeline( adh.root, adh.track_ID );
    vi.num_audio_samples = lsmash_get_media_duration_from_media_timeline( adh.root, adh.track_ID );
    if( skip_priming )
    {
        uint32_t itunes_metadata_count = lsmash_count_itunes_metadata( adh.root );
        for( i = 1; i <= itunes_metadata_count; i++ )
        {
            lsmash_itunes_metadata_t metadata;
            if( lsmash_get_itunes_metadata( adh.root, i, &metadata ) < 0 )
                continue;
            if( metadata.item != ITUNES_METADATA_ITEM_CUSTOM
             || (metadata.type != ITUNES_METADATA_TYPE_STRING && metadata.type != ITUNES_METADATA_TYPE_BINARY)
             || !metadata.meaning || !metadata.name
             || memcmp( "com.apple.iTunes", metadata.meaning, strlen( metadata.meaning ) )
             || memcmp( "iTunSMPB", metadata.name, strlen( metadata.name ) ) )
            {
                lsmash_cleanup_itunes_metadata( &metadata );
                continue;
            }
            char *value = NULL;
            if( metadata.type == ITUNES_METADATA_TYPE_STRING )
            {
                int length = strlen( metadata.value.string );
                if( length >= 116 )
                    value = duplicate_as_string( metadata.value.string, length );
            }
            else    /* metadata.type == ITUNES_METADATA_TYPE_BINARY */
            {
                if( metadata.value.binary.size >= 116 )
                    value = duplicate_as_string( metadata.value.binary.data, metadata.value.binary.size );
            }
            lsmash_cleanup_itunes_metadata( &metadata );
            if( !value )
                continue;
            uint32_t dummy[9];
            uint32_t priming_samples;
            uint32_t padding;
            uint64_t duration;
            if( 12 != sscanf( value, " %I32x %I32x %I32x %I64x %I32x %I32x %I32x %I32x %I32x %I32x %I32x %I32x",
                              &dummy[0], &priming_samples, &padding, &duration, &dummy[1], &dummy[2],
                              &dummy[3], &dummy[4], &dummy[5], &dummy[6], &dummy[7], &dummy[8] ) )
            {
                delete [] value;
                continue;
            }
            delete [] value;
            adh.implicit_preroll     = 1;
            aoh.skip_decoded_samples = priming_samples;
            vi.num_audio_samples = duration + priming_samples;
            break;
        }
        if( aoh.skip_decoded_samples == 0 )
        {
            uint32_t ctd_shift;
            if( lsmash_get_composition_to_decode_shift_from_media_timeline( adh.root, adh.track_ID, &ctd_shift ) )
                env->ThrowError( "LSMASHAudioSource: failed to get the timeline shift." );
            aoh.skip_decoded_samples = ctd_shift + get_start_time( adh.root, adh.track_ID );
        }
    }
    /* libavformat */
    for( i = 0; i < format_ctx->nb_streams && format_ctx->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO; i++ );
    if( i == format_ctx->nb_streams )
        env->ThrowError( "LSMASHAudioSource: failed to find stream by libavformat." );
    /* libavcodec */
    AVStream *stream = format_ctx->streams[i];
    AVCodecContext *ctx = stream->codec;
    adh.config.ctx = ctx;
    AVCodec *codec = avcodec_find_decoder( ctx->codec_id );
    if( !codec )
        env->ThrowError( "LSMASHAudioSource: failed to find %s decoder.", codec->name );
    ctx->thread_count = 0;
    if( avcodec_open2( ctx, codec, NULL ) < 0 )
        env->ThrowError( "LSMASHAudioSource: failed to avcodec_open2." );
}