Writing to Disk
by Adam Tindale and Ge Wang
Recording your ChucK session to ﬁle is easy!
Say you want to record the output of the following:
%>chuck foo.ck bar.ck
All you have to do is ChucK a shred that writes to ﬁle:
%>chuck foo.ck bar.ck rec.ck
No changes to existing ﬁles are necessary. An example rec.ck can be found in examples/basic/, this guy/gal writes to “foo.wav”. Edit the ﬁle to change the output file. If you don’t want to worry about overwriting the same ﬁle everytime, you can substitute rec.ck for rec-auto.ck:
%>chuck foo.ck bar.ck rec-auto.ck
rec-auto.ck will generate a ﬁle name using the current time. You can change the preﬁx of the ﬁlename by modifying
"data/session" => w.autoPrefix;
w is the WvOut in the patch.
Oh yeah, you can of course chuck rec.ck on-the-ﬂy.
From terminal 1
From terminal 2
%>⁞chuck + rec.ck
Silent ModeYou can write directly to disk without having real-time audio by starting your programs using the --silent or -s flag.
%>chuck foo.ck bar.ck rec2.ck -s
This will not synchronize to the audio card, and will generate samples as fast as it can.
Start and StopYou can start and stop the writing to ﬁle by:
1 => w.record; // start 0 => w.record; // stop
As with all things ChucKian, this can be done sample-synchronously.
Another halting problemWhat if I have inﬁnite time loop, and want to terminate the VM, will my ﬁle be written out correctly? the answer: Ctrl-C works just ﬁne.
ChucK STK module keeps track of open ﬁle handles and closes them even upon abnormal termination, like Ctrl-C. Actually for many, Ctrl-C is the natural way to end your ChucK session. At any rate, this is quite ghetto, but it works. As for seg-faults and other catastrophic events, like computer catching on ﬁre from ChucK exploding, the ﬁle probably is toast.
The Silent Sample Sucker Strikes AgainAs in rec.ck, one patch to write to ﬁle is:
dac => Gain g => WvOut w => blackhole;
The WvOut writes to ﬁle, and also pass through the incoming samples.