[Cs-dev] if-then solution (after 5.16)
Tito Latini <tito.01beta <at> gmail.com>
2012-02-05 19:57:21 GMT
Here is an idea to resolve the if-then problem with k-condition and
i-rate assignments in the body. It is not necessary to modify the
semantics, the problem is easily resolvable changing the scheme of
relinking in if-then for this particular case. For the other cases
the relink is unchanged.
Example:
if (k1 == k2) then
ivar = ...
...
else
ivar = ...
...
endif
=== becomes ===
kgoto kcont
if (i(k1) == i(k2)) then
ivar = ...
...
else
ivar = ...
...
endif
kcont:
;; the k-rate copy doesn't contain the i-rate assignments
if (k1 == k2) then
...
else
...
endif
To convert the condition from k-rate to i-rate, we can use the same
`optimize_ifun' function used in `verify_tree1' to expand i().
parsing
- if-then classic relink
+ save the type-state of the condition
+ save the state of the i-rate-assign existence
- check if-then node
+ k-condition and body with i-rate assignments ?
yes -> new relink scheme
no -> continue
Here is a complete example:
<CsoundSynthesizer>
<CsInstruments>
instr classic ; without relink simulation
k1 init 1
k2 init 1
icount init 1
if (k1 == k2) then
ival = 123
kval line 1, p3, 0
k1 = 100
printks "%d) kval = %f, k1 = %f\n", 0.1, icount, kval, k1
else
ival = 321
kval line 0, p3, 1
endif
prints "ival = %d\n", ival
printks "> after if-then: kval = %f\n", p3/4, kval
icount = icount + 1
endin
instr relink_simulation
k1 init 1
k2 init 1
icount init 1
kgoto kcont
if (i(k1) == i(k2)) then
ival = 123
kval line 1, p3, 0
k1 = 100
printks "%d) kval = %f, k1 = %f\n", 0.1, icount, kval, k1
else
ival = 321
kval line 0, p3, 1
endif
kcont:
if (k1 == k2) then
kval line 1, p3, 0
k1 = 100
printks "%d) kval = %f, k1 = %f\n", 0.1, icount, kval, k1
else
kval line 0, p3, 1
endif
prints "ival = %d\n", ival
printks "> after if-then: kval = %f\n", p3/4, kval
icount = icount + 1
endin
</CsInstruments>
<CsScore>
i "classic" 0 1
i "relink_simulation" 1 1
</CsScore>
</CsoundSynthesizer>
csound test.csd
...
new alloc for instr classic:
ival = 321
2) kval = 1.000000, k1 = 100.000000
> after if-then: kval = 1.000000
> after if-then: kval = 0.249660
> after if-then: kval = 0.499546
> after if-then: kval = 0.749660
> after if-then: kval = 0.999546
B 0.000 .. 1.000 T 1.000 TT 1.000 M: 0.0
new alloc for instr relink_simulation:
ival = 123
2) kval = 1.000000, k1 = 100.000000
> after if-then: kval = 1.000000
> after if-then: kval = 0.249660
> after if-then: kval = 0.499546
> after if-then: kval = 0.749660
> after if-then: kval = 0.999546
...
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Csound-devel mailing list
Csound-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel