diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-08 05:20:47 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-08 05:20:47 +0200 |
commit | 88975a1e252d25fb9ce1cc5dba826bfda5eb7346 (patch) | |
tree | b79848fd14ede9f110bbf1ec49724f6a19549c7f | |
parent | 995f41ad9ec5ebc3d665c4d6936969bade649422 (diff) | |
download | digitale-debutanten-88975a1e252d25fb9ce1cc5dba826bfda5eb7346.tar.gz |
since SndBuf.valueAt() has been fixed in v1.3.0.0, multichannel sound files can now be correctly read in by LiSaX: allow mixing of sound file according to gain vector
-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); } } |