Exemple #1
0
int m_batchmain(void)
{
    sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
        ((double)sys_schedblocksize) / sys_dacsr;
    while (sys_quit != SYS_QUIT_QUIT)
        sched_tick(sys_time + sys_time_per_dsp_tick);
    return (0);
}
Exemple #2
0
/*
 * Called when a sync timestamp packet
 * is received from the main brain. Resyncs the
 * scheduler if it is asynchronous.
 */
void sched_sync(void){
  if (sched_status == SCHED_RUNNING_ASYNC){
    error_occurred(ERROR_SCHED_RESYNC, PRIORITY_HIGH);
    sched_status = SCHED_RUNNING_SYNC;
  }
  sched_aux_count = 0;
  sched_sync_count = 0;
  sched_tick();
}
Exemple #3
0
void sched_audio_callbackfn(void)
{
    sys_setmiditimediff(0, 1e-6 * sys_schedadvance);
    sys_addhist(1);
    sched_tick(sys_time + sys_time_per_dsp_tick);
    sys_addhist(2);
    sys_pollmidiqueue();
    sys_addhist(3);
    sys_pollgui();
    sys_addhist(5);
    sched_pollformeters();
    sys_addhist(0);
}
Exemple #4
0
/*
 * Called by the auxiliary timer to provide
 * backup ticks if asynchronous
 */
void sched_auxiliary_tick(){
  
  sched_aux_count++;
  sched_sync_count++;
  
  if (sched_status == SCHED_NOT_RUNNING){
    sched_status = SCHED_RUNNING_SYNC;
  }
  
  // ******** SYNC ********* //
  if (sched_status == SCHED_RUNNING_SYNC){
    //increase timestamp if match
    if (sched_aux_count >= sched_aux_match){
      sched_timestamp++;
      sched_aux_count = 0;
    } //in sync, don't expect sync yet, so sched_tick
    if (sched_sync_count < sched_sync_match){ 
      sched_aux_reset_timer();
      sched_tick(); 
    } //expected sync, go async and sched_tick
    else if (sched_sync_count > sched_sync_match){ 
      sched_aux_reset_timer();
      error_occurred(ERROR_SCHED_ASYNC, PRIORITY_HIGH);
      sched_status = SCHED_RUNNING_ASYNC;
      sched_aux_count = 0;
      sched_tick();
    } 
  } //******* ASYNC *******//
  else if (sched_status == SCHED_RUNNING_ASYNC){
    sched_aux_reset_timer();
    //increase timestamp if match
    if (sched_aux_count >= sched_aux_match){
      sched_timestamp++;
      sched_aux_count = 0;
    } //running async, so always generate tick
    sched_tick();
  }
}
Exemple #5
0
int libpd_process_raw(const float *inBuffer, float *outBuffer) {
  size_t n_in = sys_inchannels * DEFDACBLKSIZE;
  size_t n_out = sys_outchannels * DEFDACBLKSIZE;
  t_sample *p;
  size_t i;
  for (p = sys_soundin, i = 0; i < n_in; i++) {
    *p++ = *inBuffer++;
  }
  memset(sys_soundout, 0, n_out * sizeof(t_sample));
  sched_tick(sys_time + sys_time_per_dsp_tick);
  for (p = sys_soundout, i = 0; i < n_out; i++) {
    *outBuffer++ = *p++;
  }
  return 0;
}
 void Instance::performDsp(int nsamples, const int nins, const float** inputs, const int nouts, float** outputs) noexcept
 {
     for(int i = 0; i < nsamples; i += DEFDACBLKSIZE)
     {
         for(int j = 0; j < nins; j++)
         {
             memcpy(sys_soundin+j*DEFDACBLKSIZE, inputs[j]+i, DEFDACBLKSIZE * sizeof(t_sample));
         }
         memset(sys_soundout, 0, DEFDACBLKSIZE * sizeof(t_sample) * nouts);
         sched_tick();
         for(int j = 0; j < nouts; j++)
         {
             memcpy(outputs[j]+i, sys_soundout+j*DEFDACBLKSIZE, DEFDACBLKSIZE * sizeof(t_sample));
         }
     }
 }
Exemple #7
0
/*
 * The real-time timer, interrupting hz times per second.
 */
