Ok, I think I see it now. No, the compiler does not commute smooth() with nonlinear functions, and this is the right thing in general. However, in many cases such as this, it would be nice to have a smooth primitive that *does* commute with memoryless nonlinear and/or time-varying block diagrams. In other words, some new compiler primitive, perhaps "ismooth()", would be moved by optimization rules to be applied after any memoryless block diagrams in series with it.
In this particular case, an alternative is to make a version of tf2s using the approximate bilinear-transform constant c=2*SR/w1 in place of the more exact c = 1/tan(w1*0.5/SR) that preserves w1 mapping exactly (nice for keeping resonators in tune when going from analog to digital). Of course, placing smooth() explicitly after the calculation of c as Kjetil has done is also a perfectly fine solution. Another idea could be for the compiler to eliminate instances of smooth() when it can determine that its input is constant. That way "c = 1/tan(w1*0.5/SR) : smooth(0.999)" could be used in filter.lib's definition of tf2s() without adding unnecessary smoothing when w1 is constant. However, this would require some kind of explicit indication that a signal is constant, since only the zero signal is truly constant in Faust (otherwise 1-1' would not generate an impulse at time 0). Since we have int() and float(), why not constant()? Maybe the 'constant' primitive could be defined as a block diagram having the same number of inputs as outputs, and where the negative-time values of each of its input signals are defined to be its value at time 0 (instead of 0 as now). Then any smooth() instances after such a "constant block diagram" can be eliminated. If the value at time zero is not fixed (e.g., there is a slider in the computation), then it would reduce to bus(N) and smooth() would not be eliminated. Just thinking out loud here... - Julius At 03:51 AM 12/7/2013, Jonatan Liljedahl wrote: >Is the optimized supposed to detect cases like this: > >process = slider : smooth(0.999) : y; >y = tanh : pow(2) : foo; > >and put the smoothing filter after tanh and pow instead of before? > > >On Thu, Dec 5, 2013 at 11:07 PM, Julius Smith <[email protected]> wrote: > > Hi All, > > > > I am having trouble reproducing this optimization problem in a simple > > isolated case. It sounds like the optimization rules do not yet always > > compute things at the control rate as far as possible in the graph. > > > > - Julius > > > > > > At 06:09 AM 12/5/2013, Jonatan Liljedahl wrote: > >> > >> Thanks, indeed that works! I went from 30% to 8% cpu usage, and no clicks. > >> > >> This seems to be a pretty common problem, I wonder if there is a way > >> to fix it except having a "smooth" version of every component? > >> > >> On Thu, Dec 5, 2013 at 2:43 PM, Kjetil Matheussen > >> <[email protected]> wrote: > >> > On Thu, Dec 5, 2013 at 2:41 PM, Kjetil Matheussen > >> > <[email protected]> wrote: > >> >> On Thu, Dec 5, 2013 at 2:26 PM, Jonatan Liljedahl <[email protected]> > >> >> wrote: > >> >>> Hi, > >> >>> > >> >>> I have a parametric EQ with lowshelf, two midbands and a highshelf, > >> >>> which gives a total of 10 parameters. In the original I get around 7% > >> >>> cpu usage. If I run each parameter slider through a smooth(0.999) > >> >>> filter, the cpu usage goes up to around 30%. That's quite a lot to > >> >>> just get rid of some subtle clicks while moving a slider.. Any ideas > >> >>> if this could be done more efficiently? > >> >>> > >> >> > >> >> Hi, > >> >> > >> >> I had the same problem in Radium over a year ago, and (if I remember > >> >> correctly), > >> >> spent some time moving the smooth calls to get them out of the inner > >> >> loop. > >> >> I don't remember exactly what I did, but I think there were some other > >> >> side effects (not clicks), although those were not a problem for > >> >> radium. > >> >> I don't remember right now what difference they made to the sound > >> >> though. > >> > > >> > Oh, I wrote it down in the file: > >> > > >> > " > >> > // Changes: > >> > // I have inserted some smooth calls here and there to make parameter > >> > changes smooth. > >> > // Just putting the smooth calls directly after slider input causes > >> > many calls to powf, > >> > // tan, cos and sqrt to be inserted into the inner DSP loop. > >> > // This version should be faster (although I don't know how much > >> > faster). -Kjetil > >> > " > >> > >> > >> > >> -- > >> /Jonatan > >> http://kymatica.com > >> > >> > >> > ------------------------------------------------------------------------------ > >> Sponsored by Intel(R) XDK > >> Develop, test and display web and hybrid apps with a single code base. > >> Download it for free now! > >> > >> > http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk > >> _______________________________________________ > >> Faudiostream-users mailing list > >> [email protected] > >> https://lists.sourceforge.net/lists/listinfo/faudiostream-users > > > > > > > > Julius O. Smith III <[email protected]> > > Professor of Music and, by courtesy, Electrical Engineering > > CCRMA, Stanford University > > http://ccrma.stanford.edu/~jos/ > > > >-- >/Jonatan >http://kymatica.com Julius O. Smith III <[email protected]> Professor of Music and, by courtesy, Electrical Engineering CCRMA, Stanford University http://ccrma.stanford.edu/~jos/ ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ Faudiostream-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/faudiostream-users
