[chuck-users] Useful code snippet: writing to mono or stereo files
Robert Poor
rdpoor at gmail.com
Tue Apr 28 13:19:32 EDT 2009
Thanks to a tip from Tom Lieber (who pointed out that WvOut doesn't actually
handle stereo files), here's a snippet of ChucK code people might find
useful:
if (me.args() > 1) {
dac.chan(0) => Gain g0 => WvOut w0 => blackhole;
dac.chan(1) => Gain g1 => WvOut w1 => blackhole;
0.5 => g0.gain;
0.5 => g1.gain;
me.arg(0) => w0.wavFilename;
me.arg(1) => w1.wavFilename;
<<< "writing stereo output to files", me.arg(0), me.arg(1) >>>;
} else if (me.args() > 0) {
dac => Gain g => WvOut w => blackhole;
0.5 => g.gain;
me.arg(0) => w.wavFilename;
<<< "writing mono output to file", me.arg(0) >>>;
}
Since it attaches to the dac, you can put it just about anywhere in your
ChucK program. When you invoke chuck as in :
% chuck mytest.ck:bleeep.wav
it will write everything your program sends to the dac to a mono
"bleeep.wav" file. If you invoke it as in:
% chuck mytest.ck:bleep_0.wav:bleep_1.wav
it will write everything you program sends to the dac to two mono files:
bleep_0.wav (left channel) andn bleep_1.wav (right channel). It's up to you
to weave the two files together into a stereo sound file. There are several
ways to do it -- I tend to use Audacity.
- Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20090428/9822fced/attachment.html>
More information about the chuck-users
mailing list