Ejemplo n.º 1
0
static int __cmd_timechart(void)
{
	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
	int ret;

	if (session == NULL)
		return -ENOMEM;

	register_perf_file_handler(&file_handler);

	ret = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
	if (ret)
		goto out_delete;

	process_samples();

	end_sample_processing();

	sort_pids();

	write_svg_file(output_name);

	pr_info("Written %2.1f seconds of trace to %s.\n",
		(last_time - first_time) / 1000000000.0, output_name);
out_delete:
	perf_session__delete(session);
	return ret;
}
Ejemplo n.º 2
0
static void *synth_thread(void *arg)
{
    while (1) {
	sem_wait(&syn_sem);
	pthread_mutex_lock(&syn_mtx);
	if (!output_running) {
		pthread_mutex_unlock(&syn_mtx);
		continue;
	}
	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
	process_samples(GETusTIME(0), FLUS_MIN_BUF);
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	pthread_mutex_unlock(&syn_mtx);
    }
    return NULL;
}
Ejemplo n.º 3
0
static void thread_loop(void *arg)
{
    struct example_sink_userdata *u = arg;
    pa_assert(u);

    pa_thread_mq_install(&u->thread_mq);

    const pa_usec_t poll_interval = 10000;

    pa_usec_t start_time = 0;
    pa_usec_t next_time = 0;

    for (;;) {
        /* process rewind */
        if (u->sink->thread_info.rewind_requested) {
            process_rewind(u);
        }

        /* process sink inputs */
        if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
            pa_usec_t now_time = pa_rtclock_now();

            if (start_time == 0) {
                start_time = now_time;
                next_time = start_time + poll_interval;
            }
            else {
                while (now_time >= next_time) {
                    uint64_t expected_bytes =
                        pa_usec_to_bytes(next_time - start_time, &u->sink->sample_spec);

                    /* render samples from sink inputs and write them to output file */
                    process_samples(u, expected_bytes);

                    /* next tick */
                    next_time += poll_interval;
                }
            }

            /* schedule set next rendering tick */
            pa_rtpoll_set_timer_absolute(u->rtpoll, next_time);
        }
        else {
            /* sleep until state change */
            start_time = 0;
            next_time = 0;
            pa_rtpoll_set_timer_disabled(u->rtpoll);
        }

        /* process events and wait next rendering tick */
#if PA_CHECK_VERSION(5, 99, 0)
        int ret = pa_rtpoll_run(u->rtpoll);
#else
        int ret = pa_rtpoll_run(u->rtpoll, true);
#endif
        if (ret < 0) {
            pa_log("[example sink] pa_rtpoll_run returned error");
            goto error;
        }

        if (ret == 0) {
            break;
        }
    }

    return;