void
hardclock(struct clockframe *frame)
{
	struct lwp *l;
	struct cpu_info *ci;

	ci = curcpu();
	l = ci->ci_data.cpu_onproc;

	timer_tick(l, CLKF_USERMODE(frame));

	/*
	 * If no separate statistics clock is available, run it from here.
	 */
	if (stathz == 0)
		statclock(frame);
	/*
	 * If no separate schedclock is provided, call it here
	 * at about 16 Hz.
	 */
	if (schedhz == 0) {
		if ((int)(--ci->ci_schedstate.spc_schedticks) <= 0) {
			schedclock(l);
			ci->ci_schedstate.spc_schedticks = hardscheddiv;
		}
	}
	if ((--ci->ci_schedstate.spc_ticks) <= 0)
		sched_tick(ci);

	if (CPU_IS_PRIMARY(ci)) {
		hardclock_ticks++;
		tc_ticktock();
	}

	/*
	 * Update real-time timeout queue.
	 */
	callout_hardclock();

#ifdef KDTRACE_HOOKS
	cyclic_clock_func_t func = cyclic_clock_func[cpu_index(ci)];
	if (func) {
		(*func)((struct clockframe *)frame);
	}
#endif
}
Exemple #8
0
/*
 * Handle clock interrupts.
 *
 * timer_handler() is called directly from the real time clock
 * interrupt.  All interrupts are still disabled at the entry
 * of this routine.
 */
