[chuck-users] input from file?

Martin Ahnelöv operagasten at gmail.com
Sat Nov 3 07:06:54 EDT 2007


fre 2007-11-02 klockan 16:41 -0300 skrev francis keyes:
> This may be a silly question but is it possible to read data into a
> chuck program from a file?
> 
> Given the code below for example, would it be possible to store the
> parameters for the Std.rand2f function in a text file and have chuck
> read them from the file on every loop? 
> // make our patch
>       SinOsc s => dac;
> 
>       // time-loop, in which the osc's frequency is changed every 100 ms
> 
>       while( true ) {
>           1000::ms => now;
>           Std.rand2f(30.0, 1000.0) => s.freq;
>       }
> 

Sorry, as far as I know, textfiles can't be written, or read at the
moment. It's very high up in the TODO-liST, though (I think).

Since you want to store float-point numbers, you might be able to hack
around this limitation by fiddling a bit:

save every float in a array, and when you quit you iterate (use a
for-loop) over that array and feed the float-points into a impulse/step,
which you record using WvOut. 

If you want to use them again in a chuck-program, you load the file in a
SndBuf and put the floats back into an array by using .last() in a
for-loop.

However, if you want to use the numbers outside
chuck/audio-programming-language, it gets tricky. In that case, you are
best off if you print the values to the screen and copy/past them to a
text-file.

Hope that helps,
Gasten



More information about the chuck-users mailing list