error:
    process_error(u);
}
Ejemplo n.º 4
0
PRIVATE void
run_swch(unsigned int thread)
{
	int i, n = top[thread].hold.size.frames;
	REAL w;
//	static int count = 0;

	process_samples(top[thread].hold.buf.l, top[thread].hold.buf.r,
		top[thread].hold.aux.l, top[thread].hold.aux.r,
		top[thread].hold.size.frames, thread);

	for (i = 0; i < n; i++)
	{
//		count++;
		if (top[thread].swch.env.curr.type == SWCH_FALL)
		{
			top[thread].swch.env.curr.val += top[thread].swch.env.fall.incr;
			w = (REAL)sin(top[thread].swch.env.curr.val * M_PI /  2.0f);
			top[thread].hold.buf.l[thread] *= w, top[thread].hold.buf.r[thread] *= w;
			top[thread].hold.aux.l[thread] *= w, top[thread].hold.aux.r[thread] *= w;
//			if (top[thread].swch.env.curr.cnt == 0) fprintf(stderr, "FALL\n"),fflush(stderr);
//			if(top[thread].swch.env.curr.cnt == 0) top[thread].hold.buf.l[thread] = top[thread].hold.buf.r[thread] = -1.0;
			if (++top[thread].swch.env.curr.cnt >= top[thread].swch.env.fall.size)
			{
				//top[thread].hold.buf.l[thread] = top[thread].hold.buf.r[thread] = -1.0;
				top[thread].swch.env.curr.type = SWCH_STDY;
				top[thread].swch.env.curr.cnt = 0;
				top[thread].swch.env.curr.val = 0.0;
//				fprintf(stderr, "Fall End: %d\n", count);
			}
		}
		else if (top[thread].swch.env.curr.type == SWCH_STDY)
		{
			top[thread].hold.buf.l[i]= top[thread].hold.buf.r[i] =
				top[thread].hold.aux.l[i] =  top[thread].hold.aux.r[i] = 0.0;
//			if (top[thread].swch.env.curr.cnt == 0) fprintf(stderr, "STDY\n"),fflush(stderr);
			if (++top[thread].swch.env.curr.cnt >= top[thread].swch.env.stdy.size)
			{
//				top[thread].hold.buf.l[thread] = top[thread].hold.buf.r[thread] = -1.0;
				top[thread].swch.env.curr.type = SWCH_RISE;
				top[thread].swch.env.curr.cnt = 0;
				top[thread].swch.env.curr.val = 0.0;
//				fprintf(stderr, "Stdy End: %d\n", count);
			}
		}
		else if (top[thread].swch.env.curr.type == SWCH_RISE)
		{
			top[thread].swch.env.curr.val += top[thread].swch.env.rise.incr;
			w = (REAL)sin(top[thread].swch.env.curr.val * M_PI /  2.0f);
			top[thread].hold.buf.l[i] *= w, top[thread].hold.buf.r[i] *= w;
			top[thread].hold.aux.l[i] *= w, top[thread].hold.aux.r[i] *= w;
//			if (top[thread].swch.env.curr.cnt == 0) fprintf(stderr, "RISE\n"),fflush(stderr);
			if (++top[thread].swch.env.curr.cnt >= top[thread].swch.env.rise.size)
			{
//				reset_meters();
//				reset_spectrum();
//				reset_counters();
	
				uni[thread].mode.trx = top[thread].swch.trx.next;
				top[thread].state = top[thread].swch.run.last;
				break;
//				fprintf(stderr, "Rise End: %d\n", count);
			}
		}
	}
}
Ejemplo n.º 5
0
PRIVATE void
run_play (unsigned int thread)
{
	process_samples (top[thread].hold.buf.l, top[thread].hold.buf.r,
		top[thread].hold.aux.l, top[thread].hold.aux.r, top[thread].hold.size.frames, thread);
}
Ejemplo n.º 6
0
PRIVATE void
run_swch(unsigned int thread)
{
	int i, n = top[thread].hold.size.frames;
	REAL w;
//	static int count = 0;

	for (i = 0; i < n; i++)
	{
//		count++;
		switch(top[thread].swch.env.curr.type)
		{
		case SWCH_FALL:
			top[thread].swch.env.curr.val += top[thread].swch.env.fall.incr;
			w = (REAL)sin(top[thread].swch.env.curr.val * M_PI /  2.0f);
			top[thread].hold.buf.l[thread] *= w, top[thread].hold.buf.r[thread] *= w;
			top[thread].hold.aux.l[thread] *= w, top[thread].hold.aux.r[thread] *= w;
//			if (top[thread].swch.env.curr.cnt == 0) fprintf(stderr, "FALL\n"),fflush(stderr);
//			if(top[thread].swch.env.curr.cnt == 0) top[thread].hold.buf.l[thread] = top[thread].hold.buf.r[thread] = -1.0;
			if (++top[thread].swch.env.curr.cnt >= top[thread].swch.env.fall.size)
			{
				//top[thread].hold.buf.l[thread] = top[thread].hold.buf.r[thread] = -1.0;
				top[thread].swch.env.curr.type = SWCH_STDY;
				top[thread].swch.env.curr.cnt = 0;
				top[thread].swch.env.curr.val = 0.0;
//				fprintf(stderr, "Fall End: %d\n", count);
			}
			break;

		case SWCH_STDY:		
			top[thread].hold.buf.l[i]= top[thread].hold.buf.r[i] =
				top[thread].hold.aux.l[i] =  top[thread].hold.aux.r[i] = 0.0;
//			if (top[thread].swch.env.curr.cnt == 0) fprintf(stderr, "STDY\n"),fflush(stderr);
			if (++top[thread].swch.env.curr.cnt >= top[thread].swch.env.stdy.size)
			{
//				top[thread].hold.buf.l[thread] = top[thread].hold.buf.r[thread] = -1.0;
				top[thread].swch.env.curr.type = SWCH_RISE;
				top[thread].swch.env.curr.cnt = 0;
				top[thread].swch.env.curr.val = 0.0;
//				fprintf(stderr, "Stdy End: %d\n", count);
			}
			break;
		
		case SWCH_RISE:
			if(!top[thread].swch.rise_thresh.flag)
			{
				top[thread].swch.rise_thresh.count++;
				if((abs(top[thread].hold.buf.l[i]) > top[thread].swch.rise_thresh.threshold ||
					abs(top[thread].hold.buf.r[i]) > top[thread].swch.rise_thresh.threshold) ||
					top[thread].swch.rise_thresh.count == top[thread].swch.rise_thresh.count_limit)
				top[thread].swch.rise_thresh.flag = TRUE;
			}
				
			if(top[thread].swch.rise_thresh.flag)
			{
				top[thread].swch.env.curr.val += top[thread].swch.env.rise.incr;
				w = 1.0f - (REAL)cos(top[thread].swch.env.curr.val * M_PI / 2.0f);				

				top[thread].hold.buf.l[i] *= w, top[thread].hold.buf.r[i] *= w;
				top[thread].hold.aux.l[i] *= w, top[thread].hold.aux.r[i] *= w;

				/*if(top[thread].swch.env.curr.cnt == 0)
				{
					top[thread].hold.buf.l[i] = 1.0;
					top[thread].hold.buf.r[i] = 1.0;
				}*/

	//			if (top[thread].swch.env.curr.cnt == 0) fprintf(stderr, "RISE\n"),fflush(stderr);
				if (++top[thread].swch.env.curr.cnt >= top[thread].swch.env.rise.size)
				{
					//top[thread].hold.buf.l[i] = 1.0;
					//top[thread].hold.buf.r[i] = 1.0;

	//				reset_meters();
	//				reset_spectrum();
	//				reset_counters();
		
					//uni[thread].mode.trx = top[thread].swch.trx.next;
					top[thread].state = top[thread].swch.run.last;
					return;
	//				fprintf(stderr, "Rise End: %d\n", count);
				}
			}
			else
			{
				top[thread].hold.buf.l[i] = 0.0f;
				top[thread].hold.buf.r[i] = 0.0f;
			}
			break;
		}
	}

	process_samples(top[thread].hold.buf.l, top[thread].hold.buf.r,
		top[thread].hold.aux.l, top[thread].hold.aux.r,
		top[thread].hold.size.frames, thread);
}