Dear James, all, your hint helped a lot, thanks, James!
Dario off-list pointed me into the right direction to use sample and hold, also for fixing the (otherwise ongoing) computation. here's a working example implementing a simple state machine that evaluates only when triggered: ``` import("stdfaust.lib"); strictRising(x) = x > x'; // one-sample trigger (1) when signal passes 0 (from - to +), otherwise (0) trig1_1(x) = strictRising(x > 0); // pass new value when triggered, otherwise hold latch(trig) = _ : select2(trig1_1(trig), _, _) ~ _; triggerSignal = os.lf_squarewave(2000); // of triggered, compute new value (set) of f // initial state os always 0 or (0, 0) or ... or (0, 0, ...) demand_1(f, tr) = f ~ par(i, outputs(f), latch(tr)); statemachine(state) = states : ba.selectn(ba.count(states), state) with { states = (1, 3, 4, 8, 0, 2, 5, 7, 6); }; process = demand_1(statemachine, triggerSignal); ``` this should also work with multi-dimensional states, i.e. list of states. However, after reading this paper https://hal.archives-ouvertes.fr/hal-02159011/document (thanks for the pointer, sletz!) I think that computation still happens for every sample, despite the input value (i.e. previous state) not changing and thus the output also keeping at a constant value. Maybe an expert in faust optimisation could shed some light on this (and proof me wrong?) all the best Till -- Till Bovermann https://tai-studio.org | http://lfsaw.de | https://www.instagram.com/_lfsaw/ > On 29. Jun 2020, at 11:35, James Mckernon <jmcker...@gmail.com> wrote: > > On 6/29/20, Till Bovermann <lf...@lfsaw.de> wrote: >> Dear list, >> >> I wonder if anyone has a clue how to implement demand-rate in faust. > > Hi Till, > > Have you looked at latch and/or sAndH in basics.lib? They may be the > closest thing to what you're looking for. Either using those functions > directly or looking at their definition may help you. > > The key trick is to use a feedback loop (~) and a conditional > (select2) to create behaviour along these lines: if trigger then > output a value from a generator function; else output whatever value I > output last time. > > But faust has a quirk in how it treats the unused branch of a > conditional statement, if the branch has some kind of internal state: > it evaluates them anyway in order to update the state. In other words, > a counter (1, 2, 3...) latched to a trigger running every second > sample (1, 0, 1, 0...) will output not 1, 1, 2, 2, 3, 3... but rather > 1, 1, 3, 3, 5, 5... This may not be what you want in this case. > Unfortunately, I don't believe there's a way to escape it. > > For what it's worth, I find this very frustrating and wish there were > a way to defeat it. _______________________________________________ Faudiostream-users mailing list Faudiostream-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/faudiostream-users