[PD-dev] libpd blues
Tom Schouten
doelie at zzz.kotnet.org
Sun Nov 21 12:33:10 CET 2004
hi all,
i'm libifying pd and ran into some problems. i decided to
jump to the problem uninformed, as usual, so.. :))
my goal is to have a (gui-less) pd as a callback in another
program. currently i'm happy if it just runs in packet forth
as part of the VM zoo.
it should 'behave' in a sense that it should not execute any
blocking calls, and leave the time keeping to the host program.
the idea is that m_scheduler_tick() is called for each
64 audio sample block, and all the other things that need to
be done should be executed in this tick method.
i got most of it running, only the time keeping seems to do
something else than i think it does. this is what i sort of
works for me:
-- in m_sched.c, i reduced the scheduler to:
void m_scheduler_init(void){
sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
((double)sys_schedblocksize) / sys_dacsr;
post("timeunitspersec = %f", (float)TIMEUNITPERSEC);
post("sys_schedblocksize = %f", (float)sys_schedblocksize);
post("sys_dacsr = %f", (float)sys_dacsr);
sys_clearhist(); // not used
sys_initmidiqueue(); // not used
}
int m_scheduler_tick(void){
sys_setmiditimediff(0, 1e-6 * sys_schedadvance);
sched_tick(sys_time + sys_time_per_dsp_tick * 8.0);
sys_pollmidiqueue();
sys_microsleep(1); // poll file descriptors
}
-- when i link libpd to pd.c (mini-pd host) using this:
int main(int argc, char **argv)
{
int retval;
if ((retval = sys_main(argc, argv))) return retval;
m_scheduler_init();
while(1){
m_scheduler_tick();
//usleep(1);
}
}
--
i added a new audio driver, which is just fills in
some values to keep pd happy, but the scheduler does
not call send_dacs. (the idea is that the tick method
does the sys_soundin -> sys_soundout step)
now, the strange things are:
* the 8.0 i needed to add in m_scheduler_tick()
maybe there's a global variable i missed somewhere?
* sys_microsleep(1) works, but sys_microsleep(0) does not
this seems strange, since it only polls?
* if i add the usleep in main(), timing is off again.
this seems completely strange to me
all very distorted and i'm probably missing something obvious..
so, the question is: how do i update pd time properly
if i run pd synchronous by calling something like m_scheduler_tick() ?
cheers
tom
More information about the Pd-dev
mailing list