Does ChucK a method of writing and reading ints, floats or strings from a file? The documentation only includes WvIn and WvOut for file I/O. I hacked a technique for sending data by scaling it to values -1.0 to 1.0 and sending it to a sound file: //WRITE1.ck// // write values to file Step x => WvOut file => blackhole; "data" => file.sndFilename; float n; for (int ii; ii<20; ii++) { ii/20.0 => n; <<< n >>>; n => x.next; 1::samp => now; } file.closeFile(); These values can then be read sequentially with WvIn: //READ1.ck// WvIn w => blackhole; "data.snd" => w.path; float n; repeat(20) { 1::samp => now; w.last() => n; <<< n >>>; } But I don't get exactly the same values returned; ie, I try to store the value 0.500000 but when read, I get 0.500015. That's a significant variance. Does anyone know where this variance comes from, or how to get around it? And is this the only way to store and read data? What about strings from files? Joel
I am guessing that the n float (which is 64 bit, I think) gets downsampled
to 16 bit resolution in the WvOut stream, which yields the variance you see
(0.5 doesn't look that neat in base 16). I don't know an easy way around
this, besides increasing the sample resolution or maybe try to chop the
float in half and write it twice in the sample?
I too have been wondering about a simple file interface. One application is
note sequences read dynamically from files. A wilder thought is ChucK
programs generating new ChucK source code and sporking them. 8) The former
can be solved by simply editing ChucK source code, but there may be
situations when you want a cleaner file to edit.
/Stefan
On Thu, Aug 21, 2008 at 4:38 AM, Joel Matthys
Does ChucK a method of writing and reading ints, floats or strings from a file? The documentation only includes WvIn and WvOut for file I/O.
I hacked a technique for sending data by scaling it to values -1.0 to 1.0 and sending it to a sound file:
//WRITE1.ck//
// write values to file Step x => WvOut file => blackhole; "data" => file.sndFilename; float n; for (int ii; ii<20; ii++) { ii/20.0 => n; <<< n >>>; n => x.next; 1::samp => now; } file.closeFile();
These values can then be read sequentially with WvIn:
//READ1.ck//
WvIn w => blackhole; "data.snd" => w.path; float n;
repeat(20) { 1::samp => now; w.last() => n; <<< n >>>; }
But I don't get exactly the same values returned; ie, I try to store the value 0.500000 but when read, I get 0.500015. That's a significant variance.
Does anyone know where this variance comes from, or how to get around it? And is this the only way to store and read data? What about strings from files?
Joel
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Release me, insect, or I will destroy the Cosmos!
On Wed, Aug 20, 2008 at 10:38 PM, Joel Matthys
Does ChucK a method of writing and reading ints, floats or strings from a file? The documentation only includes WvIn and WvOut for file I/O.
I'm pretty sure it's coming; I saw it in development last spring. -- Tom Lieber http://AllTom.com/
participants (3)
-
Joel Matthys
-
Stefan Blixt
-
Tom Lieber