To expand on Miller's reply:

Conceptually, messaging and DSP are two separate domains. Sending a message from a perform routine violates this separation. Instead you should use a clock with delay 0 to defer the message to the begin of the next scheduler tick.

Miller already mentioned the greatest danger, but there are other, more subtle issues. DSP objects typically operate on the premise that the object's state won't change from the outside during the perform routine. For example, imagine a delay object with a buffer that can be resized with a message; by sending a Pd message from the perform routine, it might accidentally feed back into the object and reallocate the buffer while still in progress.

Unfortunately, very little of this is documented. Ideally, this should be covered in the externals-how-to (https://github.com/pure-data/externals-howto); I just added an item on my (long) TODO list.

Finally, although Pd is currently single-threaded, this could change in the future. FWIW, here is a PoC for multi-threaded DSP: https://github.com/spacechild1/pure-data/tree/multi-threading. This is only possible because perform routines may only use a restricted set of API functions - which, in my fork, are annoted with the (empty) THREADSAFE macro (and made thread-safe, if necessary).

Christof

On 21.08.2023 20:55, Joseph Larralde wrote:
Hmm, I see ... unfortunately my random bug is totally unrelated to this weakness of my code.
Thanks Miller for the explanation and pointers to examples !
And thanks Claude for the extra example.
I'll check all my objects to see if there are other ones I can consolidate.

Cheers !

Joseph

Le 21/08/2023 à 19:08, Claude Heiland-Allen a écrit :
See bang~ in pure-data/src/d_misc.c for an example that uses a clock to send a message from DSP.

On 21/08/2023 18:02, Miller Puckette wrote:
The built-in objects "delay", "metro" and "pipe" use clocks in various ways.

On 8/21/23 18:02, Joseph Larralde wrote:
I just read in an answer from Christof to Alexandre : "never ever send a Pd message directly from a perform routine ! Always use a clock !"




_______________________________________________
Pd-dev mailing list
Pd-dev@lists.iem.at
https://lists.puredata.info/listinfo/pd-dev




_______________________________________________
Pd-dev mailing list
Pd-dev@lists.iem.at
https://lists.puredata.info/listinfo/pd-dev



_______________________________________________
Pd-dev mailing list
Pd-dev@lists.iem.at
https://lists.puredata.info/listinfo/pd-dev

Reply via email to