Useful code snippet: writing to mono or stereo files
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
Robert,
This is handy, thanks. Also, I suppose WvOut really ought to get an
update to handle stereo files...
_MIke
2009/4/28 Robert Poor
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
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (2)
-
mike clemow
-
Robert Poor