Hi,
I'm new to Pd, and I'm trying to write an external and thanks to johannes' HOWTO, the process hasn't been so painful. However, I haven't found how to solve this problem (I looked the source code of the timer, pipe, and line objects that do something alike, but I'm not sure if it will work): I receive a list by one inlet and perform some computation with the data until a new list arrives or the execution reach a time limit defined by the user as a parameter of the object. The method should put whatever value it got to one outlet if it reach the deadline, and wait for new data to arrive. If data arrives before the deadline, the method should abort the ongoing computation and start doing it again with the new data. I tried this simple example to see if the mechanism will work:
void foo(t_interrupt *x){ int i=0; double timenow = clock_getlogicaltime(); post("timenow = %f",timenow); while(i<=10000) { i++; post("now = %f",clock_gettimesince(timenow)); } }
but I only get 0.0000 as outputs... Furthermore, I'm not sure if it will work. Should I make a class that implements the calculation in its own thread? or Pd's scheduling methods will do the job?...
Any help will be highly appreciated, I've spent in this quite a long time now...
Thanks in advance.
Julian Villegas
University of Aizu Synthetic Worlds Laboratory Aizu - Wakamatsu Fukushima Japan 965 - 8580
Me pregunto de un modo pensativo Que significa ser colombiano? No se le respondi. Es un acto de fe JLB. --------------------------------- Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.
Hallo, Julian Villegas hat gesagt: // Julian Villegas wrote:
I receive a list by one inlet and perform some computation with the data until a new list arrives or the execution reach a time limit defined by the user as a parameter of the object. The method should put whatever value it got to one outlet if it reach the deadline, and wait for new data to arrive. If data arrives before the deadline, the method should abort the ongoing computation and start doing it again with the new data. I tried this simple example to see if the mechanism will work:
void foo(t_interrupt *x){ int i=0; double timenow = clock_getlogicaltime(); post("timenow = %f",timenow); while(i<=10000) { i++; post("now = %f",clock_gettimesince(timenow)); } }
but I only get 0.0000 as outputs...
Thank god you get zero: Logically no time passed between the call to the "foo" function and the time, when it is finished with counting to 10000 or to 1000000000000000000000000000.
That's how most objects in Pd work: It doesn't matter, how long something like the [cos] object takes on a specific machine to calculate the cosine, the result is assumed to be there immediatly. If it should not be there immediately you need a clock, see below.
You could use "sys_getrealtime" to get the real time a calculation took, however if you want to delay the time your object takes for outputting its computation's results you need something like [metro] or [del] do. You may look a its source in x_time.c, where you see that metro has a "metro_tick" method and also its own clock, created with "clock_new" and delayed with "clock_delay".
Furthermore, I'm not sure if it will work. Should I make a class that implements the calculation in its own thread? or Pd's scheduling methods will do the job?...
This depends on what exactly you want to do. You can delay actions using the Pd clock, however I think, if you want an ongoing calculation you may indeed need a thread. But I don't know that area in Pd very well, so you and I should better wait for others to answer this.
Ciao