void
timer_handler(void)
{
	struct timer *tmr;
	u_long ticks;
	int wakeup = 0;

	/*
	 * Bump time in ticks.
	 * Note that it is allowed to wrap.
	 */
	lbolt++;
	if (curthread->priority == PRI_IDLE)
		idle_ticks++;

	while (!list_empty(&timer_list)) {
		/*
		 * Check timer expiration.
		 */
		tmr = timer_next(&timer_list);
		if (time_before(lbolt, tmr->expire))
			break;

		list_remove(&tmr->link);
		if (tmr->interval != 0) {
			/*
			 * Periodic timer - reprogram timer again.
			 */
			ticks = time_remain(tmr->expire + tmr->interval);
			timer_add(tmr, ticks);
			sched_wakeup(&tmr->event);
		} else {
			/*
			 * One-shot timer
			 */
			list_insert(&expire_list, &tmr->link);
			wakeup = 1;
		}
	}
	if (wakeup)
		sched_wakeup(&timer_event);

	sched_tick();
}
Exemple #9
0
static void m_callbackscheduler(void)
{
    sys_initmidiqueue();
    while (!sys_quit)
    {
        double timewas = pd_this->pd_systime;
#ifdef _WIN32
        Sleep(1000);
#else
        sleep(1);
#endif
        if (pd_this->pd_systime == timewas)
        {
            sys_lock();
            sys_pollgui();
            sched_tick();
            sys_unlock();
        }
        if (sys_idlehook)
            sys_idlehook();
    }
}
Exemple #10
0
static void m_callbackscheduler(void)
{
    sys_initmidiqueue();
    while (!sys_quit)
    {
        double timewas = sys_time;
#ifdef MSW
        Sleep(1000);
#else
        sleep(1);
#endif
        if (sys_time == timewas)
        {
            sys_lock();
            sys_pollgui();
            sched_tick(sys_time + sys_time_per_dsp_tick);
            sys_unlock();
        }
        if (sys_idlehook)
            sys_idlehook();
    }
}
Exemple #11
0
void loader_tick() {
  int new_current_pid = sched_tick();
  if (new_current_pid != cur_pid) {
    loader_switchto(new_current_pid);
  }
}
Exemple #12
0
static void m_pollingscheduler( void)
{
    int idlecount = 0;
    sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
        ((double)sys_schedblocksize) / sys_dacsr;

#ifdef THREAD_LOCKING
        sys_lock();
#endif

    sys_clearhist();
    if (sys_sleepgrain < 100)
        sys_sleepgrain = sys_schedadvance/4;
    if (sys_sleepgrain < 100)
        sys_sleepgrain = 100;
    else if (sys_sleepgrain > 5000)
        sys_sleepgrain = 5000;
    sys_initmidiqueue();
    while (!sys_quit)
    {
        int didsomething = 0;
        int timeforward;

        sys_addhist(0);
    waitfortick:
        if (sched_useaudio != SCHED_AUDIO_NONE)
        {
#ifdef THREAD_LOCKING
            /* T.Grill - send_dacs may sleep -> 
                unlock thread lock make that time available 
                - could messaging do any harm while sys_send_dacs is running?
            */
            sys_unlock();
#endif
            timeforward = sys_send_dacs();
#ifdef THREAD_LOCKING
            /* T.Grill - done */
            sys_unlock();
#endif
                /* if dacs remain "idle" for 1 sec, they're hung up. */
            if (timeforward != 0)
                idlecount = 0;
            else
            {
                idlecount++;
                if (!(idlecount & 31))
                {
                    static double idletime;
                    if (sched_useaudio != SCHED_AUDIO_POLL)
                    {
                            bug("m_pollingscheduler\n");
                            return;
                    }
                        /* on 32nd idle, start a clock watch;  every
                        32 ensuing idles, check it */
                    if (idlecount == 32)
                        idletime = sys_getrealtime();
                    else if (sys_getrealtime() - idletime > 1.)
                    {
                        post("audio I/O stuck... closing audio\n");
                        sys_close_audio();
                        sched_set_using_audio(SCHED_AUDIO_NONE);
                        goto waitfortick;
                    }
                }
            }
        }
        else
        {
            if (1000. * (sys_getrealtime() - sched_referencerealtime)
                > clock_gettimesince(sched_referencelogicaltime))
                    timeforward = SENDDACS_YES;
            else timeforward = SENDDACS_NO;
        }
        sys_setmiditimediff(0, 1e-6 * sys_schedadvance);
        sys_addhist(1);
        if (timeforward != SENDDACS_NO)
            sched_tick(sys_time + sys_time_per_dsp_tick);
        if (timeforward == SENDDACS_YES)
            didsomething = 1;

        sys_addhist(2);
        sys_pollmidiqueue();
        if (sys_pollgui())
        {
            if (!didsomething)
                sched_didpoll++;
            didsomething = 1;
        }
        sys_addhist(3);
            /* test for idle; if so, do graphics updates. */
        if (!didsomething)
        {
            sched_pollformeters();
            sys_reportidle();
#ifdef THREAD_LOCKING
            sys_unlock();   /* unlock while we idle */
#endif
                /* call externally installed idle function if any. */
            if (!sys_idlehook || !sys_idlehook())
            {
                    /* if even that had nothing to do, sleep. */
                if (timeforward != SENDDACS_SLEPT)
                    sys_microsleep(sys_sleepgrain);
            }
#ifdef THREAD_LOCKING
            sys_lock();
#endif
            sys_addhist(5);
            sched_didnothing++;
        }
    }

#ifdef THREAD_LOCKING
    sys_unlock();
#endif
}
Exemple #13
0
int pd_extern_sched(char *flags)
{
    int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
    int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
    int i, j, rate, advance, callback, chin, chout, fill = 0, c, blocksize;
    t_binbuf *b = binbuf_new();

    sys_get_audio_params(&naudioindev, audioindev, chindev,
        &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback,
            &blocksize);

    chin = (naudioindev < 1 ? 0 : chindev[0]);
    chout = (naudiooutdev < 1 ? 0 : choutdev[0]);

    /* fprintf(stderr, "Pd plug-in scheduler called, chans %d %d, sr %d\n",
        chin, chout, (int)rate); */
    sys_setchsr(chin, chout, rate);
    sys_audioapi = API_NONE;
    while ((c = getchar()) != EOF)
    {
        if (c == ';')
        {
            int n;
            t_atom *ap;
            binbuf_text(b, inbuf, fill);
            n = binbuf_getnatom(b);
            ap = binbuf_getvec(b);
            fill = 0;
            if (n > 0 && ap[0].a_type == A_FLOAT)
            {
                /* a list -- take it as incoming signals. */
                int chan, nchan = n/DEFDACBLKSIZE;
                t_sample *fp;
                for (i = chan = 0, fp = sys_soundin; chan < nchan; chan++)
                    for (j = 0; j < DEFDACBLKSIZE; j++)
                        *fp++ = atom_getfloat(ap++);
                for (; chan < chin; chan++)
                    for (j = 0; j < DEFDACBLKSIZE; j++)
                        *fp++ = 0;
                sched_tick(sys_time+sys_time_per_dsp_tick);
                sys_pollgui();
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
                pollwatchdog();
#endif
                printf(";\n");
                for (i = chout*DEFDACBLKSIZE, fp = sys_soundout; i--; fp++)
                {
                    printf("%g\n", *fp);
                    *fp = 0;
                }
                printf(";\n");
                fflush(stdout);
            }
            else if (n > 1 && ap[0].a_type == A_SYMBOL)
            {
                t_pd *whom = ap[0].a_w.w_symbol->s_thing;
                if (!whom)
                    error("%s: no such object", ap[0].a_w.w_symbol->s_name);
                else if (ap[1].a_type == A_SYMBOL)
                    typedmess(whom, ap[1].a_w.w_symbol, n-2, ap+2);
                else pd_list(whom, 0, n-1, ap+1);
            }
        }
        else if (fill < BUFSIZE)
            inbuf[fill++] = c;
        else if (fill == BUFSIZE)
            fprintf(stderr, "pd-extern: input buffer overflow\n");
    }
    return (0);
}
Exemple #14
0
int pd_extern_sched(char *flags)
{
    int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
    int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
    int i, j, rate, advance, callback, chin, chout, fill = 0, c, blocksize,
        useascii = 0;
    t_binbuf *b = binbuf_new();

    sys_get_audio_params(&naudioindev, audioindev, chindev,
        &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback,
            &blocksize);

    chin = (naudioindev < 1 ? 0 : chindev[0]);
    chout = (naudiooutdev < 1 ? 0 : choutdev[0]);
    if (!flags || flags[0] != 'a')
    {
            /* signal to stdout object to do binary by attaching an object
            to an obscure symbol name */
        pd_ambinary_class = class_new(gensym("pd~"), 0, 0, sizeof(t_pd),
            CLASS_PD, 0);
        pd_bind(&pd_ambinary_class, gensym("#pd_binary_stdio"));
            /* On Windows, set stdin and out to "binary" mode */
#ifdef _WIN32
        setmode(fileno(stdout),O_BINARY);
        setmode(fileno(stdin),O_BINARY);
#endif
    }
    else
    {
        if (!(ascii_inbuf = getbytes(BUFSIZE)))
            return (1);
        useascii = 1;
    }
    /* fprintf(stderr, "Pd plug-in scheduler called, chans %d %d, sr %d\n",
        chin, chout, (int)rate); */
    sys_setchsr(chin, chout, rate);
    sys_audioapi = API_NONE;
    while (useascii ? readasciimessage(b) : readbinmessage(b) )
    {
        t_atom *ap = binbuf_getvec(b);
        int n = binbuf_getnatom(b);
        if (n > 0 && ap[0].a_type == A_FLOAT)
        {
            /* a list -- take it as incoming signals. */
            int chan, nchan = n/DEFDACBLKSIZE;
            t_sample *fp;
            for (i = chan = 0, fp = STUFF->st_soundin; chan < nchan; chan++)
                for (j = 0; j < DEFDACBLKSIZE; j++)
                    *fp++ = atom_getfloat(ap++);
            for (; chan < chin; chan++)
                for (j = 0; j < DEFDACBLKSIZE; j++)
                    *fp++ = 0;
            sched_tick();
            sys_pollgui();
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)\
     || defined(__GNU__)
            pollwatchdog();
#endif
            if (useascii)
                printf(";\n");
            else putchar(A_SEMI);
            for (i = chout*DEFDACBLKSIZE, fp = STUFF->st_soundout; i--;
                fp++)
            {
                if (useascii)
                    printf("%g\n", *fp);
                else pd_tilde_putfloat(*fp, stdout);
                *fp = 0;
            }
            if (useascii)
                printf(";\n");
            else putchar(A_SEMI);
            fflush(stdout);
        }
        else if (n > 1 && ap[0].a_type == A_SYMBOL)
        {
            t_pd *whom = ap[0].a_w.w_symbol->s_thing;
            if (!whom)
                error("%s: no such object", ap[0].a_w.w_symbol->s_name);
            else if (ap[1].a_type == A_SYMBOL)
                typedmess(whom, ap[1].a_w.w_symbol, n-2, ap+2);
            else pd_list(whom, 0, n-1, ap+1);
        }
    }
    binbuf_free(b);
    return (0);
}