Exemplo n.º 1
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;
  sys_microsleep(0);
  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;
}
Exemplo n.º 2
0
int libpd_process_raw(const float *inBuffer, float *outBuffer) {
  size_t n_in = STUFF->st_inchannels * DEFDACBLKSIZE;
  size_t n_out = STUFF->st_outchannels * DEFDACBLKSIZE;
  t_sample *p;
  size_t i;
  sys_lock();
  sys_microsleep(0);
  for (p = STUFF->st_soundin, i = 0; i < n_in; i++) {
    *p++ = *inBuffer++;
  }
  memset(STUFF->st_soundout, 0, n_out * sizeof(t_sample));
  SCHED_TICK(pd_this->pd_systime + STUFF->st_time_per_dsp_tick);
  for (p = STUFF->st_soundout, i = 0; i < n_out; i++) {
    *outBuffer++ = *p++;
  }
  sys_unlock();
  return 0;
}
Exemplo n.º 3
0
/* take the scheduler forward one DSP tick, also handling clock timeouts */
void sched_tick(double next_sys_time)
{
    int countdown = 5000;
    while (clock_setlist && clock_setlist->c_settime < next_sys_time)
    {
        t_clock *c = clock_setlist;
        sys_time = c->c_settime;
        clock_unset(clock_setlist);
        outlet_setstacklim();
        (*c->c_fn)(c->c_owner);
        if (!countdown--)
        {
            countdown = 5000;
            sys_pollgui();
        }
        if (sys_quit)
            return;
    }
    sys_time = next_sys_time;
    dsp_tick();
    sched_diddsp++;
    sys_microsleep(0);
}
Exemplo n.º 4
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
}