Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Period function calls

Hi all,

The attached image isn't intended to win any design contests but shows an old bit of code in a traditional QSM type arrangement for generating some tones and sending them to the sound card and a plot. Because the Sound Output Write.vi waits until the data has been played, the code just keeps calling the 'Running' state over and over again, until someone presses stop.

To implement this in the AF world I can:

-  Still have a similar running state that calls itself, but I realise this is a bit of a no-no and stopping the playback is messy.

- Use the Time Delayed Send Message vi to queue up infinite 'play' methods every 0.5s but that is not straightforward in this use case - set the period too slow and there are gaps in the playback, too fast and I end up with duplicated messages in the queue. 

- Have a separate while loop in Actor Core that just handles the playback. I like this idea but then I have to have another messanging arrangement to tell it what to play etc as it can't access the uptodate class data, which seems a shame when I have the AF messaging right there.

-Do the above option but with a by-reference class which holds the up to date values for the playback array, volume etc.

Can anyone shed any light please?

Thanks,

Martin

0 Kudos
Message 1 of 5
(3,745 Views)

I would write such a thing with a separate loop controlled by a notifier, the notifier containing all the information that the loop needs to do its task.  The notifier would be written to by the message-handling loop.

0 Kudos
Message 2 of 5
(3,146 Views)

-  Still have a similar running state that calls itself, but I realise this is a bit of a no-no and stopping the playback is messy.

This would also work, providing that the execution time of your playback action is "fast" relative to the time you need for message responsivness.  Stopping should be trivial (you just need a flag for current state that the playback action consults).

0 Kudos
Message 3 of 5
(3,146 Views)

Ah, thank you - I like the idea of using a notifier, I'll give that a go now.

0 Kudos
Message 4 of 5
(3,146 Views)

I have done this elsewhere in the project and as you say it does work, my loops are fed by data being read in at 0.25s intervals so it stays quite snappy. However I will try the separate helper loop with the notifier as I'm keen to keep the loop times as constant as possible.  Thanks very much for the tips, much appreciated.

0 Kudos
Message 5 of 5
(3,146 Views)