Hello,
“.loadToFloatArray” needs some time to work. In your code, the part ~t.do({arg i; i.postln;});
calls “~t” after “~t” is initialised. However, that moment is still before “~t” is filled with the array by".loadToFloatArray" method.
~t.do({arg i; i.postln;});
should be placed at the last line of action as follows:
(
f={arg l;
~t=[[]];
l.do({ arg n,i;
i.postln;
{SinOsc.ar(220*n,mul:0.5)}
.loadToFloatArray(0.01, action: { arg array;
~t.add(array.flatten);
~t.do({arg i; i.postln;});});
};)};
)
f.value([2,3,4]);
Please look at the following revision of your code. The Post window posts everything step by step according to the order of processed events:
(
g={ |harmonics|
var summedArray = [[]];
harmonics.do{ |nthHarmonic, index|
"iteration index %:\n".postf(index);
{ SinOsc.ar(220 * nthHarmonic, mul:0.5) }
.loadToFloatArray(
2/s.sampleRate,
action: { |arrayOfNthHarmonic|
var add;
"\nloadToFloatArray index % started:\n".postf(index);
add = summedArray.add(arrayOfNthHarmonic.flatten);
"added index %: %\n".postf(index, add);
summedArray.do{ |array|
"summedArray at the index %: %\n".postf(index, array)
};
});
}}
)
g.value([2,3,4]);
For me, there is a surprise that index 0 is processed lastly, and index 2 is processed first in the “actoin” of the “.loadToFloatArray”. Why does it work in a reversed order?
iteration index 0:
iteration index 1:
iteration index 2:
→ [ 2, 3, 4 ]
loadToFloatArray index 2 started:
added index 2: [ [ ], [ 0.057468570768833, 0.11417542397976 ] ]
summedArray at the index 2: [ ]
summedArray at the index 2: [ 0.057468570768833, 0.11417542397976 ]
loadToFloatArray index 1 started:
added index 1: [ [ ], [ 0.057468570768833, 0.11417542397976 ], [ 0.043143179267645, 0.085964545607567 ] ]
summedArray at the index 1: [ ]
summedArray at the index 1: [ 0.057468570768833, 0.11417542397976 ]
summedArray at the index 1: [ 0.043143179267645, 0.085964545607567 ]
loadToFloatArray index 0 started:
added index 0: [ [ ], [ 0.057468570768833, 0.11417542397976 ], [ 0.043143179267645, 0.085964545607567 ], [ 0.028782008215785, 0.057468563318253 ] ]
summedArray at the index 0: [ ]
summedArray at the index 0: [ 0.057468570768833, 0.11417542397976 ]
summedArray at the index 0: [ 0.043143179267645, 0.085964545607567 ]
summedArray at the index 0: [ 0.028782008215785, 0.057468563318253 ]