I was experimenting writing buffers with arrays.
This will write a stereo buffer, with two independent channels of random values: ~b = Buffer.loadCollection(s, Array.fill(100, {1.0.rand}), 2);
If I wanted to take two discretely generated arrays and combine them into a stereo buffer, though - I’m not sure what the approach would be. Any ideas?
OK - that makes sense - when using loadToFloatArray, it seems like the output becomes an interlaced list, with each of the channels.
I was attempting to make a simple function to do buffer operations - but I seem to missing something here:
a) Load the array first and then unlace it inside the “action function” where the array is loaded
b) Reverse each channel separately
c) Actually, it does not make a difference. Just forget about unlace; the result of reversing interlaced channels is the same as doing that on each channel separately.
Thanks for the tip! I will remember if I use it in huge sound files.
At the same time, it’s good that people know how to compose functions (or methods). (And as a matter of fact, it’s unfortunate that Sclang composes things so poorly regarding performance.)
I agree, but I don’t see how you could fix this without a type system… that is, without extending the ‘bootstrapping’ that the compiler does for things like while, !?, ??, if..., which would mean you can’t overload those methods.
Yea, type systems can enable specific compiler optimizations, but attributing the performance difference to the lack of a type system seems a bit of a stretch. Without profiling data, it would be speculation.
Besides, the new wave of gradually typed languages is sometimes worse than doing nothing.
I was attributing it to the fact you can’t transform .flop.flat -> .lace, as at compile time, you don’t know what those methods do, and even if the method’s content is compile time known, you can’t look them up because you don’t know the type of the receiver.
Supercollider actually does make some assumptions about the body of those above listed methods, it is very confusing when you try to dig into it.
Here is an issue about it showing some of the odd behaviour…
It also enables this magic (from object.sc)
// looping
while { arg body;
// compiler magic: the compiler inlines the following loop
// thus an uninlinable while can be implemented using while itself
while({ this.value }, {
body.value
});
}
Yes, that’s true. I’ve been inspecting the intermediate language that GHC produces to get some performance hints, and it is all about magic things. They do crazy optimizations down there. The intermediate language is also statically typed; knowing what happens after all those layers (there and below) is not trivial. If sclang aimed at type inference, it would be a substantial project. People much more astute than us struggle to get it right.