diff options
-rw-r--r-- | lib/LiSaX.ck | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/lib/LiSaX.ck b/lib/LiSaX.ck index 8ce2d6b..7c97585 100644 --- a/lib/LiSaX.ck +++ b/lib/LiSaX.ck @@ -1,24 +1,47 @@ /* * Version of LiSa that supports reading in files (like a SndBuf) + * LiSa supports only one channel so mixing can be performed */ public class LiSaX extends LiSa { + /* + * Read in file, mixing its channels using a gain vector + * mix == null means to mix all of the channels with gain 1/channels + */ fun void - read(string file) + read(string file, float mix[]) { SndBuf buf; file => buf.read; - /* buf.samples() returns number of frames (or samples in one channel) */ + /* + * buf.samples() returns number of frames + * (i.e. samples in one channel) + */ buf.samples()::samp => duration; - for (0 => int i; i < buf.samples(); i++) - /* - * BUG WORKAROUND - * Only get the first channel's data. - * Still broken for stereo files probably because a - * ChucK bug prevents buf.valueAt(i) to work for - * i > buf.samples() - */ - valueAt(i * buf.channels() => buf.valueAt, i::samp); + for (0 => int frame; frame < buf.samples(); frame++) { + 0 => float v; + + for (0 => int c; c < buf.channels(); c++) { + float g; + + if (mix == null) + 1.0/buf.channels() => g; + else + mix[c] => g; + buf.valueAt(frame*buf.channels() + c)*g +=> v; + } + + valueAt(v, frame::samp); + } + } + + /* + * Read in file, mixing its channels equally + */ + fun void + read(string file) + { + read(file, null); } } |